fix(docker): reject malformed timing limits

This commit is contained in:
Vincent Koc
2026-06-02 21:38:21 +02:00
parent 28b1ea7c0d
commit aed3743630
2 changed files with 14 additions and 3 deletions

View File

@@ -3,6 +3,7 @@
// Accepts scheduler summary.json or lane-timings.json so agents can see the // Accepts scheduler summary.json or lane-timings.json so agents can see the
// slowest lanes and phase critical path before deciding what to rerun. // slowest lanes and phase critical path before deciding what to rerun.
import fs from "node:fs"; import fs from "node:fs";
import { parsePositiveInt } from "./lib/numeric-options.mjs";
function usage() { function usage() {
return "Usage: node scripts/docker-e2e-timings.mjs <summary.json|lane-timings.json> [--limit N]"; return "Usage: node scripts/docker-e2e-timings.mjs <summary.json|lane-timings.json> [--limit N]";
@@ -15,9 +16,9 @@ function parseArgs(argv) {
if (arg === "--help" || arg === "-h") { if (arg === "--help" || arg === "-h") {
options.help = true; options.help = true;
} else if (arg === "--limit") { } else if (arg === "--limit") {
options.limit = Number(argv[(index += 1)] ?? ""); options.limit = parsePositiveInt(argv[(index += 1)], "--limit");
} else if (arg?.startsWith("--limit=")) { } else if (arg?.startsWith("--limit=")) {
options.limit = Number(arg.slice("--limit=".length)); options.limit = parsePositiveInt(arg.slice("--limit=".length), "--limit");
} else if (!options.file) { } else if (!options.file) {
options.file = arg; options.file = arg;
} else { } else {
@@ -27,7 +28,7 @@ function parseArgs(argv) {
if (options.help) { if (options.help) {
return options; return options;
} }
if (!options.file || !Number.isInteger(options.limit) || options.limit < 1) { if (!options.file) {
throw new Error(usage()); throw new Error(usage());
} }
return options; return options;

View File

@@ -42,6 +42,16 @@ describe("Docker E2E helper CLIs", () => {
); );
}); });
it("rejects malformed timings limits without a Node stack trace", () => {
const result = runHelper("scripts/docker-e2e-timings.mjs", "summary.json", "--limit=1e3");
expect(result.status).toBe(1);
expect(result.stdout).toBe("");
expect(result.stderr).toContain("--limit must be a positive integer");
expect(result.stderr).not.toContain("Error:");
expect(result.stderr).not.toContain("at file:");
});
it("prints rerun help without detecting the GitHub repository", () => { it("prints rerun help without detecting the GitHub repository", () => {
const result = runHelper("scripts/docker-e2e-rerun.mjs", "--help"); const result = runHelper("scripts/docker-e2e-rerun.mjs", "--help");