Skip to content

Commit 0b8f139

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 b4fdb90 commit 0b8f139

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

tests/ipcMain/resumeStream.test.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,26 +192,22 @@ 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 (more reliable than checking deltas which can be batched)
202+
const finalMessage = collector.getFinalMessage();
203+
expect(finalMessage).toBeDefined();
204+
const finalContent =
205+
finalMessage && "content" in finalMessage ? String(finalMessage.content) : "";
206+
expect(finalContent.length).toBeGreaterThan(0);
211207

212208
// Verify the assistant followed the instruction and said the verification word
213209
// This proves resumeStream properly loaded history and continued from it
214-
expect(allText).toContain(verificationWord);
210+
expect(finalContent).toContain(verificationWord);
215211
} finally {
216212
await cleanup();
217213
}

0 commit comments

Comments
 (0)