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

threadExecution.test.ts

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