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