xonecas.io
64875
Mc

mini-coder / commit ce6cb0f

test: prune brittle low-value coverage

xonecas2026-04-16 ce6cb0fd4cb409a04b84e1a85f91aca447602a93 parent bb02d6a

18 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

AGENTS.md+2−2
@@ -2,7 +2,6 @@
22
33 - This repo expects agents to use the `programming-practices` skill at all times.
44 - **Spec-driven development**: `spec.md` is the source of truth for behavior and design. Read it before changing code. Do not deviate without discussion.
5-- **TDD**: write tests first, then implement.
65 - Use Conventional Commits formatting for commit messages.
76 - Before committing code changes, review the diff with the user and get approval for the commit.
87
@@ -95,7 +94,8 @@
9594 - Before 1.0, prefer correct/simple semantics over speculative compatibility shims, but call out intentional breaking changes.
9695 - TUI changes need real terminal validation in `tmux`; passing tests is not enough.
9796 - Stay within the agreed TODO scope. Do not pull in adjacent items without discussion.
98-- Don't write tests that call real git commands
97+- Don't write tests that call real git commands.
98+- Don't add brittle tests that pin incidental wording, formatting, colors, layout, or other implementation-shaped output unless that exact output is the actual contract.
9999
100100 ## Testing strategy
101101
src/errors.test.ts+0−10
@@ -1,10 +0,0 @@
1-import { describe, expect, test } from "bun:test";
2-import { getErrorMessage } from "./errors.ts";
3-
4-describe("errors", () => {
5- test("getErrorMessage returns an Error message and stringifies non-Errors", () => {
6- expect(getErrorMessage(new Error("boom"))).toBe("boom");
7- expect(getErrorMessage("plain failure")).toBe("plain failure");
8- expect(getErrorMessage(42)).toBe("42");
9- });
10-});
src/input.test.ts+0−119
@@ -29,27 +29,6 @@ describe("parseInput — commands", () => {
2929 expect(result).toEqual({ type: "command", command: cmd, args: "" });
3030 }
3131 });
32-
33- test("unknown /foo is plain text", () => {
34- expect(parseInput("/foo")).toEqual({ type: "text", text: "/foo" });
35- });
36-
37- test("/ alone is plain text", () => {
38- expect(parseInput("/")).toEqual({ type: "text", text: "/" });
39- });
40-
41- test("space after slash is plain text", () => {
42- expect(parseInput("/ model")).toEqual({ type: "text", text: "/ model" });
43- });
44-
45- test("command with trailing whitespace still matches", () => {
46- const result = parseInput("/model ");
47- expect(result).toEqual({ type: "command", command: "model", args: "" });
48- });
49-
50- test("command is case-sensitive (uppercase is text)", () => {
51- expect(parseInput("/Model")).toEqual({ type: "text", text: "/Model" });
52- });
5332 });
5433
5534 // ---------------------------------------------------------------------------
@@ -57,14 +36,6 @@ describe("parseInput — commands", () => {
5736 // ---------------------------------------------------------------------------
5837
5938 describe("parseInput — skills", () => {
60- test("/skill:name extracts skill with no user text", () => {
61- expect(parseInput("/skill:review")).toEqual({
62- type: "skill",
63- skillName: "review",
64- userText: "",
65- });
66- });
67-
6839 test("/skill:name rest extracts skill and user text", () => {
6940 expect(parseInput("/skill:code-review check the auth module")).toEqual({
7041 type: "skill",
@@ -72,30 +43,6 @@ describe("parseInput — skills", () => {
7243 userText: "check the auth module",
7344 });
7445 });
75-
76- test("/skill:name with trailing space has empty user text", () => {
77- expect(parseInput("/skill:review ")).toEqual({
78- type: "skill",
79- skillName: "review",
80- userText: "",
81- });
82- });
83-
84- test("/skill: with no name is plain text", () => {
85- expect(parseInput("/skill:")).toEqual({ type: "text", text: "/skill:" });
86- });
87-
88- test("/skill without colon is plain text (not a known command)", () => {
89- expect(parseInput("/skill")).toEqual({ type: "text", text: "/skill" });
90- });
91-
92- test("skill name can contain hyphens and underscores", () => {
93- expect(parseInput("/skill:my_cool-skill do stuff")).toEqual({
94- type: "skill",
95- skillName: "my_cool-skill",
96- userText: "do stuff",
97- });
98- });
9946 });
10047
10148 // ---------------------------------------------------------------------------
@@ -110,21 +57,6 @@ describe("parseInput — images", () => {
11057 expect(result).toEqual({ type: "image", path: img });
11158 });
11259
113- test("supports all image extensions", () => {
114- for (const ext of [".png", ".jpg", ".jpeg", ".gif", ".webp"]) {
115- const img = join(tmp, `test${ext}`);
116- writeFileSync(img, "fake");
117- const result = parseInput(img, { supportsImages: true });
118- expect(result.type).toBe("image");
119- }
120- });
121-
122- test("non-existent image path is plain text", () => {
123- const img = join(tmp, "missing.png");
124- const result = parseInput(img, { supportsImages: true });
125- expect(result.type).toBe("text");
126- });
127-
12860 test("image path when model does not support images is plain text", () => {
12961 const img = join(tmp, "screenshot.png");
13062 writeFileSync(img, "fake png");
@@ -132,20 +64,6 @@ describe("parseInput — images", () => {
13264 expect(result.type).toBe("text");
13365 });
13466
135- test("image path with supportsImages undefined is plain text", () => {
136- const img = join(tmp, "screenshot.png");
137- writeFileSync(img, "fake png");
138- const result = parseInput(img);
139- expect(result.type).toBe("text");
140- });
141-
142- test("non-image extension is plain text even if file exists", () => {
143- const file = join(tmp, "readme.txt");
144- writeFileSync(file, "hello");
145- const result = parseInput(file, { supportsImages: true });
146- expect(result.type).toBe("text");
147- });
148-
14967 test("input with extra text is not an image", () => {
15068 const img = join(tmp, "screenshot.png");
15169 writeFileSync(img, "fake png");
@@ -153,13 +71,6 @@ describe("parseInput — images", () => {
15371 expect(result.type).toBe("text");
15472 });
15573
156- test("trimmed whitespace still detects image", () => {
157- const img = join(tmp, "photo.jpg");
158- writeFileSync(img, "fake jpg");
159- const result = parseInput(` ${img} `, { supportsImages: true });
160- expect(result).toEqual({ type: "image", path: img });
161- });
162-
16374 test("relative image path resolved against cwd", () => {
16475 const img = join(tmp, "img.png");
16576 writeFileSync(img, "fake png");
@@ -167,14 +78,6 @@ describe("parseInput — images", () => {
16778 expect(result).toEqual({ type: "image", path: img });
16879 });
16980
170- test("relative image path without cwd checks as-is", () => {
171- // Relative path that doesn't exist from process.cwd
172- const result = parseInput("nonexistent-dir/img.png", {
173- supportsImages: true,
174- });
175- expect(result.type).toBe("text");
176- });
177-
17881 test("image in subdirectory with cwd", () => {
17982 const sub = join(tmp, "assets");
18083 mkdirSync(sub);
@@ -188,13 +91,6 @@ describe("parseInput — images", () => {
18891 path: join(sub, "logo.webp"),
18992 });
19093 });
191-
192- test("uppercase extension is detected", () => {
193- const img = join(tmp, "PHOTO.PNG");
194- writeFileSync(img, "fake png");
195- const result = parseInput(img, { supportsImages: true });
196- expect(result).toEqual({ type: "image", path: img });
197- });
19894 });
19995
20096 // ---------------------------------------------------------------------------
@@ -208,21 +104,6 @@ describe("parseInput — text", () => {
208104 text: "fix the tests",
209105 });
210106 });
211-
212- test("empty string is text", () => {
213- expect(parseInput("")).toEqual({ type: "text", text: "" });
214- });
215-
216- test("whitespace-only is text", () => {
217- expect(parseInput(" ")).toEqual({ type: "text", text: "" });
218- });
219-
220- test("message starting with slash-like but not command", () => {
221- expect(parseInput("/usr/bin/node")).toEqual({
222- type: "text",
223- text: "/usr/bin/node",
224- });
225- });
226107 });
227108
228109 // ---------------------------------------------------------------------------
src/package.test.ts+0−65
@@ -1,65 +0,0 @@
1-import { expect, test } from "bun:test";
2-import { join } from "node:path";
3-
4-const REPO_ROOT = join(import.meta.dir, "..");
5-
6-async function packDryRun(): Promise<{
7- exitCode: number;
8- stdout: string;
9- stderr: string;
10-}> {
11- const proc = Bun.spawn(
12- [process.execPath, "pm", "pack", "--dry-run", "--ignore-scripts"],
13- {
14- cwd: REPO_ROOT,
15- stdin: "ignore",
16- stdout: "pipe",
17- stderr: "pipe",
18- env: process.env,
19- },
20- );
21-
22- const exitCode = await proc.exited;
23- const stdout = await new Response(proc.stdout).text();
24- const stderr = await new Response(proc.stderr).text();
25-
26- return { exitCode, stdout, stderr };
27-}
28-
29-test("package.json bin points to a checked-in mc launcher", async () => {
30- const pkg = (await Bun.file(join(REPO_ROOT, "package.json")).json()) as {
31- bin?: Record<string, string>;
32- };
33-
34- expect(pkg.bin).toEqual({ mc: "bin/mc.ts" });
35-
36- const launcher = pkg.bin?.mc;
37- expect(launcher).toBe("bin/mc.ts");
38- if (!launcher) {
39- throw new Error("package.json bin.mc is missing");
40- }
41- expect(Bun.file(join(REPO_ROOT, launcher)).size).toBeGreaterThan(0);
42-});
43-
44-test("package.json declares direct UI types and omits redundant diff typings", async () => {
45- const pkg = (await Bun.file(join(REPO_ROOT, "package.json")).json()) as {
46- dependencies?: Record<string, string>;
47- devDependencies?: Record<string, string>;
48- };
49-
50- expect(pkg.dependencies).toHaveProperty("@cel-tui/types");
51- expect(pkg.devDependencies).not.toHaveProperty("@types/diff");
52-});
53-
54-test("pack dry-run includes the README, mc launcher, and runtime entrypoint", async () => {
55- const result = await packDryRun();
56-
57- expect(result.exitCode).toBe(0);
58- expect(result.stderr).toBe("");
59- expect(result.stdout).toContain("packed ");
60- expect(result.stdout).toContain("README.md");
61- expect(result.stdout).toContain("bin/mc.ts");
62- expect(result.stdout).toContain("src/index.ts");
63- expect(result.stdout).not.toContain("src/package.test.ts");
64- expect(result.stdout).not.toContain("terminal-bench/");
65-});
src/paths.test.ts+0−37
@@ -1,37 +0,0 @@
1-import { describe, expect, test } from "bun:test";
2-import { mkdirSync, mkdtempSync, rmSync, symlinkSync } from "node:fs";
3-import { tmpdir } from "node:os";
4-import { join } from "node:path";
5-import { canonicalizePath, isSamePath } from "./paths.ts";
6-
7-describe("paths", () => {
8- test("canonicalizePath resolves symlinked directories", () => {
9- const tmp = mkdtempSync(join(tmpdir(), "mc-paths-"));
10-
11- try {
12- const realDir = join(tmp, "real");
13- const linkedDir = join(tmp, "linked");
14- mkdirSync(realDir, { recursive: true });
15- symlinkSync(realDir, linkedDir);
16-
17- expect(canonicalizePath(linkedDir)).toBe(canonicalizePath(realDir));
18- } finally {
19- rmSync(tmp, { recursive: true, force: true });
20- }
21- });
22-
23- test("isSamePath returns true for logical and canonical spellings", () => {
24- const tmp = mkdtempSync(join(tmpdir(), "mc-paths-"));
25-
26- try {
27- const realDir = join(tmp, "real");
28- const linkedDir = join(tmp, "linked");
29- mkdirSync(realDir, { recursive: true });
30- symlinkSync(realDir, linkedDir);
31-
32- expect(isSamePath(realDir, linkedDir)).toBe(true);
33- } finally {
34- rmSync(tmp, { recursive: true, force: true });
35- }
36- });
37-});
src/prompt.test.ts+1−194
@@ -9,15 +9,8 @@ import {
99 } from "node:fs";
1010 import { tmpdir } from "node:os";
1111 import { join, resolve } from "node:path";
12-import type { GitState } from "./git.ts";
1312 import { canonicalizePath } from "./paths.ts";
14-import {
15- buildSystemPrompt,
16- discoverAgentsMd,
17- formatGitLine,
18- resolveAgentsScanRoot,
19-} from "./prompt.ts";
20-import type { Skill } from "./skills.ts";
13+import { discoverAgentsMd, resolveAgentsScanRoot } from "./prompt.ts";
2114
2215 // ---------------------------------------------------------------------------
2316 // Helpers
@@ -207,192 +200,6 @@ describe("resolveAgentsScanRoot", () => {
207200 // formatGitLine
208201 // ---------------------------------------------------------------------------
209202
210-describe("formatGitLine", () => {
211- test("formats full git state", () => {
212- const state: GitState = {
213- root: "/repo",
214- branch: "main",
215- upstream: "origin/main",
216- staged: 3,
217- modified: 1,
218- untracked: 2,
219- ahead: 5,
220- behind: 2,
221- };
222-
223- const line = formatGitLine(state);
224- expect(line).toBe(
225- "Git: branch main | 3 staged, 1 modified, 2 untracked | +5 −2 vs origin/main",
226- );
227- });
228-
229- test("omits staged/modified/untracked when all zero", () => {
230- const state: GitState = {
231- root: "/repo",
232- branch: "main",
233- upstream: null,
234- staged: 0,
235- modified: 0,
236- untracked: 0,
237- ahead: 0,
238- behind: 0,
239- };
240-
241- const line = formatGitLine(state);
242- expect(line).toBe("Git: branch main");
243- });
244-
245- test("omits fields that are zero", () => {
246- const state: GitState = {
247- root: "/repo",
248- branch: "feature",
249- upstream: null,
250- staged: 0,
251- modified: 2,
252- untracked: 0,
253- ahead: 0,
254- behind: 0,
255- };
256-
257- const line = formatGitLine(state);
258- expect(line).toBe("Git: branch feature | 2 modified");
259- });
260-
261- test("omits ahead/behind when both zero", () => {
262- const state: GitState = {
263- root: "/repo",
264- branch: "dev",
265- upstream: "upstream/dev",
266- staged: 1,
267- modified: 0,
268- untracked: 0,
269- ahead: 0,
270- behind: 0,
271- };
272-
273- const line = formatGitLine(state);
274- expect(line).toBe("Git: branch dev | 1 staged");
275- });
276-
277- test("shows only ahead when behind is zero", () => {
278- const state: GitState = {
279- root: "/repo",
280- branch: "main",
281- upstream: "origin/main",
282- staged: 0,
283- modified: 0,
284- untracked: 0,
285- ahead: 3,
286- behind: 0,
287- };
288-
289- const line = formatGitLine(state);
290- expect(line).toBe("Git: branch main | +3 vs origin/main");
291- });
292-
293- test("shows only behind when ahead is zero", () => {
294- const state: GitState = {
295- root: "/repo",
296- branch: "main",
297- upstream: "origin/main",
298- staged: 0,
299- modified: 0,
300- untracked: 0,
301- ahead: 0,
302- behind: 4,
303- };
304-
305- const line = formatGitLine(state);
306- expect(line).toBe("Git: branch main | −4 vs origin/main");
307- });
308-
309- test("uses the actual upstream ref instead of assuming origin", () => {
310- const state: GitState = {
311- root: "/repo",
312- branch: "feature",
313- upstream: "fork/main",
314- staged: 0,
315- modified: 0,
316- untracked: 0,
317- ahead: 2,
318- behind: 1,
319- };
320-
321- const line = formatGitLine(state);
322- expect(line).toBe("Git: branch feature | +2 −1 vs fork/main");
323- });
324-});
325-
326203 // ---------------------------------------------------------------------------
327204 // buildSystemPrompt
328205 // ---------------------------------------------------------------------------
329-
330-describe("buildSystemPrompt", () => {
331- test("includes optional git and readImage environment lines when available", () => {
332- const prompt = buildSystemPrompt({
333- cwd: "/home/user/project",
334- modelLabel: "anthropic/claude-sonnet-4",
335- os: "docker",
336- shell: "zsh",
337- git: {
338- root: "/home/user/project",
339- branch: "main",
340- upstream: "origin/main",
341- staged: 3,
342- modified: 1,
343- untracked: 2,
344- ahead: 5,
345- behind: 2,
346- },
347- supportsImages: true,
348- });
349-
350- expect(prompt).toContain(
351- "- Git: branch main | 3 staged, 1 modified, 2 untracked | +5 −2 vs origin/main",
352- );
353- expect(prompt).toContain("- Read Image: Read an image from disk.");
354- expect(prompt).toContain("- OS: docker");
355- expect(prompt).toContain(
356- "- Shell: zsh. Use `command -v <name>` to check what is available to you; do not assume environment support.",
357- );
358- expect(prompt).toContain(
359- "Use `todoWrite` proactively for multi-step or non-trivial tasks.",
360- );
361- expect(prompt).toContain(
362- "Use `todoRead` when you need to inspect the current list before updating it",
363- );
364- expect(prompt).toContain(
365- "When verifying with build or test commands, avoid leaving generated binaries or scratch artifacts in the requested output location; use temporary paths or remove them before finishing.",
366- );
367- });
368-
369- test("appends AGENTS.md content, skills, and plugin suffixes after the core prompt in order", () => {
370- const skills: Skill[] = [
371- {
372- name: "test",
373- description: "Test skill.",
374- path: "/path/SKILL.md",
375- },
376- ];
377-
378- const prompt = buildSystemPrompt({
379- cwd: "/project",
380- modelLabel: "anthropic/claude-sonnet-4",
381- os: "linux",
382- shell: "bash",
383- agentsMd: [{ path: "/project/AGENTS.md", content: "Project rules" }],
384- skills,
385- pluginSuffixes: ["Plugin context here"],
386- });
387-
388- const coreIdx = prompt.indexOf("You are mini-coder");
389- const agentsIdx = prompt.indexOf("Project rules");
390- const skillsIdx = prompt.indexOf("<available_skills>");
391- const pluginIdx = prompt.indexOf("Plugin context here");
392-
393- expect(coreIdx).toBe(0);
394- expect(agentsIdx).toBeGreaterThan(coreIdx);
395- expect(skillsIdx).toBeGreaterThan(agentsIdx);
396- expect(pluginIdx).toBeGreaterThan(skillsIdx);
397- });
398-});
src/skills.test.ts+1−175
@@ -8,7 +8,7 @@ import {
88 } from "node:fs";
99 import { tmpdir } from "node:os";
1010 import { join } from "node:path";
11-import { buildSkillCatalog, discoverSkills, type Skill } from "./skills.ts";
11+import { discoverSkills } from "./skills.ts";
1212
1313 // ---------------------------------------------------------------------------
1414 // Helpers
@@ -60,27 +60,6 @@ describe("discoverSkills", () => {
6060 expect(skills[0]!.path).toBe(join(tmp, "code-review", "SKILL.md"));
6161 });
6262
63- test("discovers skills from multiple scan paths", () => {
64- const path1 = join(tmp, "scan1");
65- const path2 = join(tmp, "scan2");
66- writeSkill(
67- path1,
68- "skill-a",
69- ["---", "name: skill-a", "description: First skill", "---"].join("\n"),
70- );
71- writeSkill(
72- path2,
73- "skill-b",
74- ["---", "name: skill-b", "description: Second skill", "---"].join("\n"),
75- );
76-
77- const skills = discoverSkills([path1, path2]);
78- expect(skills).toHaveLength(2);
79- const names = skills.map((s) => s.name);
80- expect(names).toContain("skill-a");
81- expect(names).toContain("skill-b");
82- });
83-
8463 test("project-level skill overrides user-level on name collision", () => {
8564 // Earlier paths in the array have higher priority (project-level first)
8665 const project = join(tmp, "project");
@@ -102,33 +81,6 @@ describe("discoverSkills", () => {
10281 expect(skills[0]!.path).toBe(join(project, "deploy", "SKILL.md"));
10382 });
10483
105- test("ignores directories without SKILL.md", () => {
106- mkdirSync(join(tmp, "no-skill"), { recursive: true });
107- writeFileSync(join(tmp, "no-skill", "README.md"), "not a skill");
108- writeSkill(
109- tmp,
110- "real-skill",
111- ["---", "name: real-skill", "description: A real skill", "---"].join(
112- "\n",
113- ),
114- );
115-
116- const skills = discoverSkills([tmp]);
117- expect(skills).toHaveLength(1);
118- expect(skills[0]!.name).toBe("real-skill");
119- });
120-
121- test("returns empty array when scan paths do not exist", () => {
122- const skills = discoverSkills([join(tmp, "nonexistent")]);
123- expect(skills).toEqual([]);
124- });
125-
126- test("returns empty array when scan path has no skill dirs", () => {
127- mkdirSync(join(tmp, "empty"), { recursive: true });
128- const skills = discoverSkills([join(tmp, "empty")]);
129- expect(skills).toEqual([]);
130- });
131-
13284 test("uses directory name as fallback when frontmatter name is missing", () => {
13385 writeSkill(
13486 tmp,
@@ -148,70 +100,6 @@ describe("discoverSkills", () => {
148100 expect(skills[0]!.description).toBe("A tool without a name field");
149101 });
150102
151- test("uses directory name when no frontmatter exists", () => {
152- writeSkill(
153- tmp,
154- "bare-skill",
155- "# Bare Skill\n\nJust content, no frontmatter.\n",
156- );
157-
158- const skills = discoverSkills([tmp]);
159- expect(skills).toHaveLength(1);
160- expect(skills[0]!.name).toBe("bare-skill");
161- expect(skills[0]!.description).toBe("");
162- });
163-
164- test("uses empty description when frontmatter has no description", () => {
165- writeSkill(
166- tmp,
167- "nodesc",
168- ["---", "name: nodesc", "---", "", "Content only."].join("\n"),
169- );
170-
171- const skills = discoverSkills([tmp]);
172- expect(skills).toHaveLength(1);
173- expect(skills[0]!.name).toBe("nodesc");
174- expect(skills[0]!.description).toBe("");
175- });
176-
177- test("handles multi-line description in frontmatter", () => {
178- writeSkill(
179- tmp,
180- "multiline",
181- [
182- "---",
183- "name: multiline",
184- "description: >",
185- " A skill with a multi-line",
186- " description that folds.",
187- "---",
188- ].join("\n"),
189- );
190-
191- const skills = discoverSkills([tmp]);
192- expect(skills).toHaveLength(1);
193- expect(skills[0]!.description).toContain("multi-line");
194- expect(skills[0]!.description).toContain("description that folds.");
195- });
196-
197- test("strips quotes from frontmatter values", () => {
198- writeSkill(
199- tmp,
200- "quoted",
201- [
202- "---",
203- 'name: "quoted-name"',
204- "description: 'A quoted description'",
205- "---",
206- ].join("\n"),
207- );
208-
209- const skills = discoverSkills([tmp]);
210- expect(skills).toHaveLength(1);
211- expect(skills[0]!.name).toBe("quoted-name");
212- expect(skills[0]!.description).toBe("A quoted description");
213- });
214-
215103 test("skips unreadable SKILL.md files", () => {
216104 const skillPath = writeSkill(
217105 tmp,
@@ -227,65 +115,3 @@ describe("discoverSkills", () => {
227115 }
228116 });
229117 });
230-
231-// ---------------------------------------------------------------------------
232-// buildSkillCatalog
233-// ---------------------------------------------------------------------------
234-
235-describe("buildSkillCatalog", () => {
236- test("returns empty string when no skills", () => {
237- expect(buildSkillCatalog([])).toBe("");
238- });
239-
240- test("generates XML catalog with skill entries", () => {
241- const skills: Skill[] = [
242- {
243- name: "code-review",
244- description: "Review code for bugs.",
245- path: "/project/.agents/skills/code-review/SKILL.md",
246- },
247- {
248- name: "deploy",
249- description: "Deploy the app.",
250- path: "/home/user/.agents/skills/deploy/SKILL.md",
251- },
252- ];
253-
254- const catalog = buildSkillCatalog(skills);
255-
256- // Verify overall structure
257- expect(catalog).toContain("<available_skills>");
258- expect(catalog).toContain("</available_skills>");
259-
260- // Verify individual skill entries
261- expect(catalog).toContain("<name>code-review</name>");
262- expect(catalog).toContain(
263- "<description>Review code for bugs.</description>",
264- );
265- expect(catalog).toContain(
266- "<location>/project/.agents/skills/code-review/SKILL.md</location>",
267- );
268-
269- expect(catalog).toContain("<name>deploy</name>");
270- expect(catalog).toContain("<description>Deploy the app.</description>");
271- expect(catalog).toContain(
272- "<location>/home/user/.agents/skills/deploy/SKILL.md</location>",
273- );
274- });
275-
276- test("includes the preamble text", () => {
277- const skills: Skill[] = [
278- {
279- name: "test",
280- description: "A test skill.",
281- path: "/path/to/SKILL.md",
282- },
283- ];
284-
285- const catalog = buildSkillCatalog(skills);
286- expect(catalog).toContain(
287- "The following skills provide specialized instructions",
288- );
289- expect(catalog).toContain("resolve it against the skill directory");
290- });
291-});
src/theme.test.ts+0−78
@@ -1,78 +0,0 @@
1-import { describe, expect, test } from "bun:test";
2-import { DEFAULT_THEME, mergeThemes } from "./theme.ts";
3-
4-const THEME_KEYS = [
5- "userMsgBg",
6- "mutedText",
7- "accentText",
8- "secondaryAccentText",
9- "toolBorder",
10- "toolText",
11- "diffAdded",
12- "diffRemoved",
13- "divider",
14- "dividerPulse",
15- "statusSecondary",
16- "statusEffortScale",
17- "statusContextScale",
18- "error",
19- "overlayBg",
20-] as const;
21-
22-describe("theme", () => {
23- test("DEFAULT_THEME has all required keys", () => {
24- expect(Object.keys(DEFAULT_THEME).sort()).toEqual([...THEME_KEYS].sort());
25- });
26-
27- test("DEFAULT_THEME uses stepped ANSI16 tones for status pills", () => {
28- expect(DEFAULT_THEME.statusSecondary).toEqual({
29- fg: "color15",
30- bg: "color08",
31- });
32- expect(DEFAULT_THEME.statusEffortScale).toEqual([
33- { fg: "color00", bg: "color02" },
34- { fg: "color00", bg: "color06" },
35- { fg: "color15", bg: "color05" },
36- { fg: "color00", bg: "color09" },
37- ]);
38- expect(DEFAULT_THEME.statusContextScale).toEqual([
39- { fg: "color00", bg: "color02" },
40- { fg: "color00", bg: "color06" },
41- { fg: "color15", bg: "color05" },
42- { fg: "color15", bg: "color01" },
43- { fg: "color00", bg: "color09" },
44- ]);
45- });
46-
47- test("mergeThemes with no overrides returns base unchanged", () => {
48- const result = mergeThemes(DEFAULT_THEME);
49- expect(result).toEqual(DEFAULT_THEME);
50- expect(result).not.toBe(DEFAULT_THEME); // new object
51- });
52-
53- test("mergeThemes applies a single partial override", () => {
54- const result = mergeThemes(DEFAULT_THEME, { error: "color05" });
55- expect(result.error).toBe("color05");
56- // Other values preserved
57- expect(result.userMsgBg).toBe(DEFAULT_THEME.userMsgBg);
58- expect(result.divider).toBe(DEFAULT_THEME.divider);
59- });
60-
61- test("mergeThemes applies multiple overrides left-to-right", () => {
62- const result = mergeThemes(
63- DEFAULT_THEME,
64- { error: "color03", divider: "color05" },
65- { error: "color04" },
66- );
67- // Last override wins for error
68- expect(result.error).toBe("color04");
69- // First override preserved for divider (not overridden by second)
70- expect(result.divider).toBe("color05");
71- });
72-
73- test("mergeThemes does not mutate the base theme", () => {
74- const baseCopy = { ...DEFAULT_THEME };
75- mergeThemes(DEFAULT_THEME, { error: "color09" });
76- expect(DEFAULT_THEME).toEqual(baseCopy);
77- });
78-});
src/tools.test.ts+1−550
@@ -11,18 +11,13 @@ import { tmpdir } from "node:os";
1111 import { join } from "node:path";
1212 import type { Message } from "@mariozechner/pi-ai";
1313 import {
14- editTool,
1514 executeEdit,
1615 executeReadImage,
1716 executeShell,
1817 executeTodoRead,
1918 executeTodoWrite,
2019 getTodoItems,
21- shellTool,
2220 type ToolExecResult,
23- todoReadTool,
24- todoWriteTool,
25- truncateOutput,
2621 } from "./tools.ts";
2722
2823 /** Extract the text string from a text-only ToolExecResult. */
@@ -65,48 +60,6 @@ function readFile(name: string): string {
6560 return readFileSync(join(tmp, name), "utf-8");
6661 }
6762
68-async function withShellEnv<T>(
69- shellPath: string,
70- run: () => Promise<T>,
71-): Promise<T> {
72- const previousShell = process.env.SHELL;
73- process.env.SHELL = shellPath;
74- try {
75- return await run();
76- } finally {
77- if (previousShell === undefined) {
78- delete process.env.SHELL;
79- } else {
80- process.env.SHELL = previousShell;
81- }
82- }
83-}
84-
85-function hasUnpairedSurrogate(input: string): boolean {
86- for (let index = 0; index < input.length; index++) {
87- const codeUnit = input.charCodeAt(index);
88- const isHighSurrogate = codeUnit >= 0xd800 && codeUnit <= 0xdbff;
89- const isLowSurrogate = codeUnit >= 0xdc00 && codeUnit <= 0xdfff;
90-
91- if (isHighSurrogate) {
92- const nextCodeUnit = input.charCodeAt(index + 1);
93- const nextIsLowSurrogate =
94- nextCodeUnit >= 0xdc00 && nextCodeUnit <= 0xdfff;
95- if (!nextIsLowSurrogate) {
96- return true;
97- }
98- index++;
99- continue;
100- }
101-
102- if (isLowSurrogate) {
103- return true;
104- }
105- }
106-
107- return false;
108-}
109-
11063 async function waitFor(
11164 predicate: () => boolean,
11265 timeoutMs = 1_000,
@@ -204,33 +157,6 @@ describe("edit", () => {
204157 expect(readFile("new.txt")).toBe("brand new content");
205158 });
206159
207- test("creates parent directories for new files", () => {
208- const result = executeEdit(
209- { path: "deep/nested/dir/file.txt", oldText: "", newText: "nested" },
210- tmp,
211- );
212- expect(result.isError).toBe(false);
213- expect(readFile("deep/nested/dir/file.txt")).toBe("nested");
214- });
215-
216- test("fails to create file when it already exists and oldText is empty", () => {
217- writeFile("existing.txt", "already here");
218- const result = executeEdit(
219- { path: "existing.txt", oldText: "", newText: "overwrite" },
220- tmp,
221- );
222- expect(result.isError).toBe(true);
223- expect(resultText(result)).toContain("already exists");
224- // File unchanged
225- expect(readFile("existing.txt")).toBe("already here");
226- });
227-
228- test("preserves LF line endings", () => {
229- writeFile("lf.txt", "line1\nline2\nline3\n");
230- executeEdit({ path: "lf.txt", oldText: "line2", newText: "replaced" }, tmp);
231- expect(readFile("lf.txt")).toBe("line1\nreplaced\nline3\n");
232- });
233-
234160 test("preserves CRLF line endings", () => {
235161 writeFile("crlf.txt", "line1\r\nline2\r\nline3\r\n");
236162 executeEdit(
@@ -240,62 +166,6 @@ describe("edit", () => {
240166 expect(readFile("crlf.txt")).toBe("line1\r\nreplaced\r\nline3\r\n");
241167 });
242168
243- test("normalizes multi-line replacements to the file's CRLF line endings", () => {
244- writeFile("crlf-multiline.txt", "start\r\nold a\r\nold b\r\nend\r\n");
245- const result = executeEdit(
246- {
247- path: "crlf-multiline.txt",
248- oldText: "old a\r\nold b",
249- newText: "new a\nnew b",
250- },
251- tmp,
252- );
253-
254- expect(result.isError).toBe(false);
255- expect(readFile("crlf-multiline.txt")).toBe(
256- "start\r\nnew a\r\nnew b\r\nend\r\n",
257- );
258- });
259-
260- test("normalizes multi-line replacements to the file's LF line endings", () => {
261- writeFile("lf-multiline.txt", "start\nold a\nold b\nend\n");
262- const result = executeEdit(
263- {
264- path: "lf-multiline.txt",
265- oldText: "old a\nold b",
266- newText: "new a\r\nnew b",
267- },
268- tmp,
269- );
270-
271- expect(result.isError).toBe(false);
272- expect(readFile("lf-multiline.txt")).toBe("start\nnew a\nnew b\nend\n");
273- });
274-
275- test("handles UTF-8 content", () => {
276- writeFile("utf8.txt", "こんにちは世界");
277- const result = executeEdit(
278- { path: "utf8.txt", oldText: "世界", newText: "🌍" },
279- tmp,
280- );
281- expect(result.isError).toBe(false);
282- expect(readFile("utf8.txt")).toBe("こんにちは🌍");
283- });
284-
285- test("handles multi-line old text", () => {
286- writeFile("multi.txt", "function foo() {\n return 1;\n}\n");
287- const result = executeEdit(
288- {
289- path: "multi.txt",
290- oldText: "function foo() {\n return 1;\n}",
291- newText: "function foo() {\n return 2;\n}",
292- },
293- tmp,
294- );
295- expect(result.isError).toBe(false);
296- expect(readFile("multi.txt")).toBe("function foo() {\n return 2;\n}\n");
297- });
298-
299169 test("inserts replacement text literally when it contains replacement markers", () => {
300170 writeFile("literal.txt", "before TARGET after");
301171 const result = executeEdit(
@@ -321,25 +191,6 @@ describe("edit", () => {
321191 expect(result.isError).toBe(false);
322192 expect(readFileSync(join(tmp, "sub", "rel.txt"), "utf-8")).toBe("modified");
323193 });
324-
325- test("handles absolute paths directly", () => {
326- const absPath = writeFile("abs.txt", "content");
327- const result = executeEdit(
328- { path: absPath, oldText: "content", newText: "new content" },
329- tmp,
330- );
331- expect(result.isError).toBe(false);
332- expect(readFile("abs.txt")).toBe("new content");
333- });
334-
335- test("fails when file does not exist for non-empty oldText", () => {
336- const result = executeEdit(
337- { path: "nonexistent.txt", oldText: "something", newText: "else" },
338- tmp,
339- );
340- expect(result.isError).toBe(true);
341- expect(resultText(result)).toContain("not found");
342- });
Cut short: this commit's diff is over 1000 lines.
src/ui.test.ts+369−2226
Cut short: this commit's diff is over 1000 lines.
src/ui/agent.test.ts+0−49
Cut short: this commit's diff is over 1000 lines.
src/ui/commands.test.ts+2−289
Cut short: this commit's diff is over 1000 lines.
src/ui/conversation.test.ts+0−1486
Cut short: this commit's diff is over 1000 lines.
src/ui/help.test.ts+0−65
Cut short: this commit's diff is over 1000 lines.
src/ui/overlay.test.ts+0−42
Cut short: this commit's diff is over 1000 lines.
src/ui/render-performance.test.ts+0−444
Cut short: this commit's diff is over 1000 lines.
src/ui/status.test.ts+0−489
Cut short: this commit's diff is over 1000 lines.
src/version.test.ts+0−49
Cut short: this commit's diff is over 1000 lines.