mirror of
https://github.com/n8n-io/n8n.git
synced 2026-09-24 23:22:38 +08:00
fix: Use UUID thread IDs for Instance AI evals (no-changelog) (#31830)
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { vi } from 'vitest';
|
||||
|
||||
import type { N8nClient } from '../clients/n8n-client';
|
||||
import type { EvalLogger } from '../harness/logger';
|
||||
import { buildWorkflow } from '../harness/runner';
|
||||
|
||||
const silentLogger: EvalLogger = {
|
||||
info: () => {},
|
||||
verbose: () => {},
|
||||
success: () => {},
|
||||
warn: () => {},
|
||||
error: () => {},
|
||||
isVerbose: false,
|
||||
};
|
||||
|
||||
const uuidV4Pattern = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
||||
|
||||
describe('buildWorkflow thread IDs', () => {
|
||||
it('uses UUID thread IDs accepted by the instance-ai thread endpoint', async () => {
|
||||
let capturedThreadId = '';
|
||||
const client = {
|
||||
ensureThread: vi.fn(async (threadId: string) => {
|
||||
capturedThreadId = threadId;
|
||||
await Promise.resolve();
|
||||
throw new Error('stop after ensureThread');
|
||||
}),
|
||||
} as unknown as N8nClient;
|
||||
|
||||
await buildWorkflow({
|
||||
client,
|
||||
conversation: [{ role: 'user', text: 'build a workflow' }],
|
||||
preRunWorkflowIds: new Set(),
|
||||
claimedWorkflowIds: new Set(),
|
||||
logger: silentLogger,
|
||||
});
|
||||
|
||||
expect(client.ensureThread).toHaveBeenCalledTimes(1);
|
||||
expect(capturedThreadId).toMatch(uuidV4Pattern);
|
||||
});
|
||||
});
|
||||
@@ -42,7 +42,7 @@ export interface RunChatOptions {
|
||||
*/
|
||||
export async function runChat(options: RunChatOptions): Promise<ScenarioTrace> {
|
||||
const { client, prompt, timeoutMs, logger } = options;
|
||||
const threadId = `cu-eval-${crypto.randomUUID()}`;
|
||||
const threadId = crypto.randomUUID();
|
||||
const startTime = Date.now();
|
||||
|
||||
const abortController = new AbortController();
|
||||
|
||||
@@ -299,7 +299,7 @@ function isMultiTurnConversation(conversation: ConversationTurn[]): boolean {
|
||||
export async function buildWorkflow(config: BuildWorkflowConfig): Promise<BuildResult> {
|
||||
const { client, conversation, logger } = config;
|
||||
const openingMessage = conversation[0]?.text ?? '';
|
||||
const threadId = `eval-${crypto.randomUUID()}`;
|
||||
const threadId = crypto.randomUUID();
|
||||
const startTime = Date.now();
|
||||
const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user