Open History to see the last commit
1import { EnvironmentId, ThreadId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3
4import {
5 matchComposerEnvironmentItems,
6 matchComposerThreadItems,
7 type ComposerThreadCandidate,
8} from "./composerThreadItems.ts";
9
10const environmentId = EnvironmentId.make("env-composer");
11
12function 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
32it("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 excludeThreadId: null,
50 query: "model",
51 now: Date.parse("2026-10-23T00:00:00.000Z"),
52 });
53 expect(items.map((item) => item.thread.threadId)).toEqual(["word", "newer-mid-word"]);
54});
55
56describe("matchComposerEnvironmentItems", () => {
57 const environments = [
58 { environmentId: EnvironmentId.make("env-here"), label: "Laptop", machine: "laptop" },
59 { environmentId: EnvironmentId.make("env-vps"), label: "Hetzner VPS", machine: "cloud" },
60 { environmentId: EnvironmentId.make("env-mini"), label: "Mac mini", machine: "mac-mini" },
61 ] as const;
62
63 it("offers the other machines matching the query, never the composer's own", () => {
64 expect(
65 matchComposerEnvironmentItems({
66 environments,
67 environmentId: EnvironmentId.make("env-here"),
68 query: " vps ",
69 }),
70 ).toEqual([
71 {
72 id: "environment:env-vps",
73 type: "environment",
74 environmentId: "env-vps",
75 machine: "cloud",
76 label: "Hetzner VPS",
77 description: "Machine",
78 },
79 ]);
80 expect(
81 matchComposerEnvironmentItems({
82 environments,
83 environmentId: EnvironmentId.make("env-here"),
84 query: "lap",
85 }),
86 ).toEqual([]);
87 expect(
88 matchComposerEnvironmentItems({
89 environments,
90 environmentId: EnvironmentId.make("env-here"),
91 query: "",
92 }),
93 ).toEqual([]);
94 });
95});