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>
This commit is contained in:
copilot-swe-agent[bot] 2025-11-05 18:21:48 +00:00
parent 730e2da932
commit 993d53ed97

View File

@ -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',