From 993d53ed97b8520691d062e6184f2953ac11c027 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 5 Nov 2025 18:21:48 +0000 Subject: [PATCH] Complete vi.waitFor() migration for all async streaming tests Replaced all remaining setTimeout calls with vi.waitFor() for consistency and reliability. Co-authored-by: eliandoran <21236836+eliandoran@users.noreply.github.com> --- apps/server/src/routes/api/llm.spec.ts | 46 +++++++++++++++++++++----- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/apps/server/src/routes/api/llm.spec.ts b/apps/server/src/routes/api/llm.spec.ts index 913b515c2..a1f1ca3c2 100644 --- a/apps/server/src/routes/api/llm.spec.ts +++ b/apps/server/src/routes/api/llm.spec.ts @@ -382,12 +382,19 @@ describe("LLM API Tests", () => { message: "Streaming initiated successfully" }); - // Wait for async streaming operations to complete - await new Promise(resolve => setTimeout(resolve, 100)); - // Import ws service to access mock const ws = (await import("../../services/ws.js")).default; + // Wait for async streaming operations to complete + await vi.waitFor(() => { + expect(ws.sendMessageToAllClients).toHaveBeenCalledWith({ + type: 'llm-stream', + chatNoteId: testChatId, + content: ' world!', + done: true + }); + }, { timeout: 1000, interval: 50 }); + // Verify WebSocket messages were sent expect(ws.sendMessageToAllClients).toHaveBeenCalledWith({ type: 'llm-stream', @@ -539,12 +546,19 @@ describe("LLM API Tests", () => { expect(response.status).toBe(200); - // Wait for async streaming operations to complete - await new Promise(resolve => setTimeout(resolve, 100)); - // Import ws service to access mock const ws = (await import("../../services/ws.js")).default; + // Wait for async streaming operations to complete + await vi.waitFor(() => { + expect(ws.sendMessageToAllClients).toHaveBeenCalledWith({ + type: 'llm-stream', + chatNoteId: testChatId, + thinking: 'Formulating response...', + done: false + }); + }, { timeout: 1000, interval: 50 }); + // Verify thinking messages expect(ws.sendMessageToAllClients).toHaveBeenCalledWith({ type: 'llm-stream', @@ -589,12 +603,26 @@ describe("LLM API Tests", () => { expect(response.status).toBe(200); - // Wait for async streaming operations to complete - await new Promise(resolve => setTimeout(resolve, 100)); - // Import ws service to access mock const ws = (await import("../../services/ws.js")).default; + // Wait for async streaming operations to complete + await vi.waitFor(() => { + expect(ws.sendMessageToAllClients).toHaveBeenCalledWith({ + type: 'llm-stream', + chatNoteId: testChatId, + toolExecution: { + tool: 'calculator', + args: { expression: '2 + 2' }, + result: '4', + toolCallId: 'call_123', + action: 'execute', + error: undefined + }, + done: false + }); + }, { timeout: 1000, interval: 50 }); + // Verify tool execution message expect(ws.sendMessageToAllClients).toHaveBeenCalledWith({ type: 'llm-stream',