The best way to control Claude Code, Codex and more from any computer or phone

main
ts 71 lines 2.63 KB
Raw
1 import {
2 MessageId,
3 type OrchestrationV2Run,
4 ProviderInstanceId,
5 RunId,
6 ThreadId,
7 } from "@t3tools/contracts";
8 import * as DateTime from "effect/DateTime";
9 import { describe, expect, it } from "vite-plus/test";
10
11 import { offeredPromptSuggestion } from "./usePromptSuggestion";
12
13 const now = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z");
14 const run = (
15 id: RunId,
16 ordinal: number,
17 status: OrchestrationV2Run["status"],
18 started = true,
19 ): OrchestrationV2Run => ({
20 id,
21 threadId: ThreadId.make("thread-1"),
22 ordinal,
23 providerInstanceId: ProviderInstanceId.make("claudeAgent"),
24 modelSelection: { instanceId: ProviderInstanceId.make("claudeAgent"), model: "claude-haiku-4-5" },
25 providerThreadId: null,
26 userMessageId: MessageId.make(`message-${ordinal}`),
27 rootNodeId: null,
28 activeAttemptId: null,
29 status,
30 requestedAt: now,
31 startedAt: started ? now : null,
32 completedAt: now,
33 checkpointId: null,
34 contextHandoffId: null,
35 });
36 const summary = (value: OrchestrationV2Run) => ({
37 runId: value.id,
38 status: value.status,
39 requestedAt: null,
40 startedAt: value.startedAt === null ? null : "2026-06-20T00:00:00.000Z",
41 completedAt: "2026-06-20T00:00:00.000Z",
42 assistantMessageId: null,
43 });
44
45 describe("offeredPromptSuggestion", () => {
46 it("offers the finished turn's suggestion after a queued message was promoted to Steer", () => {
47 const turn = run(RunId.make("run-1"), 1, "completed");
48 const steered = run(RunId.make("run-2"), 2, "cancelled", false);
49 const suggestion = { runId: turn.id, text: "run the tests" };
50
51 expect(offeredPromptSuggestion(suggestion, summary(steered), [turn, steered])).toBe(suggestion);
52
53 // A later run that did start still replaces the earlier turn's suggestion.
54 const stopped = run(RunId.make("run-2"), 2, "cancelled");
55 expect(offeredPromptSuggestion(suggestion, summary(stopped), [turn, stopped])).toBeNull();
56
57 // Several never-started runs in a row still fall back to the turn that ran.
58 const removed = run(RunId.make("run-3"), 3, "cancelled", false);
59 expect(offeredPromptSuggestion(suggestion, summary(removed), [turn, steered, removed])).toBe(
60 suggestion,
61 );
62
63 // A newer turn that completed behind the cancelled run owns the suggestion slot.
64 const next = run(RunId.make("run-2"), 2, "completed");
65 expect(offeredPromptSuggestion(suggestion, summary(removed), [turn, next, removed])).toBeNull();
66
67 // Cached detail that predates the shell's cancelled run cannot vouch for what ran in between.
68 const unseen = run(RunId.make("run-3"), 3, "cancelled", false);
69 expect(offeredPromptSuggestion(suggestion, summary(unseen), [turn])).toBeNull();
70 });
71 });