xonecas.io
64875
Mc

mini-coder / commit 13654ac

test: tighten cli regression coverage

xonecas2026-03-14 13654ac74d0a76e4211ab43f7aedcc93e4599511 parent 7403923

3 files changed

src/cli/output.test.ts+2−1
@@ -17,7 +17,8 @@ function captureStdout(): void {
1717 }
1818
1919 function stripAnsi(text: string): string {
20- return text.replace(/\x1b\[[0-9;]*m/g, "");
20+ const esc = String.fromCharCode(0x1b);
21+ return text.replace(new RegExp(`${esc}\\[[0-9;]*m`, "g"), "");
2122 }
2223
2324 describe("renderUserMessage", () => {
src/llm-api/turn-request.test.ts+3−12
@@ -1,6 +1,6 @@
1-import { describe, expect, mock, test } from "bun:test";
2-import { buildStreamTextRequest } from "./turn-request.ts";
1+import { describe, expect, test } from "bun:test";
32 import type { CoreMessage } from "./turn.ts";
3+import { buildStreamTextRequest } from "./turn-request.ts";
44
55 describe("buildStreamTextRequest", () => {
66 test("overrides the AI SDK default onError logger", () => {
@@ -22,15 +22,6 @@ describe("buildStreamTextRequest", () => {
2222 maxSteps: 50,
2323 });
2424
25- const originalConsoleError = console.error;
26- const consoleError = mock(() => {});
27- console.error = consoleError;
28- try {
29- request.onError?.({ error: new Error("boom") });
30- } finally {
31- console.error = originalConsoleError;
32- }
33-
34- expect(consoleError).not.toHaveBeenCalled();
25+ expect(request.onError?.({ error: new Error("boom") })).toBeUndefined();
3526 });
3627 });
src/tools/shell.test.ts+18−20
@@ -1,31 +1,29 @@
11 import { describe, expect, it, mock } from "bun:test";
22 import { shellTool } from "./shell.ts";
33
4-describe("shellTool", () => {
5- it("appends a newline to streamed output when the command does not print one", async () => {
6- const onOutput = mock(() => {});
4+function collectOutput(mockFn: ReturnType<typeof mock>): string {
5+ return mockFn.mock.calls.map((call) => String(call[0] ?? "")).join("");
6+}
7+
8+async function expectStreamedOutput(command: string, expectedOutput: string) {
9+ const onOutput = mock(() => {});
10+ const result = await shellTool.execute({
11+ command,
12+ timeout: 30_000,
13+ onOutput,
14+ });
715
8- const result = await shellTool.execute({
9- command: "printf ok",
10- timeout: 30_000,
11- onOutput,
12- });
16+ expect(result.stdout).toBe(expectedOutput.trimEnd());
17+ expect(collectOutput(onOutput)).toBe(expectedOutput);
18+}
1319
14- expect(result.stdout).toBe("ok");
15- expect(onOutput.mock.calls.map(([chunk]) => chunk).join("")).toBe("ok\n");
20+describe("shellTool", () => {
21+ it("appends a newline to streamed output when the command does not print one", async () => {
22+ await expectStreamedOutput("printf ok", "ok\n");
1623 });
1724
1825 it("does not duplicate a trailing newline in streamed output", async () => {
19- const onOutput = mock(() => {});
20-
21- const result = await shellTool.execute({
22- command: "printf 'ok\\n'",
23- timeout: 30_000,
24- onOutput,
25- });
26-
27- expect(result.stdout).toBe("ok");
28- expect(onOutput.mock.calls.map(([chunk]) => chunk).join("")).toBe("ok\n");
26+ await expectStreamedOutput("printf 'ok\\n'", "ok\n");
2927 });
3028 });