diff --git a/tests/ipcMain/helpers.ts b/tests/ipcMain/helpers.ts index 4eaea823dd..de27d7fae8 100644 --- a/tests/ipcMain/helpers.ts +++ b/tests/ipcMain/helpers.ts @@ -232,7 +232,16 @@ export async function sendMessageAndWait( // Wait for stream completion const collector = createEventCollector(env.sentEvents, workspaceId); - await collector.waitForEvent("stream-end", timeoutMs); + const streamEnd = await collector.waitForEvent("stream-end", timeoutMs); + + if (!streamEnd) { + collector.logEventDiagnostics(`sendMessageAndWait timeout after ${timeoutMs}ms`); + throw new Error( + `sendMessageAndWait: Timeout waiting for stream-end after ${timeoutMs}ms.\n` + + `See detailed event diagnostics above.` + ); + } + return collector.getEvents(); } diff --git a/tests/ipcMain/resumeStream.test.ts b/tests/ipcMain/resumeStream.test.ts index b0edd8b442..e43cc6e0da 100644 --- a/tests/ipcMain/resumeStream.test.ts +++ b/tests/ipcMain/resumeStream.test.ts @@ -192,26 +192,25 @@ describeIntegration("IpcMain resumeStream integration tests", () => { .filter((e) => "role" in e && e.role === "assistant"); expect(assistantMessages.length).toBeGreaterThan(0); - // Verify we received content deltas - const deltas = collector.getDeltas(); - expect(deltas.length).toBeGreaterThan(0); - // Verify no stream errors const streamErrors = collector .getEvents() .filter((e) => "type" in e && e.type === "stream-error"); expect(streamErrors.length).toBe(0); - // Verify the assistant responded with actual content and said the verification word - const allText = deltas - .filter((d) => "delta" in d) - .map((d) => ("delta" in d ? d.delta : "")) - .join(""); - expect(allText.length).toBeGreaterThan(0); + // Get the final message content from stream-end parts + // StreamEndEvent has parts: Array + const finalMessage = collector.getFinalMessage() as any; + expect(finalMessage).toBeDefined(); + const textParts = (finalMessage?.parts ?? []).filter( + (p: any) => p.type === "text" && p.text + ); + const finalContent = textParts.map((p: any) => p.text).join(""); + expect(finalContent.length).toBeGreaterThan(0); // Verify the assistant followed the instruction and said the verification word // This proves resumeStream properly loaded history and continued from it - expect(allText).toContain(verificationWord); + expect(finalContent).toContain(verificationWord); } finally { await cleanup(); }