Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/loopover-miner/lib/purge-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
countStoreByRepo,
describeError,
} from "./store-maintenance.js";
import { argsWantJson, reportCliFailure } from "./cli-error.js";

const PURGE_USAGE = "Usage: loopover-miner purge --repo <owner/repo> [--dry-run] [--json]";

Expand Down Expand Up @@ -166,8 +167,7 @@ function renderPurgeSummary(summary) {
export function runPurge(args, options = {}) {
const parsed = parsePurgeArgs(args);
if ("error" in parsed) {
console.error(parsed.error);
return 2;
return reportCliFailure(argsWantJson(args), parsed.error);
}

if (parsed.dryRun) {
Expand Down
9 changes: 9 additions & 0 deletions test/unit/miner-purge-cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,15 @@ describe("runPurge --dry-run (#5564)", () => {
expect(error).toHaveBeenCalledWith(expect.stringContaining("Usage: loopover-miner purge"));
});

it("emits the {ok:false,error} JSON envelope for an argument error when --json is passed (#5915)", () => {
const log = vi.spyOn(console, "log").mockImplementation(() => undefined);
const error = vi.spyOn(console, "error").mockImplementation(() => undefined);
expect(runPurge(["--json"])).toBe(2);
expect(error).not.toHaveBeenCalled();
const result = JSON.parse(String(log.mock.calls[0]?.[0]));
expect(result).toEqual({ ok: false, error: expect.stringContaining("Usage: loopover-miner purge") });
});

it("opens the real default on-disk stores in dry-run when no resolveDbPaths override is supplied", () => {
const root = tempDir();
const previousDirs: Record<string, string | undefined> = {
Expand Down