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

threadExecution.test.ts

716 lines23.8 KB

1import {
2 TurnItemId,
3 NodeId,
4 MessageId,
5 ProviderInstanceId,
6 ProviderThreadId,
7 ProviderSessionId,
8 ProviderDriverKind,
9 RunId,
10 ThreadId,
11 type OrchestrationV2ExecutionNode,
12 type OrchestrationV2RunStatus,
13} from "@t3tools/contracts";
14import * as DateTime from "effect/DateTime";
15import { usageLimitBlockedRun } from "@t3tools/shared/orchestrationV2ThreadError";
16import { describe, expect, it } from "vite-plus/test";
17​
18import { v2Projection } from "./orchestrationV2TestFixtures.ts";
19import {
20 presentPendingBackgroundWork,
21 presentProviderGoal,
22 deriveReportedModelSelection,
23 deriveLatestThreadRun,
24 deriveProviderSubagentStatus,
25 formatModelSelectionEffort,
26 formatProviderSubagentStatus,
27 deriveRunlessWorkStartedAt,
28 deriveThreadActivityRun,
29 deriveThreadRuntime,
30 threadRuntimeHasInterruptibleRun,
31} from "./threadExecution.ts";
32import { threadRuntimeCanArchive, type ThreadRuntimeSummary } from "./models.ts";
33​
34const now = DateTime.makeUnsafe("2026-07-28T10:00:00.000Z");
35​
36function run(id: string, ordinal: number, status: OrchestrationV2RunStatus) {
37 return {
38 id: RunId.make(id),
39 threadId: v2Projection.thread.id,
40 ordinal,
41 providerInstanceId: v2Projection.thread.providerInstanceId,
42 modelSelection: v2Projection.thread.modelSelection,
43 providerThreadId: null,
44 userMessageId: MessageId.make(`message-${id}`),
45 rootNodeId: null,
46 activeAttemptId: null,
47 status,
48 requestedAt: now,
49 startedAt: status === "queued" ? null : now,
50 completedAt: null,
51 checkpointId: null,
52 contextHandoffId: null,
53 };
55​
56describe("thread execution presentation", () => {
57 it("derives the current root failure without inheriting errors from children or previous runs", () => {
58 const failed = { ...run("limited", 1, "failed"), rootNodeId: NodeId.make("root") };
59 const item = {
60 id: TurnItemId.make("limit-error"),
61 threadId: v2Projection.thread.id,
62 runId: failed.id,
63 nodeId: failed.rootNodeId,
64 providerThreadId: null,
65 providerTurnId: null,
66 nativeItemRef: null,
67 parentItemId: null,
68 ordinal: 1,
69 type: "error" as const,
70 status: "failed" as const,
71 title: "Usage limit reached",
72 startedAt: now,
73 completedAt: now,
74 updatedAt: now,
75 failure: {
76 class: "usage_limit" as const,
77 message: "Plan limit reached",
78 code: "usageLimitExceeded",
79 retryable: null,
80 },
81 };
82 const projection = { ...v2Projection, runs: [failed], turnItems: [item] };
83 expect(deriveThreadRuntime(projection)).toMatchObject({
84 lastError: "Plan limit reached",
85 lastErrorClass: "usage_limit",
86 });
87 expect(
88 deriveThreadRuntime({
89 ...projection,
90 turnItems: [{ ...item, nodeId: NodeId.make("child") }],
91 }),
92 ).toMatchObject({ lastError: null, lastErrorClass: null });
93 expect(
94 deriveThreadRuntime({
95 ...projection,
96 runs: [{ ...failed, rootNodeId: NodeId.make("new-root") }],
97 }),
98 ).toMatchObject({ lastError: null, lastErrorClass: null });
99 expect(
100 deriveThreadRuntime({ ...projection, runs: [failed, run("new", 2, "running")] }),
101 ).toMatchObject({ status: "running", lastError: null, lastErrorClass: null });
102 });
103​
104 it("counts a wake run's activity from the start of the work it continues", () => {
105 const workStartedAt = DateTime.makeUnsafe("2026-07-28T09:20:00.000Z");
106 const wake = { ...run("wake", 2, "running"), workStartedAt };
107 expect(
108 deriveThreadRuntime({ ...v2Projection, runs: [run("prompt", 1, "completed"), wake] })
109 ?.activityStartedAt,
110 ).toBe("2026-07-28T09:20:00.000Z");
111 expect(
112 deriveThreadRuntime({ ...v2Projection, runs: [run("prompt", 1, "running")] })
113 ?.activityStartedAt,
114 ).toBe("2026-07-28T10:00:00.000Z");
115 });
116​
117 it("keeps a subscription limit visible while later messages stay queued", () => {
118 const failed = {
119 ...run("limited", 1, "failed"),
120 rootNodeId: NodeId.make("root"),
121 completedAt: now,
122 };
123 const queued = run("queued", 2, "queued");
124 const item = {
125 id: TurnItemId.make("limit-error"),
126 threadId: v2Projection.thread.id,
127 runId: failed.id,
128 nodeId: failed.rootNodeId,
129 providerThreadId: null,
130 providerTurnId: null,
131 nativeItemRef: null,
132 parentItemId: null,
133 ordinal: 1,
134 type: "error" as const,
135 status: "failed" as const,
136 title: "Usage limit reached",
137 startedAt: now,
138 completedAt: now,
139 updatedAt: now,
140 failure: {
141 class: "usage_limit" as const,
142 message: "Plan limit reached",
143 code: "usageLimitExceeded",
144 retryable: null,
145 },
146 };
147 const projection = { ...v2Projection, runs: [failed, queued], turnItems: [item] };
148​
149 expect(deriveLatestThreadRun(projection)?.runId).toBe(failed.id);
150 expect(deriveThreadActivityRun(projection)?.runId).toBe(failed.id);
151 expect(deriveThreadRuntime(projection)).toMatchObject({
152 status: "failed",
153 lastError: "Plan limit reached",
154 lastErrorClass: "usage_limit",
155 });
156 const cancelledQueued = {
157 ...run("cancelled-queued", 3, "cancelled"),
158 startedAt: null,
159 completedAt: now,
160 };
161 expect(
162 usageLimitBlockedRun([failed, queued, cancelledQueued], projection.turnItems, null)?.id,
163 ).toBe(failed.id);
164 expect(
165 deriveThreadRuntime({ ...projection, runs: [failed, queued, cancelledQueued] }),
166 ).toMatchObject({ status: "failed", lastErrorClass: "usage_limit" });
167 expect(
168 deriveThreadRuntime({
169 ...projection,
170 turnItems: [{ ...item, failure: { ...item.failure, class: "provider_error" as const } }],
171 }),
172 ).toMatchObject({ status: "queued", lastErrorClass: null });
173 });
174​
175 it("keeps live activity attached to an executing run when a newer run is queued", () => {
176 const runningRun = run("run-running", 1, "running");
177 const queuedRun = run("run-queued", 2, "queued");
178 const projection = { ...v2Projection, runs: [queuedRun, runningRun], updatedAt: now };
179​
180 expect(deriveLatestThreadRun(projection)?.runId).toBe(queuedRun.id);
181 expect(deriveThreadActivityRun(projection)).toMatchObject({
182 runId: runningRun.id,
183 status: "running",
184 });
185​
186 const runtime = deriveThreadRuntime(projection);
187 expect(runtime).toMatchObject({
188 status: "running",
189 activeRunId: runningRun.id,
190 });
191 expect(threadRuntimeHasInterruptibleRun(runtime)).toBe(true);
192 });
193​
194 it("presents a held queue as the stopped run instead of queued work", () => {
195 const interrupted = { ...run("run-interrupted", 1, "interrupted"), completedAt: now };
196 const held = { ...run("run-held", 2, "queued"), queueHeld: true };
197 const projection = { ...v2Projection, runs: [interrupted, held], updatedAt: now };
198​
199 expect(deriveLatestThreadRun(projection)?.runId).toBe(interrupted.id);
200 expect(deriveThreadActivityRun(projection)?.runId).toBe(interrupted.id);
201 expect(deriveThreadRuntime(projection)).toMatchObject({
202 status: "interrupted",
203 activeRunId: null,
204 });
205​
206 const resumed = { ...projection, runs: [interrupted, { ...held, queueHeld: false }] };
207 expect(deriveThreadRuntime(resumed)).toMatchObject({ status: "queued" });
208​
209 const onlyHeld = {
210 ...projection,
211 runs: [held],
212 thread: { ...projection.thread, activeProviderThreadId: null },
213 };
214 expect(deriveLatestThreadRun(onlyHeld)).toBeNull();
215 expect(deriveThreadRuntime(onlyHeld)).toBeNull();
216 });
217​
218 it("does not expose a queued-only run as interruptible", () => {
219 const queuedRun = run("run-queued", 1, "queued");
220 const projection = { ...v2Projection, runs: [queuedRun], updatedAt: now };
221​
222 expect(deriveThreadActivityRun(projection)).toMatchObject({
223 runId: queuedRun.id,
224 status: "queued",
225 });
226​
227 const runtime = deriveThreadRuntime(projection);
228 expect(runtime).toMatchObject({
229 status: "queued",
230 activeRunId: null,
231 });
232 expect(threadRuntimeHasInterruptibleRun(runtime)).toBe(false);
233 });
234​
235 it("keeps checkpoint-wait activity visible without exposing a non-functional interrupt", () => {
236 const waitingRun = run("run-waiting", 1, "waiting");
237 const projection = { ...v2Projection, runs: [waitingRun], updatedAt: now };
238​
239 expect(deriveThreadActivityRun(projection)).toMatchObject({
240 runId: waitingRun.id,
241 status: "waiting",
242 });
243​
244 const runtime = deriveThreadRuntime(projection);
245 expect(runtime).toMatchObject({
246 status: "waiting",
247 activeRunId: null,
248 });
249 expect(threadRuntimeHasInterruptibleRun(runtime)).toBe(false);
250 });
251​
252 it("does not expose a stale active run after the runtime parks at idle", () => {
253 const runtime = {
254 status: "idle" as const,
255 activeRunId: RunId.make("run-stale"),
256 providerInstanceId: v2Projection.thread.providerInstanceId,
257 providerName: null,
258 lastError: null,
259 updatedAt: DateTime.formatIso(now),
260 };
261​
262 expect(threadRuntimeHasInterruptibleRun(runtime)).toBe(false);
263 });
264​
265 it.each(["preparing", "starting"] as const)("keeps an active %s run interruptible", (status) => {
266 const runtime = {
267 status,
268 activeRunId: RunId.make(`run-${status}`),
269 providerInstanceId: v2Projection.thread.providerInstanceId,
270 providerName: null,
271 lastError: null,
272 updatedAt: DateTime.formatIso(now),
273 };
274​
275 expect(threadRuntimeHasInterruptibleRun(runtime)).toBe(true);
276 });
277});
278​
279describe("deriveRunlessWorkStartedAt", () => {
280 const later = DateTime.makeUnsafe("2026-07-28T10:05:00.000Z");
281 const rootTurn = (
282 status: OrchestrationV2ExecutionNode["status"],
283 startedAt = now,
284 ): OrchestrationV2ExecutionNode => ({
285 id: NodeId.make("child-root"),
286 threadId: v2Projection.thread.id,
287 runId: null,
288 parentNodeId: null,
289 rootNodeId: NodeId.make("child-root"),
290 kind: "root_turn",
291 status,
292 countsForRun: false,
293 providerThreadId: null,
294 providerTurnId: null,
295 nativeItemRef: null,
296 runtimeRequestId: null,
297 checkpointScopeId: null,
298 startedAt,
299 completedAt: null,
300 });
301​
302 const nativeChild = {
303 ...v2Projection,
304 thread: {
305 ...v2Projection.thread,
306 creationSource: "provider" as const,
307 lineage: {
308 parentThreadId: ThreadId.make("parent"),
309 relationshipToParent: "subagent" as const,
310 rootThreadId: ThreadId.make("parent"),
311 },
312 },
313 };
314​
315 it("times a provider-native subagent from its runless root turn while it works", () => {
316 const projection = { ...nativeChild, nodes: [rootTurn("running", later)] };
317 expect(deriveRunlessWorkStartedAt(projection)).toBe("2026-07-28T10:05:00.000Z");
318 expect(deriveThreadRuntime(projection)).toBeNull();
319 });
320​
321 it.each(["completed", "cancelled", "failed", "interrupted", "idle"] as const)(
322 "is idle once the subagent is %s",
323 (status) => {
324 expect(deriveRunlessWorkStartedAt({ ...nativeChild, nodes: [rootTurn(status)] })).toBe(null);
325 },
326 );
327​
328 it("ignores root turns that belong to a run, and threads the provider does not run", () => {
329 const owned = { ...rootTurn("running"), runId: RunId.make("run-1") };
330 expect(deriveRunlessWorkStartedAt({ ...nativeChild, nodes: [owned] })).toBeNull();
331 expect(
332 deriveRunlessWorkStartedAt({ ...v2Projection, nodes: [rootTurn("running")] }),
333 ).toBeNull();
334 });
335});
336​
337describe("deriveProviderSubagentStatus", () => {
338 const root = {
339 id: NodeId.make("child-root"),
340 threadId: v2Projection.thread.id,
341 runId: null,
342 parentNodeId: null,
343 rootNodeId: NodeId.make("child-root"),
344 kind: "root_turn" as const,
345 status: "completed" as const,
346 countsForRun: false,
347 providerThreadId: null,
348 providerTurnId: null,
349 nativeItemRef: null,
350 runtimeRequestId: null,
351 checkpointScopeId: null,
352 startedAt: now,
353 completedAt: now,
354 };
355 const child = (creationSource: "provider" | "mcp") => ({
356 ...v2Projection,
357 thread: {
358 ...v2Projection.thread,
359 creationSource,
360 lineage: {
361 parentThreadId: ThreadId.make("parent"),
362 relationshipToParent: "subagent" as const,
363 rootThreadId: ThreadId.make("parent"),
364 },
365 },
366 nodes: [root],
367 });
368​
369 it("reports the provider's own subagent from its runless root turn", () => {
370 expect(deriveProviderSubagentStatus(child("provider"))).toEqual({
371 status: "completed",
372 startedAt: "2026-07-28T10:00:00.000Z",
373 completedAt: "2026-07-28T10:00:00.000Z",
374 });
375 });
376​
377 it("says how long the subagent has worked, or took", () => {
378 const startedAt = "2026-07-28T10:00:00.000Z";
379 const at = (iso: string) => Date.parse(iso);
380 expect(
381 formatProviderSubagentStatus(
382 { status: "running", startedAt, completedAt: null },
383 at("2026-07-28T10:01:05.400Z"),
384 ),
385 ).toBe("Working 1m 5s");
386 expect(
387 formatProviderSubagentStatus(
388 { status: "completed", startedAt, completedAt: "2026-07-28T10:00:34.000Z" },
389 at("2026-07-28T11:00:00.000Z"),
390 ),
391 ).toBe("Completed in 34s");
392 expect(
393 formatProviderSubagentStatus(
394 { status: "cancelled", startedAt, completedAt: "2026-07-28T10:00:34.000Z" },
395 0,
396 ),
397 ).toBe("Cancelled");
398 expect(formatProviderSubagentStatus(null, 0)).toBe("Starting");
399 });
400​
401 it("leaves T3 delegated tasks and ordinary threads alone", () => {
402 expect(deriveProviderSubagentStatus(child("mcp"))).toBeNull();
403 expect(deriveProviderSubagentStatus({ ...v2Projection, nodes: [root] })).toBeNull();
404 });
405});
406​
407describe("formatModelSelectionEffort", () => {
408 const instanceId = ProviderInstanceId.make("claudeAgent");
409 const selection = (options?: ReadonlyArray<{ id: string; value: string }>) => ({
410 instanceId,
411 model: "claude-sonnet-5",
412 ...(options === undefined ? {} : { options }),
413 });
414 const catalog = (descriptor: { currentValue?: string }) => [
415 {
416 slug: "claude-sonnet-5",
417 name: "Claude Sonnet 5",
418 isCustom: false,
419 capabilities: {
420 optionDescriptors: [
421 {
422 id: "effort",
423 label: "Reasoning",
424 type: "select" as const,
425 options: [
426 { id: "medium", label: "Medium" },
427 { id: "high", label: "High", isDefault: true },
428 { id: "xhigh", label: "Extra High" },
429 ],
430 ...descriptor,
431 },
432 ],
433 },
434 },
435 ];
436​
437 it("shows the model's default effort when the user never picked one", () => {
438 expect(formatModelSelectionEffort(selection(), catalog({}))).toBe("High");
439 });
440​
441 it("names a stored effort the way the catalog does", () => {
442 expect(
443 formatModelSelectionEffort(selection([{ id: "effort", value: "xhigh" }]), catalog({})),
444 ).toBe("Extra High");
445 });
446​
447 it("uses the descriptor's current value over the default", () => {
448 expect(formatModelSelectionEffort(selection(), catalog({ currentValue: "medium" }))).toBe(
449 "Medium",
450 );
451 });
452​
453 it("shows nothing for a model the catalog does not describe", () => {
454 expect(formatModelSelectionEffort(selection([{ id: "effort", value: "high" }]))).toBeNull();
455 expect(
456 formatModelSelectionEffort(
457 { ...selection(), model: "claude-haiku-4-5" },
458 catalog({ currentValue: "medium" }),
459 ),
460 ).toBeNull();
461 });
462});
463​
464describe("threadRuntimeCanArchive", () => {
465 const runtime = (
466 status: ThreadRuntimeSummary["status"],
467 activeRunId: ThreadRuntimeSummary["activeRunId"],
468 ): ThreadRuntimeSummary => ({
469 status,
470 activeRunId,
471 providerInstanceId: v2Projection.thread.providerInstanceId,
472 providerName: null,
473 lastError: null,
474 updatedAt: DateTime.formatIso(now),
475 });
476​
477 it.each(["preparing", "starting", "running"] as const)(
478 "blocks archive while a provider is %s",
479 (status) => {
480 expect(threadRuntimeCanArchive(runtime(status, RunId.make(`run-${status}`)))).toBe(false);
481 },
482 );
483​
484 it("only blocks a queued runtime when a provider run remains attached", () => {
485 expect(threadRuntimeCanArchive(runtime("queued", RunId.make("run-queued")))).toBe(false);
486 expect(threadRuntimeCanArchive(runtime("queued", null))).toBe(true);
487 });
488​
489 it("allows waiting and idle threads", () => {
490 expect(threadRuntimeCanArchive(runtime("waiting", RunId.make("run-finished")))).toBe(true);
491 expect(threadRuntimeCanArchive(runtime("idle", null))).toBe(true);
492 });
493});
494​
495describe("presentPendingBackgroundWork", () => {
496 it.each(["Subagent:", "Subagent: "])(
497 "falls back to the subagent noun when %s has no display name",
498 (description) => {
499 const presentation = presentPendingBackgroundWork([
500 { taskId: "unnamed", kind: "subagent", description },
501 ]);
502​
503 expect(presentation?.title).toBe("Waiting on a subagent");
504 expect(presentation?.items[0]?.label).toBe("subagent");
505 },
506 );
507​
508 it.each([
509 "/root/luna_window_properties",
510 "Subagent: /root/luna_window_properties",
511 "/root/parent/luna_window_properties",
512 ])("uses the subagent display name for %s", (description) => {
513 const childThreadId = ThreadId.make("thread:luna");
514 const presentation = presentPendingBackgroundWork([
515 { taskId: "luna", kind: "subagent", description, childThreadId },
516 ]);
517​
518 expect(presentation).toEqual({
519 title: "Waiting on subagent Luna Window Properties",
520 items: [{ taskId: "luna", kind: "subagent", label: "Luna Window Properties", childThreadId }],
521 waiting: true,
522 });
523 });
524​
525 it("formats subagent names in a mixed roster and preserves command descriptions", () => {
526 const presentation = presentPendingBackgroundWork([
527 { taskId: "cmd", kind: "command", description: "/root/run_tests" },
528 { taskId: "luna", kind: "subagent", description: "/root/luna_window_properties" },
529 { taskId: "review", kind: "subagent", description: "Review src/math.ts" },
530 ]);
531​
532 expect(presentation?.title).toBe("Waiting on 2 subagents and 1 command");
533 expect(presentation?.items.map((item) => item.label)).toEqual([
534 "Luna Window Properties",
535 "Review src/math.ts",
536 "/root/run_tests",
537 ]);
538 });
539​
540 it("names a single piece of work by kind", () => {
541 expect(
542 presentPendingBackgroundWork([
543 { taskId: "a", kind: "subagent", description: "Review src/math.ts" },
544 ])?.title,
545 ).toBe("Waiting on subagent Review src/math.ts");
546 expect(presentPendingBackgroundWork([{ taskId: "a", kind: "monitor" }])?.title).toBe(
547 "Waiting on a monitor",
548 );
549 expect(presentPendingBackgroundWork([])).toBeNull();
550 });
551​
552 it("says only commands are running, not waited on", () => {
553 expect(
554 presentPendingBackgroundWork([
555 { taskId: "dev", kind: "command", description: "Start the shared dev server" },
556 ]),
557 ).toMatchObject({ title: "Running: Start the shared dev server", waiting: false });
558 expect(presentPendingBackgroundWork([{ taskId: "a", kind: "command" }])).toMatchObject({
559 title: "Running a command",
560 waiting: false,
561 });
562 expect(
563 presentPendingBackgroundWork([
564 { taskId: "a", kind: "command", description: "vp run dev" },
565 { taskId: "b", kind: "command", description: "tailscale serve" },
566 ]),
567 ).toMatchObject({ title: "Running 2 commands", waiting: false });
568 expect(
569 presentPendingBackgroundWork([
570 { taskId: "a", kind: "command", description: "vp run dev" },
571 { taskId: "b", kind: "monitor", description: "Watch PR checks" },
572 ]),
573 ).toMatchObject({ title: "Waiting on 1 command and 1 monitor", waiting: true });
574 });
575​
576 it("groups work by kind, subagents first, and keeps each name", () => {
577 const presentation = presentPendingBackgroundWork([
578 { taskId: "cmd", kind: "command", description: "npm test" },
579 {
580 taskId: "b",
581 kind: "subagent",
582 description: "Write tests",
583 childThreadId: ThreadId.make("thread:b"),
584 },
585 { taskId: "a", kind: "subagent", description: "Review src/math.ts" },
586 ]);
587 expect(presentation?.title).toBe("Waiting on 2 subagents and 1 command");
588 expect(presentation?.items.map((item) => [item.kind, item.label, item.childThreadId])).toEqual([
589 ["subagent", "Write tests", "thread:b"],
590 ["subagent", "Review src/math.ts", undefined],
591 ["command", "npm test", undefined],
592 ]);
593 });
594​
595 it("names generic work, including rosters from servers that predate kinds", () => {
596 expect(
597 presentPendingBackgroundWork([
598 { taskId: "bash", kind: "command", description: "Background sleep" },
599 { taskId: "watch", kind: "monitor" },
600 { taskId: "other", kind: "background_task" },
601 ])?.title,
602 ).toBe("Waiting on 1 command, 1 monitor and 1 background task");
603 expect(presentPendingBackgroundWork([{ taskId: "old", kind: "background_task" }])?.title).toBe(
604 "Waiting on a background task",
605 );
606 });
607});
608​
609describe("provider-reported model selection", () => {
610 const selected = v2Projection.thread.modelSelection;
611 const reported = { ...selected, options: [{ id: "reasoningEffort", value: "default" }] };
612 const providerThread = {
613 id: ProviderThreadId.make("active"),
614 driver: ProviderDriverKind.make("codex"),
615 providerInstanceId: selected.instanceId,
616 providerSessionId: ProviderSessionId.make("session"),
617 appThreadId: v2Projection.thread.id,
618 ownerNodeId: null,
619 nativeThreadRef: null,
620 nativeConversationHeadRef: null,
621 status: "idle" as const,
622 firstRunOrdinal: null,
623 lastRunOrdinal: null,
624 handoffIds: [],
625 forkedFrom: null,
626 createdAt: now,
627 updatedAt: now,
628 nativeMetadata: { modelSelection: reported },
629 };
630 const projection = {
631 ...v2Projection,
632 thread: { ...v2Projection.thread, activeProviderThreadId: providerThread.id },
633 providerThreads: [providerThread],
634 };
635​
636 it("reads only the active provider thread's reported selection", () => {
637 expect(deriveReportedModelSelection(projection)).toBe(reported);
638 expect(
639 deriveReportedModelSelection({
640 ...projection,
641 thread: { ...projection.thread, activeProviderThreadId: null },
642 }),
643 ).toBeNull();
644 expect(
645 deriveReportedModelSelection({
646 ...projection,
647 providerThreads: [
648 { ...providerThread, providerInstanceId: ProviderInstanceId.make("other") },
649 ],
650 }),
651 ).toBeNull();
652 });
653​
654 it("shows the reported default in a subagent's effort label", () => {
655 const models = [
656 {
657 slug: selected.model,
658 name: selected.model,
659 isCustom: false,
660 capabilities: {
661 optionDescriptors: [
662 {
663 id: "variant",
664 label: "Reasoning",
665 type: "select" as const,
666 options: [{ id: "high", label: "High" }],
667 },
668 ],
669 },
670 },
671 ];
672 const variantReport = { ...selected, options: [{ id: "variant", value: "default" }] };
673 expect(formatModelSelectionEffort(selected, models, variantReport)).toBe("Default");
674 expect(formatModelSelectionEffort(selected, models)).toBe("Unknown");
675 });
676});
677​
678describe("presentProviderGoal", () => {
679 it("summarizes Codex accounting and offers resume once the goal stops short", () => {
680 expect(
681 presentProviderGoal(
682 {
683 objective: "Ship the feature",
684 status: "paused",
685 tokensUsed: 12_400,
686 tokenBudget: 50_000,
687 timeUsedSeconds: 245,
688 },
689 false,
690 ),
691 ).toEqual({
692 title: "Goal paused",
693 objective: "Ship the feature",
694 usage: "12k / 50k tokens · 4m 5s",
695 canResume: true,
696 });
697 });
698​
699 it("counts Claude evaluator checks and never offers resume", () => {
700 expect(
701 presentProviderGoal({ objective: "All tests pass", status: "active", checks: 1 }, true),
702 ).toEqual({
703 title: "Pursuing goal",
704 objective: "All tests pass",
705 usage: "1 check",
706 canResume: false,
707 });
708 expect(
709 presentProviderGoal({ objective: "All tests pass", status: "complete", checks: 0 }, false)
710 .usage,
711 ).toBeNull();
712 expect(
713 presentProviderGoal({ objective: "All tests pass", status: "active" }, false).title,
714 ).toBe("Goal set");
715 });
716});