| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { |
| 4 | removeAndRenumberTimelineItem, |
| 5 | upsertTimelineItemAtStablePosition, |
| 6 | } from "./orchestrationV2Timeline"; |
| 7 | |
| 8 | describe("removeAndRenumberTimelineItem", () => { |
| 9 | it("closes the position gap before a streamed item is reinserted", () => { |
| 10 | const remaining = removeAndRenumberTimelineItem( |
| 11 | [ |
| 12 | { position: 0, sourceItemId: "first" }, |
| 13 | { position: 1, sourceItemId: "streaming" }, |
| 14 | { position: 2, sourceItemId: "last" }, |
| 15 | ], |
| 16 | "streaming", |
| 17 | ); |
| 18 | |
| 19 | expect(remaining).toEqual([ |
| 20 | { position: 0, sourceItemId: "first" }, |
| 21 | { position: 1, sourceItemId: "last" }, |
| 22 | ]); |
| 23 | expect(new Set(remaining.map((row) => row.position)).size).toBe(remaining.length); |
| 24 | }); |
| 25 | }); |
| 26 | |
| 27 | describe("upsertTimelineItemAtStablePosition", () => { |
| 28 | it("replaces a streaming item without moving it behind newer items", () => { |
| 29 | const updated = upsertTimelineItemAtStablePosition( |
| 30 | [ |
| 31 | { position: 0, sourceItemId: "reasoning", text: "partial" }, |
| 32 | { position: 1, sourceItemId: "subagent", text: "running" }, |
| 33 | ], |
| 34 | { position: 2, sourceItemId: "reasoning", text: "completed" }, |
| 35 | ); |
| 36 | |
| 37 | expect(updated).toEqual([ |
| 38 | { position: 0, sourceItemId: "reasoning", text: "completed" }, |
| 39 | { position: 1, sourceItemId: "subagent", text: "running" }, |
| 40 | ]); |
| 41 | }); |
| 42 | |
| 43 | it("appends a genuinely new item at the next position", () => { |
| 44 | const updated = upsertTimelineItemAtStablePosition( |
| 45 | [{ position: 0, sourceItemId: "reasoning" }], |
| 46 | { position: 99, sourceItemId: "assistant" }, |
| 47 | ); |
| 48 | |
| 49 | expect(updated).toEqual([ |
| 50 | { position: 0, sourceItemId: "reasoning" }, |
| 51 | { position: 1, sourceItemId: "assistant" }, |
| 52 | ]); |
| 53 | }); |
| 54 | }); |