xonecas.io
64875
Mc

mini-coder / commit fdcd3a5

Audit and quiet test suite

xonecas2026-03-10 fdcd3a51c46bf3c7470487e8ca130f950960d8c4 parent 0d5e7e3

7 files changed

TODO.md+4−0
@@ -1,5 +1,9 @@
11 # TODO
22
3+## Tool hook issue
4+
5+- If the hook alters the code, like a formatting hook like we use, the llm sees the diff before the formatting change, causing unecessary re-reads. The post tool hooks should run before we send the output diff to the agent.
6+
37 ## Investigate error:
48
59 ```
package.json+2−1
@@ -14,7 +14,8 @@
1414 "lint": "biome check src",
1515 "format": "biome format --write src",
1616 "knip": "knip",
17- "test": "bun test",
17+ "test": "bun test --only-failures",
18+ "test:verbose": "bun test",
1819 "jscpd": "jscpd src"
1920 },
2021 "dependencies": {
src/agent/agent.test.ts+0−36
@@ -1,5 +1,4 @@
11 import { describe, expect, test } from "bun:test";
2-import { getTurnControlAction } from "../cli/input.ts";
32 import type { CoreMessage } from "../llm-api/turn.ts";
43 import {
54 extractAssistantText,
@@ -109,41 +108,6 @@ describe("hasRalphSignal", () => {
109108 });
110109 });
111110
112-// ─── getTurnControlAction ─────────────────────────────────────────────────────
113-
114-describe("getTurnControlAction", () => {
115- test("returns cancel for ESC byte (0x1B)", () => {
116- expect(getTurnControlAction(Buffer.from([0x1b]))).toBe("cancel");
117- });
118-
119- test("returns quit for Ctrl+C byte (0x03)", () => {
120- expect(getTurnControlAction(Buffer.from([0x03]))).toBe("quit");
121- });
122-
123- test("returns null for regular printable bytes", () => {
124- expect(getTurnControlAction(Buffer.from([0x61]))).toBeNull(); // 'a'
125- });
126-
127- test("returns null for multi-byte ESC sequence (arrow keys, function keys)", () => {
128- // Arrow-up: ESC [ A — should NOT cancel
129- expect(getTurnControlAction(Buffer.from([0x1b, 0x5b, 0x41]))).toBeNull();
130- // Arrow-down: ESC [ B
131- expect(getTurnControlAction(Buffer.from([0x1b, 0x5b, 0x42]))).toBeNull();
132- });
133-
134- test("returns null for two-byte ESC sequence", () => {
135- expect(getTurnControlAction(Buffer.from([0x1b, 0x66]))).toBeNull(); // Alt+f
136- });
137-
138- test("returns quit for Ctrl+C even in multi-byte chunk", () => {
139- expect(getTurnControlAction(Buffer.from([0x61, 0x03, 0x62]))).toBe("quit");
140- });
141-
142- test("returns null for empty buffer", () => {
143- expect(getTurnControlAction(Buffer.from([]))).toBeNull();
144- });
145-});
146-
147111 // ─── makeInterruptMessage ─────────────────────────────────────────────────────
148112
149113 describe("makeInterruptMessage", () => {
src/cli/agents.test.ts+4−0
@@ -3,15 +3,19 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
33 import { tmpdir } from "node:os";
44 import { join } from "node:path";
55 import { loadAgents } from "./agents.ts";
6+import { terminal } from "./terminal-io.ts";
67
78 describe("loadAgents", () => {
89 let dir: string;
10+ const originalStdoutWrite = terminal.stdoutWrite.bind(terminal);
911
1012 beforeEach(() => {
1113 dir = mkdtempSync(join(tmpdir(), "mc-agents-test-"));
14+ terminal.stdoutWrite = () => {};
1215 });
1316
1417 afterEach(() => {
18+ terminal.stdoutWrite = originalStdoutWrite;
1519 rmSync(dir, { recursive: true, force: true });
1620 });
1721
src/cli/input.test.ts+7−2
@@ -121,16 +121,21 @@ describe("getTurnControlAction", () => {
121121 expect(getTurnControlAction(new Uint8Array([0x03]))).toBe("quit");
122122 });
123123
124- test("only cancels on a lone ESC — multi-byte chunks containing ESC are not cancel", () => {
124+ test("only cancels on a lone ESC — escape sequences are ignored and Ctrl+C still wins", () => {
125125 // [ESC, Ctrl+C]: not a lone ESC, Ctrl+C still fires quit
126126 expect(getTurnControlAction(new Uint8Array([0x1b, 0x03]))).toBe("quit");
127127 // [Ctrl+C, ESC]: Ctrl+C fires quit
128128 expect(getTurnControlAction(new Uint8Array([0x03, 0x1b]))).toBe("quit");
129129 // Arrow-up sequence ESC [ A: not cancel
130130 expect(getTurnControlAction(new Uint8Array([0x1b, 0x5b, 0x41]))).toBeNull();
131+ // Arrow-down sequence ESC [ B: not cancel
132+ expect(getTurnControlAction(new Uint8Array([0x1b, 0x5b, 0x42]))).toBeNull();
133+ // Two-byte escape sequence such as Alt+f: not cancel
134+ expect(getTurnControlAction(new Uint8Array([0x1b, 0x66]))).toBeNull();
131135 });
132136
133- test("ignores unrelated bytes", () => {
137+ test("returns null for empty or unrelated bytes", () => {
138+ expect(getTurnControlAction(new Uint8Array([]))).toBeNull();
134139 expect(getTurnControlAction(new Uint8Array([0x61, 0x62, 0x63]))).toBeNull();
135140 });
136141 });
src/cli/load-markdown-configs.test.ts+4−0
@@ -3,14 +3,18 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
33 import { tmpdir } from "node:os";
44 import { join } from "node:path";
55 import { loadMarkdownConfigs } from "./load-markdown-configs.ts";
6+import { terminal } from "./terminal-io.ts";
67
78 let dir: string;
9+const originalStdoutWrite = terminal.stdoutWrite.bind(terminal);
810
911 beforeEach(() => {
1012 dir = mkdtempSync(join(tmpdir(), "mc-load-markdown-configs-test-"));
13+ terminal.stdoutWrite = () => {};
1114 });
1215
1316 afterEach(() => {
17+ terminal.stdoutWrite = originalStdoutWrite;
1418 rmSync(dir, { recursive: true, force: true });
1519 });
1620
src/cli/markdown.test.ts+40−88
@@ -43,43 +43,27 @@ function hasYellow(s: string): boolean {
4343 // ---------------------------------------------------------------------------
4444
4545 describe("renderMarkdown – headings", () => {
46- test("h1 renders the heading text without the # prefix", () => {
47- const out = renderMarkdown("# Hello World");
48- expect(strip(out)).toBe("Hello World");
49- });
50-
51- test("h1 is bold and cyan", () => {
52- const out = renderMarkdown("# Hello");
53- expect(hasBold(out)).toBe(true);
54- expect(hasCyan(out)).toBe(true);
55- });
56-
57- test("h2 renders the heading text without the ## prefix", () => {
58- const out = renderMarkdown("## Section");
59- expect(strip(out)).toBe("Section");
60- });
61-
62- test("h2 is bold and cyan", () => {
63- const out = renderMarkdown("## Section");
64- expect(hasBold(out)).toBe(true);
65- expect(hasCyan(out)).toBe(true);
66- });
67-
68- test("h3 renders the heading text without the ### prefix", () => {
69- const out = renderMarkdown("### Sub");
70- expect(strip(out)).toBe("Sub");
71- });
72-
73- test("h3 is bold but NOT cyan (only bold)", () => {
74- const out = renderMarkdown("### Sub");
75- expect(hasBold(out)).toBe(true);
76- expect(hasCyan(out)).toBe(false);
77- });
78-
79- test("h4+ is treated the same as h3 (#{3,} pattern)", () => {
80- const h4 = strip(renderMarkdown("#### Deep"));
81- const h3 = strip(renderMarkdown("### Deep"));
82- expect(h4).toBe(h3);
46+ for (const [input, visible] of [
47+ ["# Hello World", "Hello World"],
48+ ["## Section", "Section"],
49+ ] as const) {
50+ test(`${input.slice(0, input.indexOf(" "))} strips its marker and keeps bold cyan styling`, () => {
51+ const out = renderMarkdown(input);
52+ expect(strip(out)).toBe(visible);
53+ expect(hasBold(out)).toBe(true);
54+ expect(hasCyan(out)).toBe(true);
55+ });
56+ }
57+
58+ test("h3+ strips markers, stays bold, and drops cyan", () => {
59+ const h3 = renderMarkdown("### Sub");
60+ const h4 = renderMarkdown("#### Deep");
61+ expect(strip(h3)).toBe("Sub");
62+ expect(hasBold(h3)).toBe(true);
63+ expect(hasCyan(h3)).toBe(false);
64+ expect(strip(h4)).toBe("Deep");
65+ expect(hasBold(h4)).toBe(true);
66+ expect(hasCyan(h4)).toBe(false);
8367 });
8468
8569 test("multiple headings each rendered on own line", () => {
@@ -89,30 +73,15 @@ describe("renderMarkdown – headings", () => {
8973 });
9074
9175 describe("renderMarkdown – horizontal rules", () => {
92- test("--- renders as a dim rule", () => {
93- const out = renderMarkdown("---");
94- expect(hasDim(out)).toBe(true);
95- expect(strip(out)).toMatch(/^─+$/);
76+ test("supported rule markers render a dim divider", () => {
77+ for (const input of ["---", "===", "***", "----"]) {
78+ const out = renderMarkdown(input);
79+ expect(hasDim(out)).toBe(true);
80+ expect(strip(out)).toMatch(/^─+$/);
81+ }
9682 });
9783
98- test("=== renders as a dim rule", () => {
99- const out = renderMarkdown("===");
100- expect(hasDim(out)).toBe(true);
101- expect(strip(out)).toMatch(/^─+$/);
102- });
103-
104- test("*** renders as a dim rule", () => {
105- const out = renderMarkdown("***");
106- expect(hasDim(out)).toBe(true);
107- expect(strip(out)).toMatch(/^─+$/);
108- });
109-
110- test("---- (4 dashes) is also a horizontal rule", () => {
111- const out = strip(renderMarkdown("----"));
112- expect(out).toMatch(/^─+$/);
113- });
114-
115- test("-- (2 dashes) is NOT a horizontal rule — passed through as plain text", () => {
84+ test("too-short markers are passed through as plain text", () => {
11685 const out = strip(renderMarkdown("--"));
11786 expect(out).toBe("--");
11887 });
@@ -183,45 +152,36 @@ describe("renderMarkdown – blockquotes", () => {
183152 });
184153
185154 describe("renderMarkdown – unordered lists", () => {
186- test("- item renders with · bullet", () => {
187- const out = strip(renderMarkdown("- item"));
188- expect(out).toBe("· item");
155+ test("all supported unordered markers render the same bullet", () => {
156+ for (const input of ["- item", "* item", "+ item"]) {
157+ expect(strip(renderMarkdown(input))).toBe("· item");
158+ }
189159 });
190160
191- test("* item renders with · bullet", () => {
192- const out = strip(renderMarkdown("* item"));
193- expect(out).toBe("· item");
194- });
195-
196- test("+ item renders with · bullet", () => {
197- const out = strip(renderMarkdown("+ item"));
198- expect(out).toBe("· item");
199- });
200-
201- test("indented - item preserves leading whitespace", () => {
161+ test("indented items preserve leading whitespace", () => {
202162 const out = strip(renderMarkdown(" - nested"));
203163 expect(out).toBe(" · nested");
204164 });
205165
206- test("list item content goes through inline processing", () => {
166+ test("list item content still goes through inline processing", () => {
207167 const out = strip(renderMarkdown("- **bold** item"));
208- // bold markers stripped in plain text, content preserved
209168 expect(out).toBe("· bold item");
210169 });
211170 });
212171
213172 describe("renderMarkdown – ordered lists", () => {
214- test("1. item renders number with dim styling", () => {
215- const out = strip(renderMarkdown("1. first"));
216- expect(out).toBe("1. first");
173+ test("ordered list numbers stay visible while the marker is dimmed", () => {
174+ const out = renderMarkdown("1. first");
175+ expect(strip(out)).toBe("1. first");
176+ expect(hasDim(out)).toBe(true);
217177 });
218178
219- test("multi-item ordered list", () => {
179+ test("multi-item ordered lists preserve numbering across lines", () => {
220180 const out = strip(renderMarkdown("1. alpha\n2. beta\n3. gamma"));
221181 expect(out).toBe("1. alpha\n2. beta\n3. gamma");
222182 });
223183
224- test("ordered list item content goes through inline processing", () => {
184+ test("ordered list item content still goes through inline processing", () => {
225185 const out = strip(renderMarkdown("1. **bold** text"));
226186 expect(out).toBe("1. bold text");
227187 });
@@ -335,12 +295,4 @@ describe("renderMarkdown – inline combinations", () => {
335295 const out = strip(renderMarkdown("**foo *bar*"));
336296 expect(out).toBe("**foo bar");
337297 });
338-
339- test("***text*** does not corrupt surrounding text — stray * passed through as plain", () => {
340- // Triple-star is ambiguous; the parser should not silently eat content.
341- // Current behaviour: outer * passed through as plain, inner text bolded.
342- const out = strip(renderMarkdown("***text***"));
343- expect(out).toContain("text");
344- expect(out).not.toContain("**");
345- });
346298 });