Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

TransferBudgetV2Fixture.integration.ts

408 lines12.0 KB

1import {
2 CheckpointId,
3 CheckpointScopeId,
4 EventId,
5 MessageId,
6 NodeId,
7 ProjectId,
8 ProviderInstanceId,
9 RunId,
10 ThreadId,
11 TurnItemId,
12 type ProviderDriverKind,
13 type OrchestrationV2DomainEvent,
14 type OrchestrationV2TurnItem,
15} from "@t3tools/contracts";
16import * as DateTime from "effect/DateTime";
17import {
18 diagnosticOutput,
19 TRANSFER_HISTORY_TOOLS_PER_TURN,
20 TRANSFER_MEASURED_TOOLS,
21 TRANSFER_HISTORY_MCP_RESULT_BYTES,
22 TRANSFER_MEASURED_MCP_RESULT_BYTES,
23} from "./fixtures/transferBudget.ts";
24​
25export const THREAD_ID = ThreadId.make("transfer-budget-thread");
26export function threadCreated(
27 provider: ProviderDriverKind,
28 threadId: ThreadId = THREAD_ID,
29): OrchestrationV2DomainEvent {
30 const now = DateTime.makeUnsafe("2026-06-01T00:00:00Z");
31 return {
32 id: EventId.make(`thread-created:${threadId}`),
33 type: "thread.created",
34 threadId,
35 occurredAt: now,
36 payload: {
37 id: threadId,
38 projectId: ProjectId.make("transfer-project"),
39 title: "Transfer budget",
40 providerInstanceId: ProviderInstanceId.make(provider),
41 modelSelection: {
42 instanceId: ProviderInstanceId.make(provider),
43 model: provider === "codex" ? "gpt-5.4" : "claude-sonnet-4-6",
44 },
45 runtimeMode: "full-access",
46 interactionMode: "default",
47 branch: null,
48 worktreePath: null,
49 activeProviderThreadId: null,
50 lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId },
51 forkedFrom: null,
52 createdBy: "user",
53 creationSource: "web",
54 createdAt: now,
55 updatedAt: now,
56 archivedAt: null,
57 settledOverride: null,
58 settledAt: null,
59 lastVisitedAt: null,
60 deletedAt: null,
61 },
62 };
64export function turnEvents(
65 provider: ProviderDriverKind,
66 index: number,
67 measured: boolean,
68): ReadonlyArray<OrchestrationV2DomainEvent> {
69 const now = DateTime.makeUnsafe(`2026-06-01T00:${String(index + 1).padStart(2, "0")}:00Z`);
70 const runId = RunId.make(`run-${index}`);
71 const nodeId = NodeId.make(`node-${index}`);
72 const userMessageId = MessageId.make(`user-${index}`);
73 const providerInstanceId = ProviderInstanceId.make(provider);
74 const run = {
75 id: runId,
76 threadId: THREAD_ID,
77 ordinal: index + 1,
78 providerInstanceId,
79 modelSelection: {
80 instanceId: ProviderInstanceId.make(provider),
81 model: provider === "codex" ? "gpt-5.4" : "claude-sonnet-4-6",
82 },
83 providerThreadId: null,
84 userMessageId,
85 rootNodeId: nodeId,
86 activeAttemptId: null,
87 status: "running" as const,
88 requestedAt: now,
89 startedAt: now,
90 completedAt: null,
91 checkpointId: null,
92 contextHandoffId: null,
93 };
94 const common = {
95 threadId: THREAD_ID,
96 runId,
97 nodeId,
98 driver: provider,
99 providerInstanceId,
100 occurredAt: now,
101 };
102 const events: OrchestrationV2DomainEvent[] = [
103 { ...common, id: EventId.make(`run-${index}`), type: "run.created", payload: run },
104 ];
105 for (const role of ["user", "assistant"] as const) {
106 events.push({
107 ...common,
108 id: EventId.make(`${role}-${index}`),
109 type: "message.updated",
110 payload: {
111 id: MessageId.make(`${role}-${index}`),
112 threadId: THREAD_ID,
113 runId,
114 nodeId,
115 role,
116 text:
117 role === "user"
118 ? `Inspect transfer ${index}`
119 : `Completed ${provider} inspection ${index}. ` +
120 "The projection preserves transcript text and bounds tool output. ".repeat(60),
121 attachments: [],
122 streaming: false,
123 createdAt: now,
124 updatedAt: now,
125 createdBy: role === "user" ? "user" : "agent",
126 creationSource: "web",
127 },
128 });
129 }
130 const toolCount = measured ? TRANSFER_MEASURED_TOOLS : TRANSFER_HISTORY_TOOLS_PER_TURN;
131 for (let tool = 0; tool <= toolCount; tool++) {
132 const mcp = tool === toolCount;
133 const output = diagnosticOutput({
134 provider,
135 turnIndex: index,
136 toolIndex: tool,
137 targetBytes: mcp
138 ? measured
139 ? TRANSFER_MEASURED_MCP_RESULT_BYTES
140 : TRANSFER_HISTORY_MCP_RESULT_BYTES
141 : 4096,
142 });
143 const base = {
144 id: TurnItemId.make(`item-${index}-${tool}`),
145 threadId: THREAD_ID,
146 runId,
147 nodeId,
148 providerThreadId: null,
149 providerTurnId: null,
150 nativeItemRef: null,
151 parentItemId: null,
152 ordinal: tool + 1,
153 status: "completed" as const,
154 title: mcp ? "MCP search" : `Inspect source ${tool}`,
155 startedAt: now,
156 completedAt: now,
157 updatedAt: now,
158 };
159 events.push({
160 ...common,
161 id: EventId.make(`tool-${index}-${tool}`),
162 type: "turn-item.updated",
163 payload: mcp
164 ? {
165 ...base,
166 type: "dynamic_tool",
167 toolName: "mcp__test__search",
168 input: { query: "transfer" },
169 output: { text: output },
170 }
171 : {
172 ...base,
173 type: "command_execution",
174 input: `cat src/module-${tool}.ts`,
175 output,
176 exitCode: 0,
177 },
178 });
179 }
180 events.push({
181 ...common,
182 id: EventId.make(`complete-${index}`),
183 type: "run.updated",
184 payload: { ...run, status: "completed", completedAt: now },
185 });
186 return events;
188​
189export const LONG_TURN_THREAD_ID = ThreadId.make("transfer-budget-long-turn");
190export const LONG_TURN_WORK_ROWS = 900;
191​
192/**
193 * Three short user turns, then one agent turn far longer than a cold-open
194 * window, with the item kinds a long agent run produces. One batch per turn.
195 */
196export function longTurnThreadBatches(
197 provider: ProviderDriverKind,
198): ReadonlyArray<ReadonlyArray<OrchestrationV2DomainEvent>> {
199 const threadId = LONG_TURN_THREAD_ID;
200 const providerInstanceId = ProviderInstanceId.make(provider);
201 const modelSelection = {
202 instanceId: providerInstanceId,
203 model: provider === "codex" ? "gpt-5.4" : "claude-sonnet-4-6",
204 };
205 let ordinal = 0;
206 const text = (turn: number, row: number, targetBytes: number) =>
207 diagnosticOutput({ provider, turnIndex: 100 + turn, toolIndex: row, targetBytes });
208​
209 const turn = (index: number, workRows: number): OrchestrationV2DomainEvent[] => {
210 const now = DateTime.makeUnsafe(`2026-06-02T00:${String(index).padStart(2, "0")}:00Z`);
211 const runId = RunId.make(`long-turn-run-${index}`);
212 const nodeId = NodeId.make(`long-turn-node-${index}`);
213 const common = {
214 threadId,
215 runId,
216 nodeId,
217 driver: provider,
218 providerInstanceId,
219 occurredAt: now,
220 };
221 const run = {
222 id: runId,
223 threadId,
224 ordinal: index + 1,
225 providerInstanceId,
226 modelSelection,
227 providerThreadId: null,
228 userMessageId: MessageId.make(`long-turn-user-${index}`),
229 rootNodeId: nodeId,
230 activeAttemptId: null,
231 status: "running" as const,
232 requestedAt: now,
233 startedAt: now,
234 completedAt: null,
235 checkpointId: null,
236 contextHandoffId: null,
237 };
238 const base = (row: string, title: string | null) => {
239 ordinal += 1;
240 return {
241 id: TurnItemId.make(`long-turn-item-${index}-${row}`),
242 threadId,
243 runId,
244 nodeId,
245 providerThreadId: null,
246 providerTurnId: null,
247 nativeItemRef: null,
248 parentItemId: null,
249 ordinal,
250 status: "completed" as const,
251 title,
252 startedAt: now,
253 completedAt: now,
254 updatedAt: now,
255 };
256 };
257 const events: OrchestrationV2DomainEvent[] = [
258 { ...common, id: EventId.make(`long-turn-run-${index}`), type: "run.created", payload: run },
259 ];
260 const message = (role: "user" | "assistant", row: string, messageText: string) => {
261 const messageId = MessageId.make(`long-turn-${role}-${index}-${row}`);
262 const createdBy = role === "user" ? ("user" as const) : ("agent" as const);
263 events.push(
264 {
265 ...common,
266 id: EventId.make(`long-turn-message-${index}-${row}`),
267 type: "message.updated",
268 payload: {
269 id: messageId,
270 threadId,
271 runId,
272 nodeId,
273 role,
274 text: messageText,
275 attachments: [],
276 streaming: false,
277 createdAt: now,
278 updatedAt: now,
279 createdBy,
280 creationSource: "web",
281 },
282 },
283 {
284 ...common,
285 id: EventId.make(`long-turn-item-event-${index}-${row}`),
286 type: "turn-item.updated",
287 payload:
288 role === "user"
289 ? {
290 ...base(row, null),
291 type: "user_message",
292 createdBy,
293 creationSource: "web",
294 messageId,
295 inputIntent: "turn_start",
296 text: messageText,
297 attachments: [],
298 }
299 : {
300 ...base(row, null),
301 type: "assistant_message",
302 messageId,
303 text: messageText,
304 streaming: false,
305 },
306 },
307 );
308 };
309 const workItem = (row: number): OrchestrationV2TurnItem => {
310 if (row % 100 === 50) {
311 return {
312 ...base(String(row), "Checkpoint"),
313 type: "checkpoint",
314 checkpointId: CheckpointId.make(`long-turn-checkpoint-${index}-${row}`),
315 scopeId: CheckpointScopeId.make(`long-turn-scope-${index}`),
316 files: Array.from({ length: 40 }, (_, file) => ({
317 path: `src/feature/module-${row}-${file}.ts`,
318 kind: "modified",
319 additions: file + 1,
320 deletions: file,
321 })),
322 };
323 }
324 if (row % 100 === 99) {
325 return {
326 ...base(String(row), "Subagent"),
327 type: "subagent",
328 subagentId: NodeId.make(`long-turn-subagent-${index}-${row}`),
329 origin: "app_owned",
330 driver: provider,
331 providerInstanceId,
332 childThreadId: null,
333 prompt: text(index, row, 2_048),
334 result: text(index, row + 1, 3_072),
335 };
336 }
337 switch (row % 8) {
338 case 0:
339 case 7:
340 return {
341 ...base(String(row), "Reasoning"),
342 type: "reasoning",
343 text: text(index, row, 1_536),
344 streaming: false,
345 };
346 case 3:
347 return {
348 ...base(String(row), `Edit module ${row}`),
349 type: "file_change",
350 fileName: `src/feature/module-${row}.ts`,
351 additions: 12,
352 deletions: 4,
353 diffStr: text(index, row, 2_048),
354 };
355 case 4:
356 return {
357 ...base(String(row), "MCP search"),
358 type: "dynamic_tool",
359 toolName: "mcp__test__search",
360 input: { query: `module ${row}` },
361 output: { text: text(index, row, 6_144) },
362 };
363 case 5:
364 return {
365 ...base(String(row), null),
366 type: "assistant_message",
367 messageId: MessageId.make(`long-turn-progress-${index}-${row}`),
368 text: text(index, row, 600),
369 streaming: false,
370 };
371 default:
372 return {
373 ...base(String(row), `Run check ${row}`),
374 type: "command_execution",
375 input: `vp test run src/feature/module-${row}.test.ts`,
376 output: text(index, row, 4_096),
377 exitCode: 0,
378 };
379 }
380 };
381​
382 message("user", "prompt", `Continue the feature work, step ${index}.`);
383 for (let row = 0; row < workRows; row++) {
384 events.push({
385 ...common,
386 id: EventId.make(`long-turn-work-${index}-${row}`),
387 type: "turn-item.updated",
388 payload: workItem(row),
389 });
390 }
391 message("assistant", "answer", text(index, workRows, 1_200));
392 events.push({
393 ...common,
394 id: EventId.make(`long-turn-complete-${index}`),
395 type: "run.updated",
396 payload: { ...run, status: "completed", completedAt: now },
397 });
398 return events;
399 };
400​
401 return [
402 [threadCreated(provider, threadId)],
403 turn(0, 4),
404 turn(1, 4),
405 turn(2, 4),
406 turn(3, LONG_TURN_WORK_ROWS),
407 ];