|
1 | | -import { RunId } from "@t3tools/contracts"; |
| 1 | +import { |
| 2 | + MessageId, |
| 3 | + type OrchestrationV2Run, |
| 4 | + ProviderInstanceId, |
| 5 | + RunId, |
| 6 | + ThreadId, |
| 7 | +} from "@t3tools/contracts"; |
| 8 | +import * as DateTime from "effect/DateTime"; |
2 | 9 | import { describe, expect, it } from "vite-plus/test"; |
3 | 10 |
|
4 | 11 | import { |
5 | | - isDetailRunBehindShell, |
| 12 | + announcedRun, |
6 | 13 | nextThreadAnnouncement, |
7 | 14 | type ThreadActivitySnapshot, |
8 | 15 | type ThreadAnnouncementMemory, |
@@ -118,27 +125,32 @@ describe("nextThreadAnnouncement", () => { |
118 | 125 | expect(speak([busy(), idle(secondRun, "failed")])).toEqual(["Failed"]); |
119 | 126 | }); |
120 | 127 |
|
121 | | - it("stays silent when a thread reopens after its turn ended while it was closed", () => { |
122 | | - // The cached detail still shows the run working until it catches up with the live shell. |
123 | | - const frames = [busy(), idle(secondRun, "completed")]; |
124 | | - const shellRun = { runId: secondRun, status: "completed" } as const; |
125 | | - const current = frames.filter( |
126 | | - (frame) => |
127 | | - !isDetailRunBehindShell( |
128 | | - frame.runId === null || frame.runStatus === null |
129 | | - ? null |
130 | | - : { runId: frame.runId, status: frame.runStatus }, |
131 | | - shellRun, |
132 | | - ), |
133 | | - ); |
134 | | - expect(speak(current)).toEqual([]); |
135 | | - expect(isDetailRunBehindShell({ runId: secondRun, status: "running" }, null)).toBe(false); |
136 | | - expect( |
137 | | - isDetailRunBehindShell( |
138 | | - { runId: secondRun, status: "running" }, |
139 | | - { runId: firstRun, status: "completed" }, |
140 | | - ), |
141 | | - ).toBe(false); |
| 128 | + it("says how the turn ended when a queued message was cancelled before it started", () => { |
| 129 | + const now = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z"); |
| 130 | + const run = (id: RunId, ordinal: number, status: OrchestrationV2Run["status"]) => |
| 131 | + ({ |
| 132 | + id, |
| 133 | + threadId: ThreadId.make("thread-1"), |
| 134 | + ordinal, |
| 135 | + providerInstanceId: ProviderInstanceId.make("codex"), |
| 136 | + modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" }, |
| 137 | + providerThreadId: null, |
| 138 | + userMessageId: MessageId.make(`message-${ordinal}`), |
| 139 | + rootNodeId: null, |
| 140 | + activeAttemptId: null, |
| 141 | + status, |
| 142 | + requestedAt: now, |
| 143 | + startedAt: status === "cancelled" ? null : now, |
| 144 | + completedAt: now, |
| 145 | + checkpointId: null, |
| 146 | + contextHandoffId: null, |
| 147 | + }) satisfies OrchestrationV2Run; |
| 148 | + const cancelledRun = RunId.make("run-3"); |
| 149 | + const ended = announcedRun({ runId: cancelledRun, status: "cancelled", startedAt: null }, [ |
| 150 | + run(secondRun, 1, "completed"), |
| 151 | + run(cancelledRun, 2, "cancelled"), |
| 152 | + ]); |
| 153 | + expect(speak([busy(), idle(ended?.runId ?? null, ended?.status ?? null)])).toEqual(["Done"]); |
142 | 154 | }); |
143 | 155 |
|
144 | 156 | it("waits for the run to settle before announcing how the turn ended", () => { |
|
0 commit comments