Skip to content

Commit 5c7dff9

Browse files
committed
fix: use getFinalMessage() instead of getDeltas() in resumeStream test
The test was flaky because stream-delta events can be batched or arrive before the collector starts collecting. Using getFinalMessage().content is more reliable since it's captured from the stream-end event.
1 parent 2e91857 commit 5c7dff9

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

tests/ipcMain/resumeStream.test.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,26 +192,25 @@ describeIntegration("IpcMain resumeStream integration tests", () => {
192192
.filter((e) => "role" in e && e.role === "assistant");
193193
expect(assistantMessages.length).toBeGreaterThan(0);
194194

195-
// Verify we received content deltas
196-
const deltas = collector.getDeltas();
197-
expect(deltas.length).toBeGreaterThan(0);
198-
199195
// Verify no stream errors
200196
const streamErrors = collector
201197
.getEvents()
202198
.filter((e) => "type" in e && e.type === "stream-error");
203199
expect(streamErrors.length).toBe(0);
204200

205-
// Verify the assistant responded with actual content and said the verification word
206-
const allText = deltas
207-
.filter((d) => "delta" in d)
208-
.map((d) => ("delta" in d ? d.delta : ""))
209-
.join("");
210-
expect(allText.length).toBeGreaterThan(0);
201+
// Get the final message content from stream-end parts
202+
// StreamEndEvent has parts: Array<MuxTextPart | MuxReasoningPart | MuxToolPart>
203+
const finalMessage = collector.getFinalMessage() as any;
204+
expect(finalMessage).toBeDefined();
205+
const textParts = (finalMessage?.parts ?? []).filter(
206+
(p: any) => p.type === "text" && p.text
207+
);
208+
const finalContent = textParts.map((p: any) => p.text).join("");
209+
expect(finalContent.length).toBeGreaterThan(0);
211210

212211
// Verify the assistant followed the instruction and said the verification word
213212
// This proves resumeStream properly loaded history and continued from it
214-
expect(allText).toContain(verificationWord);
213+
expect(finalContent).toContain(verificationWord);
215214
} finally {
216215
await cleanup();
217216
}

0 commit comments

Comments
 (0)