The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
test(shared): cover unsent manual continuation source resolution (#39653)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Neil Daquioag committed
Nov 20, 2026 at 17:01 UTC
1ed4f6a96f93b86839f998ede47c46261c08a4d0
1 file changed
+111
packages/shared/src/orchestrationV2ManualContinuation.test.ts
new
+111
@@ -0,0 +1,111 @@
1
+import { describe, expect, it } from "vite-plus/test";
2
+import type {
3
+ OrchestrationV2ProviderTurn,
4
+ OrchestrationV2Run,
5
+ OrchestrationV2RunAttempt,
6
+ OrchestrationV2ThreadProjection,
7
+ RunAttemptId,
8
+ RunId,
9
+} from "@t3tools/contracts";
10
+
11
+import { unsentManualContinuationSource } from "./orchestrationV2ManualContinuation.ts";
12
+
13
+// The source only reads id/manualContinuationOfRunId on runs, runId+attemptOrdinal+reason+id
14
+// on attempts, and runAttemptId on turns, so the fixtures carry just those fields.
15
+const run = (id: string, manualContinuationOfRunId?: string) =>
16
+ ({ id, manualContinuationOfRunId }) as unknown as OrchestrationV2Run;
17
+
18
+const attempt = (id: string, runId: string, ordinal: number, reason = "initial") =>
19
+ ({ id, runId, attemptOrdinal: ordinal, reason }) as unknown as OrchestrationV2RunAttempt;
20
+
21
+const turn = (runAttemptId: string | null) =>
22
+ ({ runAttemptId: runAttemptId as RunAttemptId | null }) as OrchestrationV2ProviderTurn;
23
+
24
+const projection = (
25
+ runs: OrchestrationV2Run[],
26
+ attempts: OrchestrationV2RunAttempt[],
27
+ providerTurns: OrchestrationV2ProviderTurn[],
28
+) =>
29
+ ({ runs, attempts, providerTurns }) as Pick<
30
+ OrchestrationV2ThreadProjection,
31
+ "runs" | "attempts" | "providerTurns"
32
+ >;
33
+
34
+describe("unsentManualContinuationSource", () => {
35
+ it("returns undefined when the source run no longer exists", () => {
36
+ expect(
37
+ unsentManualContinuationSource(run("r2", "ghost" as RunId), projection([run("r2")], [], [])),
38
+ ).toBeUndefined();
39
+ });
40
+
41
+ it("returns the source run when it never had an accepted attempt", () => {
42
+ const source = run("src");
43
+ expect(
44
+ unsentManualContinuationSource(run("r2", "src" as RunId), projection([source], [], [])),
45
+ ).toBe(source);
46
+ });
47
+
48
+ it("returns undefined once the source attempt was accepted", () => {
49
+ const a1 = attempt("a1", "src", 1);
50
+ expect(
51
+ unsentManualContinuationSource(
52
+ run("r2", "src" as RunId),
53
+ projection([run("src")], [a1], [turn("a1")]),
54
+ ),
55
+ ).toBeUndefined();
56
+ });
57
+
58
+ it("returns the source when a steering restart ran after the accepted attempt", () => {
59
+ const source = run("src");
60
+ const a1 = attempt("a1", "src", 1);
61
+ const a2 = attempt("a2", "src", 2, "steering_restart");
62
+ expect(
63
+ unsentManualContinuationSource(
64
+ run("r2", "src" as RunId),
65
+ projection([source], [a1, a2], [turn("a1")]),
66
+ ),
67
+ ).toBe(source);
68
+ });
69
+
70
+ it("ignores a steering restart that predates the accepted attempt", () => {
71
+ const a1 = attempt("a1", "src", 1, "steering_restart");
72
+ const a2 = attempt("a2", "src", 2);
73
+ expect(
74
+ unsentManualContinuationSource(
75
+ run("r2", "src" as RunId),
76
+ projection([run("src")], [a1, a2], [turn("a2")]),
77
+ ),
78
+ ).toBeUndefined();
79
+ });
80
+
81
+ it("walks a chain of manual continuations until a source that never delivered", () => {
82
+ const root = run("root");
83
+ const mid = run("mid", "root" as RunId);
84
+ expect(
85
+ unsentManualContinuationSource(run("r3", "mid" as RunId), projection([root, mid], [], [])),
86
+ ).toBe(root);
87
+ });
88
+
89
+ it("stops the chain at a source whose attempt was accepted", () => {
90
+ const root = run("root");
91
+ const mid = run("mid", "root" as RunId);
92
+ const midAccepted = attempt("a-mid", "mid", 1);
93
+ const rootRestart = attempt("a-root", "root", 1, "steering_restart");
94
+ // mid's accepted attempt already delivered the forwarded message, so
95
+ // root's older steering restart is not still pending.
96
+ expect(
97
+ unsentManualContinuationSource(
98
+ run("r3", "mid" as RunId),
99
+ projection([root, mid], [midAccepted, rootRestart], [turn("a-mid")]),
100
+ ),
101
+ ).toBeUndefined();
102
+ });
103
+
104
+ it("stops on a cyclic continuation chain instead of looping", () => {
105
+ const a = run("a", "b" as RunId);
106
+ const b = run("b", "a" as RunId);
107
+ expect(
108
+ unsentManualContinuationSource(run("c", "a" as RunId), projection([a, b], [], [])),
109
+ ).toBeUndefined();
110
+ });
111
+});