Skip to content

Commit 757a60f

Browse files
committed
test(core): stop assuming run and stream event ordering
1 parent a1ca646 commit 757a60f

1 file changed

Lines changed: 12 additions & 29 deletions

File tree

packages/core/test/runStream.test.ts

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -354,36 +354,19 @@ describe("RunSubscription", () => {
354354
// Verify we only created one stream
355355
expect(streamCreationCount).toBe(1);
356356

357-
// Verify we got all the expected events
357+
// Run-shape and stream events are produced independently, so their relative
358+
// ordering is not guaranteed. Preserve ordering within each source instead.
358359
expect(results).toHaveLength(4);
359-
expect(results[0]).toMatchObject({
360-
type: "run",
361-
run: {
362-
id: "run_123",
363-
taskIdentifier: "openai-streaming",
364-
status: "EXECUTING",
365-
durationMs: 100,
366-
},
367-
});
368-
expect(results[1]).toMatchObject({
369-
type: "openai",
370-
chunk: { id: "chunk1", content: "Hello" },
371-
run: { id: "run_123", durationMs: 100 },
372-
});
373-
expect(results[2]).toMatchObject({
374-
type: "openai",
375-
chunk: { id: "chunk2", content: "World" },
376-
run: { id: "run_123", durationMs: 100 },
377-
});
378-
expect(results[3]).toMatchObject({
379-
type: "run",
380-
run: {
381-
id: "run_123",
382-
taskIdentifier: "openai-streaming",
383-
status: "EXECUTING",
384-
durationMs: 200,
385-
},
386-
});
360+
361+
const runEvents = results.filter((event) => event.type === "run");
362+
expect(runEvents.map((event) => event.run.durationMs)).toEqual([100, 200]);
363+
364+
const streamEvents = results.filter((event) => event.type === "openai");
365+
expect(streamEvents.map((event) => event.chunk)).toEqual([
366+
{ id: "chunk1", content: "Hello" },
367+
{ id: "chunk2", content: "World" },
368+
]);
369+
expect(streamEvents.map((event) => event.run.durationMs)).toEqual([100, 100]);
387370
});
388371

389372
it("should handle multiple streams simultaneously", async () => {

0 commit comments

Comments
 (0)