Skip to content

Commit ed900a5

Browse files
jrusso1020claude
andcommitted
fix(cli): reject a bad snapshot --frames, quiet spinner progress, drop added comments
- `snapshot --frames abc` (or 0, -3, 2.5) is now a usage error: exit 2, and a usage_error envelope under --json. It used to fall back to 5 frames silently. - An unattended spinner prints its start line once and its outcome, but no longer one line per progress update, which flooded stderr during remove-background and the Chrome download. - Removes the comment lines this branch added, so the comment ratchet passes. - The render --json test now expects exit 2 and usage_error for bad inline --variables. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 923b282 commit ed900a5

10 files changed

Lines changed: 23 additions & 19 deletions

File tree

‎packages/cli/src/cli.agentMode.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ describe("agent-mode contract", () => {
227227
["cloud delete render_1", "Confirmation required"],
228228
["snapshot --at 1 --range 0,1", "Use only one of"],
229229
["snapshot --at x", "--at must be"],
230+
["snapshot --frames abc", "--frames must be a positive integer"],
231+
["snapshot --frames -3", "--frames must be a positive integer"],
230232
["compare a.html", "need 2+ paths"],
231233
["compare a.html b.html --cols 0", "--cols must be"],
232234
["grade-compare --for frame.png", "Exactly one of --grades or --luts"],
@@ -327,9 +329,9 @@ describe("agent-mode contract", () => {
327329
writeFileSync(join(project, "index.html"), "<!doctype html><html><body></body></html>");
328330
const run = await runAsAgent(["render", project, "--variables", "{bad", "--json"]);
329331
expectQuiet(run);
330-
expect(run.code, run.stderr).toBe(1);
332+
expect(run.code, run.stderr).toBe(2);
331333
expect(run.stdout.trim().split("\n")).toHaveLength(1);
332-
expectJsonFailure(run, "runtime_error");
334+
expectJsonFailure(run, "usage_error");
333335
expect(JSON.parse(run.stdout).error.message).toBe("Invalid JSON in --variables");
334336
});
335337

‎packages/cli/src/commands/check.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ export function createCheckCommand(
311311
});
312312
}
313313

314-
/** A bad flag is a usage error (exit 2); anything else is a failed check (exit 1). */
315314
function reportCheckFailure(
316315
error: unknown,
317316
asJson: boolean,

‎packages/cli/src/commands/cloudrun.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,6 @@ async function runRenderBatch(args: Record<string, unknown>): Promise<void> {
653653
failUsage();
654654
}
655655
const fps = resolveCloudRunFps(args, projectDir, "render-batch");
656-
// Check the render flags before any upload; inside the per-entry loop a bad flag would only
657-
// count as N failed renders.
658656
buildRenderConfig(args, fps, width, height, undefined);
659657
if (!existsSync(resolve(batchPath))) {
660658
console.error(`[cloudrun render-batch] batch file not found: ${batchPath}`);

‎packages/cli/src/commands/snapshot.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { reportArtifacts } from "../utils/toolContext.js";
1212
import { withProjectLock } from "../utils/projectLock.js";
1313
import {
1414
parseSnapshotAt,
15+
parseSnapshotFrames,
1516
parseSnapshotRange,
1617
sampleSnapshotRange,
1718
resolveSnapshotCompositionRange,
@@ -1484,7 +1485,7 @@ export default defineCommand({
14841485
);
14851486
if (clash) throw new CliUsageError(`--review picks its own frames; drop --${clash}`);
14861487
}
1487-
const frames = parseInt(args.frames as string, 10) || 5;
1488+
const frames = args.frames === undefined ? 5 : parseSnapshotFrames(String(args.frames));
14881489
const range = args.range === undefined ? undefined : parseSnapshotRange(String(args.range));
14891490
const atTimestamps = args.at === undefined ? undefined : parseSnapshotAt(String(args.at));
14901491
if (args.keep === true && atTimestamps) assertDistinctKeepNames(atTimestamps);

‎packages/cli/src/commands/snapshotSampling.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, it, expect } from "vitest";
22
import {
3+
parseSnapshotFrames,
34
parseSnapshotRange,
45
sampleSnapshotRange,
56
resolveSnapshotCompositionRange,
@@ -18,6 +19,9 @@ describe("snapshot scoped sampling", () => {
1819
expect(() => parseSnapshotRange(v)).toThrow();
1920
expect(parseSnapshotRange("1.8:2.5")).toEqual([1.8, 2.5]);
2021
expect(parseSnapshotRange("1.8,2.5")).toEqual([1.8, 2.5]);
22+
for (const v of ["abc", "-3", "0", "2.5", ""])
23+
expect(() => parseSnapshotFrames(v)).toThrow("--frames must be a positive integer");
24+
expect(parseSnapshotFrames("10")).toBe(10);
2125
for (const n of [0, -1, 1.5, NaN]) expect(() => sampleSnapshotRange([1, 2], n, 5)).toThrow();
2226
expect(() => sampleSnapshotRange([1, 6], 5, 5)).toThrow();
2327
});

‎packages/cli/src/commands/snapshotSampling.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export function parseSnapshotRange(value: string): SnapshotRange {
1414
throw new CliUsageError("--range must be START,END in seconds, with 0 <= START < END");
1515
return [range[0]!, range[1]!];
1616
}
17+
export function parseSnapshotFrames(value: string): number {
18+
const frames = Number(value);
19+
if (value.trim() === "" || !Number.isInteger(frames) || frames < 1)
20+
throw new CliUsageError("--frames must be a positive integer");
21+
return frames;
22+
}
1723
export function parseSnapshotAt(value: string): number[] {
1824
const times = value.split(",").map((part) => (part.trim() === "" ? NaN : Number(part)));
1925
if (!times.every((time) => Number.isFinite(time) && time >= 0))

‎packages/cli/src/ui/prompts.test.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,14 @@ describe("prompt wrapper", () => {
4646
}
4747
});
4848

49-
it("an unattended spinner writes its start, progress and outcome as plain lines on stderr", () => {
49+
it("an unattended spinner writes its start and outcome, not its progress, on stderr", () => {
5050
const write = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
5151
try {
5252
const spin = prompts.spinner();
5353
spin.start("\u001b[36mTranscoding\u001b[39m clip.mov");
5454
spin.message("Still transcoding...");
5555
spin.stop("\u001b[32mDone\u001b[39m");
56-
expect(write.mock.calls).toEqual([
57-
["Transcoding clip.mov\n"],
58-
["Still transcoding...\n"],
59-
["Done\n"],
60-
]);
56+
expect(write.mock.calls).toEqual([["Transcoding clip.mov\n"], ["Done\n"]]);
6157
expect(clack.spinner).not.toHaveBeenCalled();
6258
} finally {
6359
write.mockRestore();

‎packages/cli/src/ui/prompts.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function lineSpinner(): SpinnerResult {
5858
};
5959
return {
6060
start: say,
61-
message: say,
61+
message: () => {},
6262
stop: say,
6363
cancel: say,
6464
error: say,
@@ -67,7 +67,7 @@ function lineSpinner(): SpinnerResult {
6767
};
6868
}
6969

70-
/** Unattended, each start, progress and outcome message is written as one plain line on stderr. */
70+
/** Unattended, the start and outcome messages are each written as one plain line on stderr. */
7171
export function spinner(opts?: SpinnerOptions): SpinnerResult {
7272
return isUnattended() ? lineSpinner() : clack.spinner(opts);
7373
}

‎packages/cli/src/utils/jsonError.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ export function jsonFailure(code: string, message: string, hint?: string): JsonF
2323
return { ok: false, error: hint ? { code, message, hint } : { code, message } };
2424
}
2525

26-
/** Reports a caught failure as the --json envelope or one line on stderr, then fails the command
27-
* (exit 2 for a usage error, else 1). */
26+
/** Reports a caught failure as the --json envelope or one stderr line; exit 2 if usage, else 1. */
2827
export function failCaught(
2928
error: unknown,
3029
json: boolean,

‎packages/cli/src/utils/variables.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,9 @@ export function resolveVariablesArg(
135135
if (!result.ok) {
136136
const { title, message } = variablesErrorMessage(result.error);
137137
errorBox(title, message);
138-
// The flags themselves are wrong (both given, or bad inline JSON); a file that cannot be read
139-
// or holds bad JSON is a runtime failure.
140138
const { kind } = result.error;
141-
if (kind === "conflict" || (inline != null && kind !== "read-error")) failUsage();
139+
const flagsAreWrong = kind === "conflict" || (inline != null && kind !== "read-error");
140+
if (flagsAreWrong) failUsage();
142141
failCommand();
143142
}
144143
return result.value;

0 commit comments

Comments
 (0)