|
1 | 1 | import { |
| 2 | + ContextHandoffId, |
2 | 3 | ProviderInstanceId, |
3 | 4 | RunId, |
4 | 5 | type OrchestrationV2ThreadProjection, |
@@ -74,11 +75,72 @@ describe("handoff endpoints shared by web and mobile", () => { |
74 | 75 | }); |
75 | 76 |
|
76 | 77 | const projection = { |
77 | | - runs: [{ ...run("source", 1, from, "source"), startedAt: "2026-10-11T00:00:00Z" }], |
| 78 | + runs: [ |
| 79 | + { |
| 80 | + ...run("source", 1, from, "source"), |
| 81 | + status: "completed", |
| 82 | + contextHandoffId: null, |
| 83 | + startedAt: "2026-10-11T00:00:00Z", |
| 84 | + }, |
| 85 | + ], |
78 | 86 | visibleTurnItems: [{ item: { type: "user_message" } }], |
79 | 87 | } as unknown as OrchestrationV2ThreadProjection; |
80 | 88 |
|
81 | 89 | describe("pending context handoff", () => { |
| 90 | + it.each([from, to])("removes the preview while the handoff to %s starts", (instanceId) => { |
| 91 | + const selection = { instanceId, model: "destination" }; |
| 92 | + const providers = [ |
| 93 | + { instanceId: from, requiresNewThreadForModelChange: true }, |
| 94 | + ] as unknown as ServerProvider[]; |
| 95 | + const starting = { |
| 96 | + ...projection, |
| 97 | + runs: [ |
| 98 | + ...projection.runs, |
| 99 | + { |
| 100 | + ...projection.runs[0]!, |
| 101 | + ...run("target", 2, instanceId, "destination"), |
| 102 | + status: "starting" as const, |
| 103 | + startedAt: null, |
| 104 | + contextHandoffId: ContextHandoffId.make("handoff"), |
| 105 | + }, |
| 106 | + ], |
| 107 | + }; |
| 108 | + |
| 109 | + expect(resolvePendingHandoff(projection, selection, providers)).not.toBeNull(); |
| 110 | + expect(resolvePendingHandoff(starting, selection, providers)).toBeNull(); |
| 111 | + expect( |
| 112 | + resolvePendingHandoff(starting, { instanceId: from, model: "source" }, providers), |
| 113 | + ).toEqual({ |
| 114 | + from: [selection], |
| 115 | + to: { instanceId: from, model: "source" }, |
| 116 | + }); |
| 117 | + }); |
| 118 | + |
| 119 | + it.each(["preparing", "queued", "failed", "cancelled", "rolled_back"] as const)( |
| 120 | + "keeps the preview when an unstarted handoff run is %s", |
| 121 | + (status) => { |
| 122 | + const selection = { instanceId: to, model: "destination" }; |
| 123 | + const unstarted = { |
| 124 | + ...projection, |
| 125 | + runs: [ |
| 126 | + ...projection.runs, |
| 127 | + { |
| 128 | + ...projection.runs[0]!, |
| 129 | + ...run("target", 2, to, "destination"), |
| 130 | + status, |
| 131 | + startedAt: null, |
| 132 | + contextHandoffId: ContextHandoffId.make("handoff"), |
| 133 | + }, |
| 134 | + ], |
| 135 | + }; |
| 136 | + |
| 137 | + expect(resolvePendingHandoff(unstarted, selection, [])).toEqual({ |
| 138 | + from: [{ instanceId: from, model: "source" }], |
| 139 | + to: selection, |
| 140 | + }); |
| 141 | + }, |
| 142 | + ); |
| 143 | + |
82 | 144 | it("appears on selection, updates the destination, and disappears on returning", () => { |
83 | 145 | expect(resolvePendingHandoff(projection, { instanceId: to, model: "first" }, [])).toEqual({ |
84 | 146 | from: [{ instanceId: from, model: "source" }], |
|
0 commit comments