diff --git a/src/cli/commands/stats.ts b/src/cli/commands/stats.ts index 37e2939..5591bd8 100644 --- a/src/cli/commands/stats.ts +++ b/src/cli/commands/stats.ts @@ -34,6 +34,7 @@ function transcriptSummary(path: string): void { if (!existsSync(path)) { console.error(`no such transcript: ${path}`); process.exit(1); + return; } const lines = readFileSync(path, "utf8").split(/\r?\n/).filter(Boolean); let assistantTurns = 0; diff --git a/tests/stats-command.test.ts b/tests/stats-command.test.ts new file mode 100644 index 0000000..88cf79f --- /dev/null +++ b/tests/stats-command.test.ts @@ -0,0 +1,21 @@ +import { join } from "node:path"; +import { describe, expect, it, vi } from "vitest"; +import { statsCommand } from "../src/cli/commands/stats.js"; + +describe("statsCommand", () => { + it("stops after reporting a missing transcript path", () => { + const missing = join("tmp", "missing-transcript.jsonl"); + const err = vi.spyOn(console, "error").mockImplementation(() => {}); + const exit = vi.spyOn(process, "exit").mockImplementation(() => undefined as never); + + expect(() => statsCommand({ transcript: missing })).not.toThrow(); + + expect(exit).toHaveBeenCalledWith(1); + expect(err.mock.calls.map((call) => String(call[0])).join("\n")).toContain( + `no such transcript: ${missing}`, + ); + + err.mockRestore(); + exit.mockRestore(); + }); +});