1// @effect-diagnostics nodeBuiltinImport:off
2import * as NodeFS from "node:fs";
3import * as NodePath from "node:path";
4
5import { assert, it } from "@effect/vitest";
6
7import {
8 buildTriageContext,
9 buildTriageLaunchPrompt,
10 buildTriageSeedPrompt,
11 TRIAGE_PLAYBOOK,
12} from "./triagePrompt.ts";
13
14it("stays byte-identical to .github/triage/PLAYBOOK.md", () => {
15 // Old releases fetch the repo copy from `main` and follow it when it differs
16 // from their bundled playbook. The two must say the same thing at HEAD, or a
17 // playbook edit silently changes behavior only for old (or only for new)
18 // installs. Edit both files together.
19 const canonicalPath = NodePath.join(
20 import.meta.dirname,
21 "../../../../.github/triage/PLAYBOOK.md",
22 );
23 assert.equal(TRIAGE_PLAYBOOK, NodeFS.readFileSync(canonicalPath, "utf8"));
24});
25
26it("seed prompt names the context file and embeds the playbook", () => {
27 const prompt = buildTriageSeedPrompt("/tmp/triage-run/context.md");
28 assert.include(prompt, "/tmp/triage-run/context.md");
29 assert.include(prompt, TRIAGE_PLAYBOOK);
30});
31
32it("launch prompt stays a single argv-safe line naming the prompt file", () => {
33 // The launch argument goes through cmd.exe on Windows (.cmd shims), which
34 // cannot carry newlines; the playbook itself must stay on disk.
35 const launch = buildTriageLaunchPrompt(String.raw`C:\Users\a b\.t3\userdata\triage\x\prompt.md`);
36 assert.notInclude(launch, "\n");
37 assert.include(launch, String.raw`C:\Users\a b\.t3\userdata\triage\x\prompt.md`);
38 assert.isBelow(launch.length, 1_000);
39});
40
41it("context file carries every path the playbook depends on", () => {
42 const context = buildTriageContext({
43 generatedAt: "2026-08-13T00:00:00.000Z",
44 cliVersion: "0.0.33",
45 os: "linux x64 (7.0.0)",
46 nodeVersion: "v24.0.0",
47 launchedAs: "npx t3 triage",
48 server: "running (pid 42, http://127.0.0.1:4501)",
49 paths: {
50 stateDir: "/home/u/.t3/userdata",
51 dbPath: "/home/u/.t3/userdata/state.sqlite",
52 settingsPath: "/home/u/.t3/userdata/settings.json",
53 logsDir: "/home/u/.t3/userdata/logs",
54 serviceLogPath: "/home/u/.t3/userdata/logs/boot-service.log",
55 desktopBackendLogGlob: "/home/u/.t3/userdata/logs/server-child*.log*",
56 serverTracePath: "/home/u/.t3/userdata/logs/server.trace.ndjson",
57 providerEventLogPath: "/home/u/.t3/userdata/logs/provider/events.log",
58 terminalLogsDir: "/home/u/.t3/userdata/logs/terminals",
59 providerStatusCacheDir: "/home/u/.t3/caches",
60 secretsDir: "/home/u/.t3/userdata/secrets",
61 sourceCacheDir: "/home/u/.t3/source",
62 },
63 });
64 assert.include(context, "/home/u/.t3/userdata/state.sqlite");
65 assert.include(context, "/home/u/.t3/userdata/logs/server.trace.ndjson");
66 assert.include(context, "/home/u/.t3/userdata/logs/boot-service.log");
67 assert.include(context, "/home/u/.t3/userdata/logs/server-child*.log*");
68 assert.include(context, "/home/u/.t3/userdata/logs/provider/events.log");
69 assert.include(context, "/home/u/.t3/userdata/secrets");
70 assert.include(context, "/home/u/.t3/source");
71 assert.include(context, "npx t3 triage");
72});
73
74it("context file labels the CLI version as the CLI's, not the user's build", () => {
75 // `npx t3 triage` can resolve a different `t3` than the app the bug
76 // happened on (#13337), so the agent must not read it as the user's version.
77 const context = buildTriageContext({
78 generatedAt: "2026-09-24T00:00:00.000Z",
79 cliVersion: "0.0.42",
80 os: "linux x64 (7.2.0)",
81 nodeVersion: "v26.8.2",
82 launchedAs: "npx t3 triage",
83 server: "running (pid 42, http://127.0.0.1:3773, version 0.0.43-nightly.20260923.2173)",
84 paths: {
85 stateDir: "/home/u/.t3/userdata",
86 dbPath: "/home/u/.t3/userdata/state.sqlite",
87 settingsPath: "/home/u/.t3/userdata/settings.json",
88 logsDir: "/home/u/.t3/userdata/logs",
89 serviceLogPath: "/home/u/.t3/userdata/logs/boot-service.log",
90 desktopBackendLogGlob: "/home/u/.t3/userdata/logs/server-child*.log*",
91 serverTracePath: "/home/u/.t3/userdata/logs/server.trace.ndjson",
92 providerEventLogPath: "/home/u/.t3/userdata/logs/provider/events.log",
93 terminalLogsDir: "/home/u/.t3/userdata/logs/terminals",
94 providerStatusCacheDir: "/home/u/.t3/caches",
95 secretsDir: "/home/u/.t3/userdata/secrets",
96 sourceCacheDir: "/home/u/.t3/source",
97 },
98 });
99 assert.notInclude(context, "Installed version");
100 assert.notInclude(context, "Release tag");
101 assert.include(context, "- Triage CLI version: 0.0.42 (");
102 assert.include(context, "version 0.0.43-nightly.20260923.2173");
103});