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

orchestrationV2.test.ts

652 lines22.7 KB

1import { describe, expect, it } from "@effect/vitest";
2import * as DateTime from "effect/DateTime";
3import * as Schema from "effect/Schema";
4​
5import { NodeId, RunAttemptId, TrimmedNonEmptyString } from "./index.ts";
6import {
7 latestProviderTurnForAttempt,
8 OrchestrationV2CheckpointFileSummary,
9 OrchestrationV2ProviderCapabilities,
10 OrchestrationV2ProviderThread,
11 OrchestrationV2ProviderThreadJson,
12 OrchestrationV2RpcSchemas,
13 OrchestrationV2Subagent,
14 OrchestrationV2ThreadShellJson,
15 OrchestrationV2SubagentJson,
16 OrchestrationV2ThreadHistoryPage,
17 OrchestrationV2TurnItem,
18 OrchestrationV2TurnItemJson,
19} from "./orchestrationV2.ts";
20​
21const now = DateTime.makeUnsafe("2026-04-20T00:00:00.000Z");
22​
23const decodeOrchestrationV2TurnItemJson = Schema.decodeUnknownSync(OrchestrationV2TurnItemJson);
24const encodeOrchestrationV2TurnItemJson = Schema.encodeSync(OrchestrationV2TurnItemJson);
25const decodeOrchestrationV2Subagent = Schema.decodeUnknownSync(OrchestrationV2Subagent);
26const decodeCheckpointFileSummary = Schema.decodeSync(OrchestrationV2CheckpointFileSummary);
27const encodeOrchestrationV2SubagentJson = Schema.encodeSync(OrchestrationV2SubagentJson);
28const decodeOrchestrationV2ProviderThreadJson = Schema.decodeUnknownSync(
29 OrchestrationV2ProviderThreadJson,
30);
31const encodeOrchestrationV2ProviderThreadJson = Schema.encodeSync(
32 OrchestrationV2ProviderThreadJson,
33);
34const decodeOrchestrationV2ProviderThread = Schema.decodeUnknownSync(OrchestrationV2ProviderThread);
35const decodeOrchestrationV2ProviderCapabilities = Schema.decodeUnknownSync(
36 OrchestrationV2ProviderCapabilities,
37);
38​
39describe("orchestration V2 contracts", () => {
40 it("decodes thread event types from a newer server as skippable items", () => {
41 const decodeWireItems = Schema.decodeUnknownSync(
42 Schema.toCodecJson(Schema.Array(OrchestrationV2RpcSchemas.subscribeThread.output)),
43 );
44 const detached = (id: string, sequence: number) => ({
45 kind: "event",
46 sequence,
47 event: {
48 id,
49 type: "provider-session.detached",
50 threadId: "thread-1",
51 occurredAt: DateTime.formatIso(now),
52 payload: { providerSessionId: "provider-session-1", detachedAt: DateTime.formatIso(now) },
53 },
54 });
55​
56 const items = decodeWireItems([
57 detached("event-1", 1),
58 {
59 kind: "event",
60 sequence: 2,
61 event: {
62 id: "event-2",
63 type: "run.from-a-future-server",
64 threadId: "thread-1",
65 occurredAt: DateTime.formatIso(now),
66 payload: { runId: "run-1" },
67 },
68 },
69 detached("event-3", 3),
70 ]);
71​
72 expect(items.map((item) => item.kind)).toEqual(["event", "unknown-event", "event"]);
73 expect(items[1]).toEqual({
74 kind: "unknown-event",
75 sequence: 2,
76 eventType: "run.from-a-future-server",
77 });
78 expect(() =>
79 decodeWireItems([
80 { ...detached("event-4", 4), event: { ...detached("event-4", 4).event, payload: {} } },
81 ]),
82 ).toThrow();
83 });
84​
85 it("skips turn item types from a newer server in snapshots and turn-item events", () => {
86 const decodeWireItems = Schema.decodeUnknownSync(
87 Schema.toCodecJson(Schema.Array(OrchestrationV2RpcSchemas.subscribeThread.output)),
88 );
89 const decodeHistoryPage = Schema.decodeUnknownSync(
90 Schema.toCodecJson(OrchestrationV2ThreadHistoryPage),
91 );
92 const item = (id: string, type: string, extra: Record<string, unknown>) => ({
93 id,
94 type,
95 threadId: "thread-1",
96 runId: null,
97 nodeId: null,
98 providerThreadId: null,
99 providerTurnId: null,
100 nativeItemRef: null,
101 parentItemId: null,
102 ordinal: 1,
103 status: "completed",
104 title: null,
105 startedAt: null,
106 completedAt: null,
107 updatedAt: DateTime.formatIso(now),
108 ...extra,
109 });
110 const known = item("item-known", "system_notice", { message: "Hello" });
111 const future = item("item-future", "hologram", { beam: "ref-1" });
112 const projected = (position: number, turnItem: { readonly id: string }) => ({
113 position,
114 visibility: "local",
115 sourceThreadId: "thread-1",
116 sourceItemId: turnItem.id,
117 item: turnItem,
118 });
119 const projection = {
120 thread: {
121 createdBy: "user",
122 creationSource: "web",
123 id: "thread-1",
124 projectId: "project-1",
125 title: "Thread",
126 providerInstanceId: "codex",
127 modelSelection: { instanceId: "codex", model: "gpt-5-codex" },
128 runtimeMode: "full-access",
129 interactionMode: "default",
130 branch: null,
131 worktreePath: null,
132 activeProviderThreadId: null,
133 lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: "thread-1" },
134 forkedFrom: null,
135 createdAt: DateTime.formatIso(now),
136 updatedAt: DateTime.formatIso(now),
137 archivedAt: null,
138 deletedAt: null,
139 },
140 runs: [],
141 attempts: [],
142 nodes: [],
143 subagents: [],
144 providerSessions: [],
145 providerThreads: [],
146 providerTurns: [],
147 runtimeRequests: [],
148 messages: [],
149 plans: [],
150 turnItems: [future, known],
151 checkpointScopes: [],
152 checkpoints: [],
153 contextHandoffs: [],
154 contextTransfers: [],
155 visibleTurnItems: [projected(0, future), projected(1, known)],
156 updatedAt: DateTime.formatIso(now),
157 };
158 const turnItemEvent = (sequence: number, payload: unknown) => ({
159 kind: "event",
160 sequence,
161 event: {
162 id: `event-${sequence}`,
163 type: "turn-item.updated",
164 threadId: "thread-1",
165 occurredAt: DateTime.formatIso(now),
166 payload,
167 },
168 });
169​
170 const [snapshot, futureEvent, knownEvent] = decodeWireItems([
171 { kind: "snapshot", snapshotSequence: 1, projection },
172 turnItemEvent(2, future),
173 turnItemEvent(3, known),
174 ]);
175​
176 expect(snapshot).toMatchObject({ kind: "snapshot" });
177 if (snapshot?.kind !== "snapshot") throw new Error("expected a snapshot");
178 expect(snapshot.projection.turnItems.map((turnItem) => turnItem.id)).toEqual(["item-known"]);
179 expect(snapshot.projection.visibleTurnItems.map((row) => row.item.id)).toEqual(["item-known"]);
180 // The same snapshot with an ID table: refs resolve before unknown items are skipped.
181 const tabled = (turnItem: { readonly id: string }, ref: number) => ({ ...turnItem, id: ref });
182 const [tabledSnapshot] = decodeWireItems([
183 {
184 kind: "snapshot",
185 snapshotSequence: 1,
186 projection: {
187 ...projection,
188 turnItems: [tabled(future, 0), tabled(known, 1)],
189 visibleTurnItems: [
190 { ...projected(0, future), sourceItemId: 0, item: tabled(future, 0) },
191 { ...projected(1, known), sourceItemId: 1, item: tabled(known, 1) },
192 ],
193 },
194 ids: ["item-future", "item-known"],
195 },
196 ]);
197 expect(tabledSnapshot).toEqual(snapshot);
198 expect(futureEvent).toEqual({
199 kind: "unknown-event",
200 sequence: 2,
201 eventType: "turn-item.updated",
202 });
203 expect(knownEvent).toMatchObject({
204 kind: "event",
205 event: { type: "turn-item.updated", payload: { id: "item-known", type: "system_notice" } },
206 });
207 expect(
208 decodeHistoryPage({
209 snapshotSequence: 1,
210 items: [projected(0, future), projected(1, known)],
211 nextCursor: null,
212 hasMoreHistory: false,
213 }).items.map((row) => row.item.id),
214 ).toEqual(["item-known"]);
215​
216 const broken = item("item-broken", "system_notice", {});
217 expect(() => decodeWireItems([turnItemEvent(4, broken)])).toThrow();
218 expect(() =>
219 decodeWireItems([
220 {
221 kind: "snapshot",
222 snapshotSequence: 1,
223 projection: { ...projection, turnItems: [broken] },
224 },
225 ]),
226 ).toThrow();
227 });
228​
229 it("decodes persisted capability snapshots that predate runtimePolicy", () => {
230 const legacyCapabilities = {
231 sessions: {
232 supportsMultipleProviderThreadsPerSession: false,
233 supportsModelSwitchInSession: false,
234 supportsProviderSwitchingViaHandoff: true,
235 supportsRuntimeModeSwitchInSession: false,
236 pendingRequestsSurviveRestart: false,
237 },
238 threads: {
239 canCreateEmptyThread: true,
240 canReadThreadSnapshot: false,
241 canRollbackThread: true,
242 canForkThread: false,
243 canForkFromTurn: false,
244 canForkFromSubagentThread: false,
245 exposesNativeThreadId: true,
246 },
247 turns: {
248 exposesNativeTurnId: false,
249 emitsTurnStarted: true,
250 emitsTurnCompleted: true,
251 supportsInterrupt: true,
252 supportsActiveSteering: false,
253 supportsSteeringByInterruptRestart: true,
254 supportsQueuedMessages: true,
255 terminalStatusQuality: "strong",
256 },
257 streaming: {
258 streamsAssistantText: true,
259 streamsReasoning: true,
260 streamsToolOutput: true,
261 streamsPlanText: false,
262 emitsMessageCompleted: true,
263 },
264 tools: {
265 exposesToolItemIds: true,
266 emitsToolStarted: true,
267 emitsToolCompleted: true,
268 emitsToolOutput: true,
269 supportsMcpTools: false,
270 supportsDynamicToolCallbacks: false,
271 },
272 approvals: {
273 supportsCommandApproval: true,
274 supportsFileReadApproval: true,
275 supportsFileChangeApproval: true,
276 supportsApplyPatchApproval: false,
277 approvalsHaveNativeRequestIds: false,
278 approvalCallbacksAreLiveOnly: true,
279 approvalsCanOriginateFromSubagents: false,
280 },
281 planning: {
282 emitsPlanUpdated: true,
283 emitsTodoList: true,
284 emitsProposedPlan: false,
285 supportsStructuredQuestions: true,
286 planDeltasHaveItemIds: false,
287 },
288 subagents: {
289 supportsSubagents: false,
290 exposesSubagentThreadIds: false,
291 emitsSubagentLifecycle: false,
292 canWaitForSubagents: false,
293 canCloseSubagents: false,
294 canForkSubagentThread: false,
295 },
296 context: {
297 acceptsSystemContext: false,
298 acceptsDeveloperContext: false,
299 acceptsSyntheticUserContext: true,
300 canGenerateSummaries: true,
301 canConsumeHandoffSummaries: true,
302 supportsDeltaHandoff: true,
303 supportsFullThreadHandoff: true,
304 maxRecommendedHandoffChars: null,
305 },
306 checkpointing: {
307 appCanCheckpointFilesystem: true,
308 supportsNestedCheckpointScopes: true,
309 providerCanRollbackConversation: true,
310 providerRollbackReturnsSnapshot: true,
311 providerCanReadConversationSnapshot: false,
312 },
313 identity: {
314 nativeThreadIds: "strong",
315 nativeTurnIds: "weak",
316 nativeItemIds: "weak",
317 nativeRequestIds: "weak",
318 },
319 };
320​
321 const decoded = decodeOrchestrationV2ProviderCapabilities(legacyCapabilities);
322 expect(decoded.runtimePolicy).toEqual({ enforcement: "client-boundary" });
323​
324 const explicit = decodeOrchestrationV2ProviderCapabilities({
325 ...legacyCapabilities,
326 runtimePolicy: { enforcement: "native" },
327 });
328 expect(explicit.runtimePolicy).toEqual({ enforcement: "native" });
329 });
330​
331 it.each([" indented prompt\n", "\n \t\n"])(
332 "preserves workflow prompt and result %j in stored and wire JSON",
333 (preview) => {
334 const subagent = {
335 ...decodeOrchestrationV2Subagent({
336 id: "workflow-coordinator",
337 threadId: "thread-1",
338 runId: "run-1",
339 parentNodeId: "node-root-1",
340 origin: "provider_native",
341 createdBy: "agent",
342 driver: "claudeAgent",
343 providerInstanceId: "claudeAgent",
344 providerThreadId: null,
345 childThreadId: null,
346 nativeTaskRef: null,
347 prompt: "Run workflow",
348 title: null,
349 model: null,
350 status: "running",
351 result: null,
352 startedAt: now,
353 completedAt: null,
354 updatedAt: now,
355 }),
356 workflow: {
357 phases: [],
358 agents: [
359 {
360 index: 1,
361 label: "Member",
362 state: "completed" as const,
363 model: "claude-opus-5[1m]",
364 effort: "xhigh",
365 speed: "standard",
366 prompt: preview,
367 result: preview,
368 },
369 ],
370 },
371 };
372 const { workflow, ...coordinator } = subagent;
373 const incoming = { ...encodeOrchestrationV2SubagentJson(coordinator), workflow };
374 for (const codec of [
375 OrchestrationV2SubagentJson,
376 Schema.toCodecJson(OrchestrationV2Subagent),
377 ]) {
378 const encode = Schema.encodeSync(codec);
379 const decode = Schema.decodeUnknownSync(codec);
380 const json: unknown = JSON.parse(JSON.stringify(encode(subagent)));
381 expect(json).toMatchObject({
382 workflow: { agents: [{ prompt: preview, result: preview }] },
383 });
384 expect(decode(json).workflow?.agents[0]).toMatchObject({
385 prompt: preview,
386 result: preview,
387 model: "claude-opus-5[1m]",
388 effort: "xhigh",
389 speed: "standard",
390 });
391 expect(decode(incoming).workflow?.agents[0]).toMatchObject({
392 prompt: preview,
393 result: preview,
394 model: "claude-opus-5[1m]",
395 effort: "xhigh",
396 speed: "standard",
397 });
398 }
399 },
400 );
401​
402 it.each([" leading.ts", "src/trailing.ts "])(
403 "decodes the checkpoint file path %j exactly",
404 (path) => {
405 expect(
406 decodeCheckpointFileSummary({ path, kind: "added", additions: 1, deletions: 0 }).path,
407 ).toBe(path);
408 },
409 );
410​
411 it("decodes historical provider-thread JSON without pendingBackgroundTasks as empty roster", () => {
412 const providerThread = decodeOrchestrationV2ProviderThreadJson({
413 id: "provider-thread-1",
414 driver: "claude",
415 providerInstanceId: "claudeAgent",
416 providerSessionId: "provider-session-1",
417 appThreadId: "thread-1",
418 ownerNodeId: null,
419 nativeThreadRef: {
420 driver: "claude",
421 nativeId: "native-session-1",
422 strength: "strong",
423 },
424 nativeConversationHeadRef: null,
425 status: "idle",
426 firstRunOrdinal: 1,
427 lastRunOrdinal: 1,
428 handoffIds: [],
429 forkedFrom: null,
430 createdAt: "2026-04-20T00:00:00.000Z",
431 updatedAt: "2026-04-20T00:00:00.000Z",
432 });
433​
434 expect(providerThread.pendingBackgroundTasks).toEqual([]);
435 expect(providerThread.contextUsage).toBeNull();
436 expect(providerThread.nativeMetadata).toBeNull();
437​
438 const runtimeThread = decodeOrchestrationV2ProviderThread({
439 id: "provider-thread-2",
440 driver: "claude",
441 providerInstanceId: "claudeAgent",
442 providerSessionId: null,
443 appThreadId: "thread-2",
444 ownerNodeId: null,
445 nativeThreadRef: null,
446 nativeConversationHeadRef: null,
447 status: "idle",
448 firstRunOrdinal: null,
449 lastRunOrdinal: null,
450 handoffIds: [],
451 forkedFrom: null,
452 createdAt: now,
453 updatedAt: now,
454 });
455 expect(runtimeThread.pendingBackgroundTasks).toEqual([]);
456 expect(runtimeThread.contextUsage).toBeNull();
457 expect(runtimeThread.nativeMetadata).toBeNull();
458 });
459});
460​
461describe("thread open stats", () => {
462 it("reads a thread whose open stats this build cannot read, without them", () => {
463 const shell = {
464 id: "thread-test",
465 projectId: "project-test",
466 title: "Thread",
467 providerInstanceId: "codex",
468 modelSelection: { instanceId: "codex", model: "gpt-5.4" },
469 runtimeMode: "full-access",
470 interactionMode: "default",
471 branch: null,
472 worktreePath: null,
473 activeProviderThreadId: null,
474 lineage: { rootThreadId: "thread-test", parentThreadId: null, relationshipToParent: null },
475 forkedFrom: null,
476 createdBy: "user",
477 creationSource: "mobile",
478 latestRunId: null,
479 activeRunId: null,
480 status: "idle",
481 pendingRuntimeRequest: null,
482 latestVisibleMessage: null,
483 latestUserMessageAt: null,
484 hasActionableProposedPlan: false,
485 itemCount: 0,
486 visibleItemCount: 0,
487 createdAt: "2026-10-01T00:00:00.000Z",
488 updatedAt: "2026-10-01T00:00:00.000Z",
489 archivedAt: null,
490 settledOverride: null,
491 settledAt: null,
492 deletedAt: null,
493 };
494 const decode = Schema.decodeUnknownSync(OrchestrationV2ThreadShellJson);
495 const opens = { openedAt: 1, score: 1, picks: [{ query: "upl", at: 1 }] };
496 expect(decode({ ...shell, opens }).opens).toEqual(opens);
497 expect(decode({ ...shell, opens: { openedAt: "2026-10-01", score: 1 } }).opens).toBeNull();
498 });
499});
500​
501describe("background work kinds from older or newer servers", () => {
502 const storedNotification = (source: unknown) => ({
503 id: "notification",
504 threadId: "parent",
505 runId: null,
506 nodeId: null,
507 providerThreadId: null,
508 providerTurnId: null,
509 nativeItemRef: null,
510 parentItemId: null,
511 ordinal: 1,
512 status: "completed",
513 title: null,
514 startedAt: null,
515 completedAt: null,
516 updatedAt: "2026-09-09T00:00:00.000Z",
517 type: "notification",
518 outcome: "completed",
519 summary: "Background activity updated",
520 source,
521 });
522​
523 it("decodes notification sources stored before specific kinds existed", () => {
524 const sourceOf = (source: unknown) => {
525 const item = decodeOrchestrationV2TurnItemJson(storedNotification(source));
526 return item.type === "notification" ? item.source : undefined;
527 };
528 expect(
529 sourceOf({ kind: "background_task", nativeRef: { driver: "claude", nativeId: "task-1" } }),
530 ).toEqual({ kind: "background_task" });
531 expect(sourceOf({ kind: "background_command" })).toEqual({ kind: "command" });
532 expect(sourceOf({ kind: "monitor" })).toEqual({ kind: "monitor" });
533 });
534​
535 it("sends and stores sources that clients from before specific kinds still decode", () => {
536 const PreSpecificKindsNotification = Schema.Struct({
537 type: Schema.Literal("notification"),
538 source: Schema.Union([
539 Schema.Struct({ kind: Schema.Literal("delegated_task"), taskIds: Schema.Array(NodeId) }),
540 Schema.Struct({
541 kind: Schema.Literals(["background_task", "background_command", "monitor"]),
542 nativeRef: Schema.optional(Schema.Unknown),
543 }),
544 ]),
545 outcome: Schema.Literals(["completed", "failed", "cancelled", "updated", "unknown"]),
546 summary: Schema.String,
547 detail: Schema.optional(Schema.String),
548 });
549 const decodePreSpecificKinds = Schema.decodeUnknownSync(PreSpecificKindsNotification);
550 const sendOverWire = Schema.encodeSync(Schema.toCodecJson(OrchestrationV2TurnItem));
551 const cases = [
552 [{ kind: "subagent", childThreadId: "child" }, { kind: "background_task" }],
553 [{ kind: "subagent" }, { kind: "background_task" }],
554 [{ kind: "command" }, { kind: "background_command" }],
555 [{ kind: "monitor" }, { kind: "monitor" }],
556 [{ kind: "background_task" }, { kind: "background_task" }],
557 [
558 { kind: "delegated_task", taskIds: ["task-1"], childThreadId: "child" },
559 { kind: "delegated_task", taskIds: ["task-1"] },
560 ],
561 ] as const;
562 for (const [source, preSpecificKindsSource] of cases) {
563 const item = decodeOrchestrationV2TurnItemJson(storedNotification(source));
564 for (const encoded of [encodeOrchestrationV2TurnItemJson(item), sendOverWire(item)]) {
565 expect(decodePreSpecificKinds(encoded).source).toEqual(preSpecificKindsSource);
566 expect(decodeOrchestrationV2TurnItemJson(encoded)).toEqual(item);
567 }
568 expect(item).toMatchObject({ source });
569 }
570 });
571​
572 it("decodes a notification source kind from a newer server as generic background work", () => {
573 const item = decodeOrchestrationV2TurnItemJson(
574 storedNotification({ kind: "workflow", workflowId: "wf-1" }),
575 );
576 expect(item).toMatchObject({ type: "notification", source: { kind: "background_task" } });
577 });
578​
579 it("decodes rosters stored before kinds existed, and kinds from a newer server, as generic tasks", () => {
580 const providerThread = decodeOrchestrationV2ProviderThreadJson({
581 id: "provider-thread-1",
582 driver: "claude",
583 providerInstanceId: "claudeAgent",
584 providerSessionId: null,
585 appThreadId: "thread-1",
586 ownerNodeId: null,
587 nativeThreadRef: null,
588 nativeConversationHeadRef: null,
589 status: "idle",
590 firstRunOrdinal: 1,
591 lastRunOrdinal: 1,
592 handoffIds: [],
593 forkedFrom: null,
594 createdAt: "2026-04-20T00:00:00.000Z",
595 updatedAt: "2026-04-20T00:00:00.000Z",
596 pendingBackgroundTasks: [
597 { taskId: "bg-1", description: "Background sleep", taskType: "local_bash" },
598 { taskId: "bg-2" },
599 { taskId: "bg-3", description: "Nightly", kind: "workflow", schedule: "0 3 * * *" },
600 { taskId: "bg-4", description: "npm test", kind: "command" },
601 { taskId: "bg-5", kind: "subagent", childThreadId: "thread-child" },
602 { taskId: "bg-6", kind: "subagent", providerInstanceId: "claudeAgent" },
603 ],
604 });
605 expect(providerThread.pendingBackgroundTasks).toEqual([
606 { taskId: "bg-1", description: "Background sleep", kind: "background_task" },
607 { taskId: "bg-2", kind: "background_task" },
608 { taskId: "bg-3", description: "Nightly", kind: "background_task" },
609 { taskId: "bg-4", description: "npm test", kind: "command" },
610 { taskId: "bg-5", kind: "subagent", childThreadId: "thread-child" },
611 { taskId: "bg-6", kind: "subagent", providerInstanceId: "claudeAgent" },
612 ]);
613 const encoded = encodeOrchestrationV2ProviderThreadJson(providerThread).pendingBackgroundTasks;
614 expect(encoded).toEqual(providerThread.pendingBackgroundTasks);
615 const decodePreKindsRoster = Schema.decodeUnknownSync(
616 Schema.Array(
617 Schema.Struct({
618 taskId: TrimmedNonEmptyString,
619 description: Schema.optional(TrimmedNonEmptyString),
620 taskType: Schema.optional(TrimmedNonEmptyString),
621 }),
622 ),
623 );
624 expect(decodePreKindsRoster(encoded).map((task) => task.taskId)).toEqual([
625 "bg-1",
626 "bg-2",
627 "bg-3",
628 "bg-4",
629 "bg-5",
630 "bg-6",
631 ]);
632 expect(() =>
633 decodeOrchestrationV2ProviderThreadJson({
634 ...encodeOrchestrationV2ProviderThreadJson(providerThread),
635 pendingBackgroundTasks: [{ taskId: "", kind: "command" }],
636 }),
637 ).toThrow();
638 });
639});
640​
641describe("latestProviderTurnForAttempt", () => {
642 it("returns the attempt's highest-ordinal turn, as a Codex goal run spans several", () => {
643 const turns = [
644 { id: "first", runAttemptId: RunAttemptId.make("goal-attempt"), ordinal: 3 },
645 { id: "other", runAttemptId: RunAttemptId.make("other-attempt"), ordinal: 9 },
646 { id: "last", runAttemptId: RunAttemptId.make("goal-attempt"), ordinal: 5 },
647 { id: "subagent", runAttemptId: null, ordinal: 7 },
648 ];
649 expect(latestProviderTurnForAttempt(turns, RunAttemptId.make("goal-attempt"))?.id).toBe("last");
650 expect(latestProviderTurnForAttempt(turns, null)).toBeUndefined();
651 });
652});