|
1 | 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | +import { |
| 3 | + MessageId, |
| 4 | + NodeId, |
| 5 | + type OrchestrationV2TurnItem, |
| 6 | + RunId, |
| 7 | + ThreadId, |
| 8 | + TurnItemId, |
| 9 | +} from "@t3tools/contracts"; |
| 10 | +import * as DateTime from "effect/DateTime"; |
2 | 11 |
|
| 12 | +import { foldedQueuedTurnItems } from "./QueuedRunBatch.ts"; |
3 | 13 | import { queuedRunsInDeliveryOrder } from "./QueuedRunOrder.ts"; |
4 | 14 |
|
5 | 15 | describe("queued run delivery order", () => { |
| 16 | + it("folds a completed batch but excludes its messages after the turn restarts on a new input node", () => { |
| 17 | + const runId = RunId.make("run:batch"); |
| 18 | + const originalNodeId = NodeId.make("node:original"); |
| 19 | + const restartedNodeId = NodeId.make("node:restarted"); |
| 20 | + const input = ( |
| 21 | + name: string, |
| 22 | + ordinal: number, |
| 23 | + nodeId: NodeId, |
| 24 | + ): Extract<OrchestrationV2TurnItem, { type: "user_message" }> => ({ |
| 25 | + id: TurnItemId.make(`item:${name}`), |
| 26 | + threadId: ThreadId.make("thread:batch"), |
| 27 | + runId, |
| 28 | + nodeId, |
| 29 | + providerThreadId: null, |
| 30 | + providerTurnId: null, |
| 31 | + nativeItemRef: null, |
| 32 | + parentItemId: null, |
| 33 | + ordinal, |
| 34 | + status: "completed", |
| 35 | + title: null, |
| 36 | + startedAt: null, |
| 37 | + completedAt: null, |
| 38 | + updatedAt: DateTime.makeUnsafe("2026-10-29T00:00:00Z"), |
| 39 | + type: "user_message", |
| 40 | + messageId: MessageId.make(`message:${name}`), |
| 41 | + inputIntent: "queued_turn", |
| 42 | + text: name, |
| 43 | + attachments: [], |
| 44 | + createdBy: "user", |
| 45 | + creationSource: "web", |
| 46 | + }); |
| 47 | + const first = input("first", 0, originalNodeId); |
| 48 | + const second = input("second", 1, originalNodeId); |
| 49 | + const third = input("third", 2, originalNodeId); |
| 50 | + const batch = [first, second, third]; |
| 51 | + |
| 52 | + expect(foldedQueuedTurnItems(batch, { id: runId, userMessageId: first.messageId })).toEqual([ |
| 53 | + second, |
| 54 | + third, |
| 55 | + ]); |
| 56 | + |
| 57 | + const current = input("current", 3, restartedNodeId); |
| 58 | + expect( |
| 59 | + foldedQueuedTurnItems([...batch, current], { |
| 60 | + id: runId, |
| 61 | + userMessageId: current.messageId, |
| 62 | + }), |
| 63 | + ).toEqual([]); |
| 64 | + }); |
| 65 | + |
6 | 66 | it("keeps automatic completion delivery ahead of visible queued messages", () => { |
7 | 67 | const projection = { |
8 | 68 | messages: [ |
|
0 commit comments