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

threadExecution.test.ts

677 lines22.9 KB

1import {
2 TurnItemId,
3 NodeId,
4 MessageId,
5 ProviderInstanceId,
6 ProviderThreadId,
7 ProviderSessionId,
8 ProviderDriverKind,
9 ProviderTurnId,
10 RunAttemptId,
11 RunId,
12 ThreadId,
13 type OrchestrationV2ExecutionNode,
14 type OrchestrationV2RunStatus,
15} from "@t3tools/contracts";
16import * as DateTime from "effect/DateTime";
17import { createModelCapabilities, createModelSelection } from "@t3tools/shared/model";
18import { usageLimitBlockedRun } from "@t3tools/shared/orchestrationV2ThreadError";
19import { describe, expect, it } from "vite-plus/test";
20​
21import { v2Projection } from "./orchestrationV2TestFixtures.ts";
22import {
23 deriveReportedModelSelection,
24 deriveLatestThreadRun,
25 deriveProviderSubagentStatus,
26 deriveProviderExtensionStatuses,
27 deriveResumableRunId,
28 deriveRunlessWorkStartedAt,
29 deriveThreadActivityRun,
30 deriveThreadRuntime,
31 formatModelSelectionEffort,
32 isBackgroundWorkStopPending,
33 presentPendingBackgroundWork,
34 presentProviderGoal,
35 presentRunStop,
36 threadRuntimeHasInterruptibleRun,
37} from "./threadExecution.ts";
38​
39const now = DateTime.makeUnsafe("2026-07-28T10:00:00.000Z");
40​
41function run(id: string, ordinal: number, status: OrchestrationV2RunStatus) {
42 return {
43 id: RunId.make(id),
44 threadId: v2Projection.thread.id,
45 ordinal,
46 providerInstanceId: v2Projection.thread.providerInstanceId,
47 modelSelection: v2Projection.thread.modelSelection,
48 providerThreadId: null,
49 userMessageId: MessageId.make(`message-${id}`),
50 rootNodeId: null,
51 activeAttemptId: null,
52 status,
53 requestedAt: now,
54 startedAt: status === "queued" ? null : now,
55 completedAt: null,
56 checkpointId: null,
57 contextHandoffId: null,
58 };
60​
61describe("thread execution presentation", () => {
62 it("shows extension statuses only from the selected provider's current live session", () => {
63 const instanceId = v2Projection.thread.modelSelection.instanceId;
64 const providerThreadId = ProviderThreadId.make("native-status-thread");
65 const sessionId = ProviderSessionId.make("native-status-session");
66 const statuses = [{ key: "watch", text: "Watching" }];
67 const projection = {
68 thread: { ...v2Projection.thread, activeProviderThreadId: providerThreadId },
69 providerThreads: [
70 { id: providerThreadId, providerSessionId: sessionId, providerInstanceId: instanceId },
71 ],
72 providerSessions: [
73 {
74 id: sessionId,
75 providerInstanceId: instanceId,
76 status: "ready" as const,
77 extensionStatuses: statuses,
78 },
79 ],
80 };
81 expect(deriveProviderExtensionStatuses(projection)).toEqual(statuses);
82 expect(
83 deriveProviderExtensionStatuses({
84 ...projection,
85 providerSessions: [
86 ...projection.providerSessions,
87 {
88 ...projection.providerSessions[0]!,
89 id: ProviderSessionId.make("unrelated"),
90 extensionStatuses: [{ key: "wrong", text: "Wrong session" }],
91 },
92 ],
93 }),
94 ).toEqual(statuses);
95 expect(
96 deriveProviderExtensionStatuses({
97 ...projection,
98 providerSessions: [{ ...projection.providerSessions[0]!, status: "stopped" }],
99 }),
100 ).toEqual([]);
101 expect(
102 deriveProviderExtensionStatuses({
103 ...projection,
104 providerSessions: [{ ...projection.providerSessions[0]!, status: "error" }],
105 }),
106 ).toEqual(statuses);
107 expect(
108 deriveProviderExtensionStatuses({
109 ...projection,
110 providerSessions: [
111 { ...projection.providerSessions[0]!, status: "error", extensionStatuses: [] },
112 ],
113 }),
114 ).toEqual([]);
115 expect(
116 deriveProviderExtensionStatuses({
117 ...projection,
118 providerSessions: [{ ...projection.providerSessions[0]!, extensionStatuses: undefined }],
119 }),
120 ).toEqual([]);
121 expect(
122 deriveProviderExtensionStatuses({
123 ...projection,
124 thread: {
125 ...projection.thread,
126 modelSelection: { instanceId: ProviderInstanceId.make("other"), model: "default" },
127 },
128 }),
129 ).toEqual([]);
130 expect(deriveProviderExtensionStatuses(null)).toEqual([]);
131 });
132​
133 it("derives the current root failure without inheriting errors from children or previous runs", () => {
134 const failed = { ...run("limited", 1, "failed"), rootNodeId: NodeId.make("root") };
135 const item = {
136 id: TurnItemId.make("limit-error"),
137 threadId: v2Projection.thread.id,
138 runId: failed.id,
139 nodeId: failed.rootNodeId,
140 providerThreadId: null,
141 providerTurnId: null,
142 nativeItemRef: null,
143 parentItemId: null,
144 ordinal: 1,
145 type: "error" as const,
146 status: "failed" as const,
147 title: "Usage limit reached",
148 startedAt: now,
149 completedAt: now,
150 updatedAt: now,
151 failure: {
152 class: "usage_limit" as const,
153 message: "Plan limit reached",
154 code: "usageLimitExceeded",
155 retryable: null,
156 },
157 };
158 const projection = { ...v2Projection, runs: [failed], turnItems: [item] };
159 expect(deriveThreadRuntime(projection)).toMatchObject({
160 lastError: "Plan limit reached",
161 lastErrorClass: "usage_limit",
162 });
163 expect(deriveResumableRunId(projection, deriveThreadRuntime(projection))).toBe(failed.id);
164 expect(
165 deriveThreadRuntime({
166 ...projection,
167 turnItems: [{ ...item, nodeId: NodeId.make("child") }],
168 }),
169 ).toMatchObject({ lastError: null, lastErrorClass: null });
170 expect(
171 deriveThreadRuntime({
172 ...projection,
173 runs: [{ ...failed, rootNodeId: NodeId.make("new-root") }],
174 }),
175 ).toMatchObject({ lastError: null, lastErrorClass: null });
176 expect(
177 deriveThreadRuntime({ ...projection, runs: [failed, run("new", 2, "running")] }),
178 ).toMatchObject({ status: "running", lastError: null, lastErrorClass: null });
179 });
180​
181 // regression: #15029 working timers no longer reset on every background wake
182 it("counts a wake run's activity from the start of the work it continues", () => {
183 const workStartedAt = DateTime.makeUnsafe("2026-07-28T09:20:00.000Z");
184 const wake = { ...run("wake", 2, "running"), workStartedAt };
185 expect(
186 deriveThreadRuntime({ ...v2Projection, runs: [run("prompt", 1, "completed"), wake] })
187 ?.activityStartedAt,
188 ).toBe("2026-07-28T09:20:00.000Z");
189 expect(
190 deriveThreadRuntime({ ...v2Projection, runs: [run("prompt", 1, "running")] })
191 ?.activityStartedAt,
192 ).toBe("2026-07-28T10:00:00.000Z");
193 });
194​
195 it("keeps a subscription limit visible while later messages stay queued", () => {
196 const failed = {
197 ...run("limited", 1, "failed"),
198 rootNodeId: NodeId.make("root"),
199 completedAt: now,
200 };
201 const queued = run("queued", 2, "queued");
202 const item = {
203 id: TurnItemId.make("limit-error"),
204 threadId: v2Projection.thread.id,
205 runId: failed.id,
206 nodeId: failed.rootNodeId,
207 providerThreadId: null,
208 providerTurnId: null,
209 nativeItemRef: null,
210 parentItemId: null,
211 ordinal: 1,
212 type: "error" as const,
213 status: "failed" as const,
214 title: "Usage limit reached",
215 startedAt: now,
216 completedAt: now,
217 updatedAt: now,
218 failure: {
219 class: "usage_limit" as const,
220 message: "Plan limit reached",
221 code: "usageLimitExceeded",
222 retryable: null,
223 },
224 };
225 const projection = { ...v2Projection, runs: [failed, queued], turnItems: [item] };
226​
227 expect(deriveLatestThreadRun(projection)?.runId).toBe(failed.id);
228 expect(deriveThreadActivityRun(projection)?.runId).toBe(failed.id);
229 expect(deriveThreadRuntime(projection)).toMatchObject({
230 status: "failed",
231 lastError: "Plan limit reached",
232 lastErrorClass: "usage_limit",
233 });
234 expect(deriveResumableRunId(projection, deriveThreadRuntime(projection))).toBe(failed.id);
235 const cancelledQueued = {
236 ...run("cancelled-queued", 3, "cancelled"),
237 startedAt: null,
238 completedAt: now,
239 };
240 expect(
241 usageLimitBlockedRun([failed, queued, cancelledQueued], projection.turnItems, null)?.id,
242 ).toBe(failed.id);
243 expect(
244 deriveThreadRuntime({ ...projection, runs: [failed, queued, cancelledQueued] }),
245 ).toMatchObject({ status: "failed", lastErrorClass: "usage_limit" });
246 const providerError = {
247 ...projection,
248 turnItems: [{ ...item, failure: { ...item.failure, class: "provider_error" as const } }],
249 };
250 expect(deriveThreadRuntime(providerError)).toMatchObject({
251 status: "queued",
252 lastErrorClass: null,
253 });
254 expect(deriveResumableRunId(providerError, deriveThreadRuntime(providerError))).toBeNull();
255​
256 // A notification wake that completes before the reset did no work and keeps the limit
257 // in place. One that completes after the reset is a real run and clears it.
258 const resetAt = "2026-07-28T11:00:00.000Z";
259 const limited = { ...item, failure: { ...item.failure, resetAt } };
260 const wake = {
261 ...run("wake", 2, "completed"),
262 rootNodeId: NodeId.make("wake-root"),
263 completedAt: DateTime.makeUnsafe("2026-07-28T10:30:00.000Z"),
264 };
265 const notification = {
266 ...item,
267 id: TurnItemId.make("wake-notification"),
268 runId: wake.id,
269 nodeId: wake.rootNodeId,
270 type: "notification" as const,
271 status: "completed" as const,
272 source: { kind: "delegated_task" as const, taskIds: [] },
273 outcome: "failed" as const,
274 summary: "Subagent failed",
275 };
276 const hidden = { ...v2Projection, runs: [failed, wake], turnItems: [limited, notification] };
277 expect(deriveThreadRuntime(hidden)).toMatchObject({
278 status: "failed",
279 lastErrorClass: "usage_limit",
280 });
281 expect(deriveResumableRunId(hidden, deriveThreadRuntime(hidden))).toBe(failed.id);
282 const afterReset = { ...wake, completedAt: DateTime.makeUnsafe("2026-07-28T11:30:00.000Z") };
283 expect(usageLimitBlockedRun([failed, afterReset], hidden.turnItems, null)).toBeNull();
284 });
285​
286 it("keeps live activity attached to an executing run when a newer run is queued", () => {
287 const runningRun = run("run-running", 1, "running");
288 const queuedRun = run("run-queued", 2, "queued");
289 const projection = { ...v2Projection, runs: [queuedRun, runningRun], updatedAt: now };
290​
291 expect(deriveLatestThreadRun(projection)?.runId).toBe(queuedRun.id);
292 expect(deriveThreadActivityRun(projection)).toMatchObject({
293 runId: runningRun.id,
294 status: "running",
295 });
296​
297 const runtime = deriveThreadRuntime(projection);
298 expect(runtime).toMatchObject({
299 status: "running",
300 activeRunId: runningRun.id,
301 });
302 expect(threadRuntimeHasInterruptibleRun(runtime)).toBe(true);
303 });
304​
305 it("marks an open run whose provider turn already ended", () => {
306 const attemptId = RunAttemptId.make("attempt-open");
307 const openRun = { ...run("run-open", 1, "running"), activeAttemptId: attemptId };
308 const providerTurn = (status: "running" | "failed") => ({
309 id: ProviderTurnId.make("provider-turn-open"),
310 providerThreadId: ProviderThreadId.make("provider-thread-open"),
311 nodeId: NodeId.make("node-open"),
312 runAttemptId: attemptId,
313 nativeTurnRef: null,
314 ordinal: 1,
315 status,
316 startedAt: now,
317 completedAt: status === "running" ? null : now,
318 });
319 const projection = (status: "running" | "failed") => ({
320 ...v2Projection,
321 runs: [openRun],
322 providerTurns: [providerTurn(status)],
323 updatedAt: now,
324 });
325​
326 expect(deriveThreadActivityRun(projection("running"))?.turnEnded).toBeUndefined();
327 expect(deriveThreadActivityRun(projection("failed"))).toMatchObject({
328 status: "running",
329 turnEnded: true,
330 });
331 });
332​
333 it("presents a held queue as the stopped run instead of queued work", () => {
334 const interrupted = { ...run("run-interrupted", 1, "interrupted"), completedAt: now };
335 const held = { ...run("run-held", 2, "queued"), queueHeld: true };
336 const projection = { ...v2Projection, runs: [interrupted, held], updatedAt: now };
337​
338 expect(deriveLatestThreadRun(projection)?.runId).toBe(interrupted.id);
339 expect(deriveThreadActivityRun(projection)?.runId).toBe(interrupted.id);
340 expect(deriveThreadRuntime(projection)).toMatchObject({
341 status: "interrupted",
342 activeRunId: null,
343 });
344 expect(deriveResumableRunId(projection, deriveThreadRuntime(projection))).toBe(interrupted.id);
345​
346 const resumed = { ...projection, runs: [interrupted, { ...held, queueHeld: false }] };
347 expect(deriveThreadRuntime(resumed)).toMatchObject({ status: "queued" });
348​
349 const onlyHeld = {
350 ...projection,
351 runs: [held],
352 thread: { ...projection.thread, activeProviderThreadId: null },
353 };
354 expect(deriveLatestThreadRun(onlyHeld)).toBeNull();
355 expect(deriveThreadRuntime(onlyHeld)).toBeNull();
356 });
357​
358 it("does not expose a queued-only run as interruptible", () => {
359 const queuedRun = run("run-queued", 1, "queued");
360 const projection = { ...v2Projection, runs: [queuedRun], updatedAt: now };
361​
362 expect(deriveThreadActivityRun(projection)).toMatchObject({
363 runId: queuedRun.id,
364 status: "queued",
365 });
366​
367 const runtime = deriveThreadRuntime(projection);
368 expect(runtime).toMatchObject({
369 status: "queued",
370 activeRunId: null,
371 });
372 expect(threadRuntimeHasInterruptibleRun(runtime)).toBe(false);
373 });
374});
375​
376describe("presentRunStop", () => {
377 const signal = (type: "run_interrupt_request" | "run_interrupt_result", runId: RunId) => ({
378 id: TurnItemId.make(`${type}:${runId}`),
379 threadId: v2Projection.thread.id,
380 runId,
381 nodeId: null,
382 providerThreadId: null,
383 providerTurnId: null,
384 nativeItemRef: null,
385 parentItemId: null,
386 ordinal: 1,
387 status: type === "run_interrupt_result" ? ("interrupted" as const) : ("completed" as const),
388 title: "Interrupt",
389 startedAt: now,
390 completedAt: now,
391 updatedAt: now,
392 type,
393 message: "Stopped by user",
394 });
395 const running = run("run-stopping", 1, "running");
396 const request = signal("run_interrupt_request", running.id);
397​
398 it.each([
399 { name: "no Stop", runs: [running], turnItems: [], state: null },
400 {
401 name: "a Stop the agent is winding down",
402 runs: [running],
403 turnItems: [request],
404 state: "stopping",
405 },
406 {
407 name: "a Stop the provider never confirmed",
408 runs: [running],
409 turnItems: [{ ...request, unresponsiveAt: now }],
410 state: "unresponsive",
411 },
412 {
413 name: "a Stop that ended the run",
414 runs: [running],
415 turnItems: [request, signal("run_interrupt_result", running.id)],
416 state: null,
417 },
418 {
419 name: "a settled run's background work still stopping",
420 runs: [{ ...running, status: "completed" as const, completedAt: now }],
421 turnItems: [request],
422 state: null,
423 },
424 {
425 name: "a settled run whose background work ignored Stop",
426 runs: [{ ...running, status: "completed" as const, completedAt: now }],
427 turnItems: [{ ...request, unresponsiveAt: now }],
428 state: "unresponsive",
429 },
430 {
431 name: "a settled run whose background work ignored Stop, with a queued follow-up",
432 runs: [
433 { ...running, status: "completed" as const, completedAt: now },
434 run("run-queued", 2, "queued"),
435 ],
436 turnItems: [{ ...request, unresponsiveAt: now }],
437 state: "unresponsive",
438 },
439 ])("presents $name", ({ runs, turnItems, state }) => {
440 expect(presentRunStop({ runs, turnItems })?.state ?? null).toBe(state);
441 });
442});
443​
444describe("deriveRunlessWorkStartedAt", () => {
445 const later = DateTime.makeUnsafe("2026-07-28T10:05:00.000Z");
446 const rootTurn = (
447 status: OrchestrationV2ExecutionNode["status"],
448 startedAt = now,
449 ): OrchestrationV2ExecutionNode => ({
450 id: NodeId.make("child-root"),
451 threadId: v2Projection.thread.id,
452 runId: null,
453 parentNodeId: null,
454 rootNodeId: NodeId.make("child-root"),
455 kind: "root_turn",
456 status,
457 countsForRun: false,
458 providerThreadId: null,
459 providerTurnId: null,
460 nativeItemRef: null,
461 runtimeRequestId: null,
462 checkpointScopeId: null,
463 startedAt,
464 completedAt: null,
465 });
466​
467 const nativeChild = {
468 ...v2Projection,
469 thread: {
470 ...v2Projection.thread,
471 creationSource: "provider" as const,
472 lineage: {
473 parentThreadId: ThreadId.make("parent"),
474 relationshipToParent: "subagent" as const,
475 rootThreadId: ThreadId.make("parent"),
476 },
477 },
478 };
479​
480 it("times a provider-native subagent from its runless root turn while it works", () => {
481 const projection = { ...nativeChild, nodes: [rootTurn("running", later)] };
482 expect(deriveRunlessWorkStartedAt(projection)).toBe("2026-07-28T10:05:00.000Z");
483 expect(deriveThreadRuntime(projection)).toBeNull();
484 });
485​
486 it("ignores root turns that belong to a run, and threads the provider does not run", () => {
487 const owned = { ...rootTurn("running"), runId: RunId.make("run-1") };
488 expect(deriveRunlessWorkStartedAt({ ...nativeChild, nodes: [owned] })).toBeNull();
489 expect(
490 deriveRunlessWorkStartedAt({ ...v2Projection, nodes: [rootTurn("running")] }),
491 ).toBeNull();
492 });
493});
494​
495describe("deriveProviderSubagentStatus", () => {
496 const root = {
497 id: NodeId.make("child-root"),
498 threadId: v2Projection.thread.id,
499 runId: null,
500 parentNodeId: null,
501 rootNodeId: NodeId.make("child-root"),
502 kind: "root_turn" as const,
503 status: "completed" as const,
504 countsForRun: false,
505 providerThreadId: null,
506 providerTurnId: null,
507 nativeItemRef: null,
508 runtimeRequestId: null,
509 checkpointScopeId: null,
510 startedAt: now,
511 completedAt: now,
512 };
513 const child = (creationSource: "provider" | "mcp") => ({
514 ...v2Projection,
515 thread: {
516 ...v2Projection.thread,
517 creationSource,
518 lineage: {
519 parentThreadId: ThreadId.make("parent"),
520 relationshipToParent: "subagent" as const,
521 rootThreadId: ThreadId.make("parent"),
522 },
523 },
524 nodes: [root],
525 });
526​
527 it("leaves T3 delegated tasks and ordinary threads alone", () => {
528 expect(deriveProviderSubagentStatus(child("mcp"))).toBeNull();
529 expect(deriveProviderSubagentStatus({ ...v2Projection, nodes: [root] })).toBeNull();
530 });
531});
532​
533describe("provider-reported model selection", () => {
534 const selected = v2Projection.thread.modelSelection;
535 const reported = { ...selected, options: [{ id: "reasoningEffort", value: "default" }] };
536 const providerThread = {
537 id: ProviderThreadId.make("active"),
538 driver: ProviderDriverKind.make("codex"),
539 providerInstanceId: selected.instanceId,
540 providerSessionId: ProviderSessionId.make("session"),
541 appThreadId: v2Projection.thread.id,
542 ownerNodeId: null,
543 nativeThreadRef: null,
544 nativeConversationHeadRef: null,
545 status: "idle" as const,
546 firstRunOrdinal: null,
547 lastRunOrdinal: null,
548 handoffIds: [],
549 forkedFrom: null,
550 createdAt: now,
551 updatedAt: now,
552 nativeMetadata: { modelSelection: reported },
553 };
554 const projection = {
555 ...v2Projection,
556 thread: { ...v2Projection.thread, activeProviderThreadId: providerThread.id },
557 providerThreads: [providerThread],
558 };
559​
560 it("reads only the active provider thread's reported selection", () => {
561 expect(deriveReportedModelSelection(projection)).toBe(reported);
562 expect(
563 deriveReportedModelSelection({
564 ...projection,
565 thread: { ...projection.thread, activeProviderThreadId: null },
566 }),
567 ).toBeNull();
568 expect(
569 deriveReportedModelSelection({
570 ...projection,
571 providerThreads: [
572 { ...providerThread, providerInstanceId: ProviderInstanceId.make("other") },
573 ],
574 }),
575 ).toBeNull();
576 });
577});
578​
579describe("formatModelSelectionEffort", () => {
580 it("labels an old Ultracode effort by the effort it runs at", () => {
581 const models = [
582 {
583 slug: "claude-opus-5-5",
584 name: "Claude Opus 5.5",
585 isCustom: false,
586 capabilities: createModelCapabilities({
587 optionDescriptors: [
588 {
589 id: "effort",
590 label: "Reasoning",
591 type: "select",
592 options: [
593 { id: "high", label: "High", isDefault: true },
594 { id: "xhigh", label: "Extra High" },
595 ],
596 },
597 { id: "ultracode", label: "Ultracode", type: "boolean" },
598 ],
599 }),
600 },
601 ];
602 const selection = createModelSelection(
603 ProviderInstanceId.make("claudeAgent"),
604 "claude-opus-5-5",
605 [{ id: "effort", value: "ultracode" }],
606 );
607​
608 expect(formatModelSelectionEffort(selection, models)).toBe("Extra High");
609 });
610});
611​
612describe("isBackgroundWorkStopPending", () => {
613 const tasks = [{ taskId: "dev-server" }];
614 const sent = { threadKey: "env:thread", taskIds: ["dev-server"], retryAt: null };
615 const accepted = { ...sent, retryAt: 10_000 };
616​
617 it("stays pending after acceptance while a stopped task is still listed", () => {
618 expect(isBackgroundWorkStopPending(sent, "env:thread", tasks, false)).toBe(true);
619 expect(isBackgroundWorkStopPending(accepted, "env:thread", tasks, false)).toBe(true);
620 });
621​
622 it("ends once the stopped tasks leave, even if new work starts", () => {
623 expect(isBackgroundWorkStopPending(accepted, "env:thread", [], false)).toBe(false);
624 expect(isBackgroundWorkStopPending(accepted, "env:thread", [{ taskId: "next" }], false)).toBe(
625 false,
626 );
627 });
628​
629 it("allows retry at the deadline even if a stopped task remains", () => {
630 const request = { ...accepted, retryAt: 10_000 };
631 expect(isBackgroundWorkStopPending(request, "env:thread", tasks, false)).toBe(true);
632 expect(isBackgroundWorkStopPending(request, "env:thread", tasks, true)).toBe(false);
633 });
634​
635 it("only applies to the thread that sent the Stop", () => {
636 expect(isBackgroundWorkStopPending(null, "env:thread", tasks, false)).toBe(false);
637 expect(isBackgroundWorkStopPending(sent, "env:other", tasks, false)).toBe(false);
638 });
639});
640​
641describe("presentProviderGoal", () => {
642 it("rolls token counts that round to 1000k over to 1m", () => {
643 const usage = (tokensUsed: number) =>
644 presentProviderGoal(
645 { objective: "Ship the feature", status: "active", tokensUsed, tokenBudget: 2_000_000 },
646 true,
647 ).usage;
648 expect(usage(999_499)).toBe("999k / 2m tokens");
649 expect(usage(999_500)).toBe("1m / 2m tokens");
650 expect(usage(999_999)).toBe("1m / 2m tokens");
651 expect(usage(1_000_000)).toBe("1m / 2m tokens");
652 expect(
653 presentProviderGoal(
654 {
655 objective: "Ship the feature",
656 status: "paused",
657 tokensUsed: 999_500,
658 tokenBudget: 999_500,
659 },
660 false,
661 ).usage,
662 ).toBe("1m / 1m tokens");
663 });
664});
665​
666describe("presentPendingBackgroundWork", () => {
667 it("names a command by its script, not the shell that wraps it", () => {
668 const presentation = presentPendingBackgroundWork([
669 {
670 taskId: "call_1",
671 kind: "command",
672 description: `/bin/zsh -lc "mv a.ts b.ts\ncat > b.ts <<'EOF'\nexport {};\nEOF"`,
673 },
674 ]);
675 expect(presentation?.items[0]?.label).toBe("mv a.ts b.ts\ncat > b.ts <<'EOF'\nexport {};\nEOF");
676 });
677});