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

main
ts 148 lines 4.77 KB
Raw
1 import { EnvironmentId, ThreadId } from "@t3tools/contracts";
2 import { describe, expect, it } from "vite-plus/test";
3
4 import {
5 matchComposerEnvironmentItems,
6 matchComposerThreadItems,
7 type ComposerThreadCandidate,
8 } from "./composerThreadItems.ts";
9
10 const environmentId = EnvironmentId.make("env-composer");
11
12 function shell(
13 id: string,
14 title: string,
15 overrides: Partial<ComposerThreadCandidate> = {},
16 ): ComposerThreadCandidate {
17 return {
18 environmentId,
19 id: ThreadId.make(id),
20 title,
21 branch: null,
22 createdAt: "2026-10-01T00:00:00.000Z",
23 updatedAt: "2026-10-01T00:00:00.000Z",
24 latestUserMessageAt: null,
25 opens: null,
26 archivedAt: null,
27 lineage: { rootThreadId: ThreadId.make(id), parentThreadId: null, relationshipToParent: null },
28 ...overrides,
29 };
30 }
31
32 it("ranks thread mentions like the palette and leaves out subagent threads", () => {
33 const items = matchComposerThreadItems({
34 shells: [
35 shell("newer-mid-word", "Remodel the settings page", {
36 updatedAt: "2026-10-20T00:00:00.000Z",
37 }),
38 shell("word", "Fix model picker"),
39 shell("subagent", "Model review", {
40 lineage: {
41 rootThreadId: ThreadId.make("word"),
42 parentThreadId: ThreadId.make("word"),
43 relationshipToParent: "subagent",
44 },
45 }),
46 shell("other-environment", "Model docs", { environmentId: EnvironmentId.make("env-other") }),
47 ],
48 environmentId,
49 linkedEnvironments: new Map(),
50 excludeThreadId: null,
51 query: "model",
52 now: Date.parse("2026-10-23T00:00:00.000Z"),
53 });
54 expect(items.map((item) => item.thread.threadId)).toEqual(["word", "newer-mid-word"]);
55 });
56
57 it("offers the composer thread's own used side chats, but not other threads' side chats", () => {
58 const sideChatOf = (parent: string) => ({
59 rootThreadId: ThreadId.make(parent),
60 parentThreadId: ThreadId.make(parent),
61 relationshipToParent: "fork" as const,
62 sideChat: true,
63 });
64 const latestUserMessageAt = "2026-10-22T00:00:00.000Z";
65 const items = matchComposerThreadItems({
66 shells: [
67 shell("mine", "Why is the build slow?", { lineage: sideChatOf("main"), latestUserMessageAt }),
68 shell("unused", "Slow side chat", { lineage: sideChatOf("main") }),
69 shell("theirs", "Why is the test slow?", {
70 lineage: sideChatOf("other"),
71 latestUserMessageAt,
72 }),
73 ],
74 environmentId,
75 linkedEnvironments: new Map(),
76 excludeThreadId: ThreadId.make("main"),
77 query: "slow",
78 now: Date.parse("2026-10-23T00:00:00.000Z"),
79 });
80 expect(items.map(({ thread, description }) => ({ id: thread.threadId, description }))).toEqual([
81 { id: "mine", description: "Side chat" },
82 ]);
83 });
84
85 it("also offers threads on linked machines, naming the machine, but no other machine's", () => {
86 const vps = EnvironmentId.make("env-vps");
87 const items = matchComposerThreadItems({
88 shells: [
89 shell("here", "Deploy script"),
90 shell("there", "Deploy script", { environmentId: vps }),
91 shell("unlinked", "Deploy notes", { environmentId: EnvironmentId.make("env-unlinked") }),
92 ],
93 environmentId,
94 linkedEnvironments: new Map([[vps, "Hetzner VPS"]]),
95 excludeThreadId: null,
96 query: "deploy",
97 now: Date.parse("2026-10-23T00:00:00.000Z"),
98 });
99 expect(items.map(({ thread, label, description }) => ({ thread, label, description }))).toEqual([
100 { thread: { environmentId, threadId: "here" }, label: "Deploy script", description: "Thread" },
101 {
102 thread: { environmentId: vps, threadId: "there" },
103 label: "Deploy script",
104 description: "Thread on Hetzner VPS",
105 },
106 ]);
107 });
108
109 describe("matchComposerEnvironmentItems", () => {
110 const environments = [
111 { environmentId: EnvironmentId.make("env-here"), label: "Laptop", machine: "laptop" },
112 { environmentId: EnvironmentId.make("env-vps"), label: "Hetzner VPS", machine: "cloud" },
113 { environmentId: EnvironmentId.make("env-mini"), label: "Mac mini", machine: "mac-mini" },
114 ] as const;
115
116 it("offers the other machines matching the query, never the composer's own", () => {
117 expect(
118 matchComposerEnvironmentItems({
119 environments,
120 environmentId: EnvironmentId.make("env-here"),
121 query: " vps ",
122 }),
123 ).toEqual([
124 {
125 id: "environment:env-vps",
126 type: "environment",
127 environmentId: "env-vps",
128 machine: "cloud",
129 label: "Hetzner VPS",
130 description: "Machine",
131 },
132 ]);
133 expect(
134 matchComposerEnvironmentItems({
135 environments,
136 environmentId: EnvironmentId.make("env-here"),
137 query: "lap",
138 }),
139 ).toEqual([]);
140 expect(
141 matchComposerEnvironmentItems({
142 environments,
143 environmentId: EnvironmentId.make("env-here"),
144 query: "",
145 }),
146 ).toEqual([]);
147 });
148 });