diff --git a/scripts/ci-run-timings.mjs b/scripts/ci-run-timings.mjs index eb701665150..6cec3e244c1 100644 --- a/scripts/ci-run-timings.mjs +++ b/scripts/ci-run-timings.mjs @@ -386,7 +386,13 @@ export function parseRunTimingArgs(args) { index = recentOption.nextIndex; continue; } - explicitRunId ??= arg; + if (arg.startsWith("-")) { + throw new Error(`Unknown CI run timing option: ${arg}`); + } + if (explicitRunId) { + throw new Error(`Unexpected CI run id argument: ${arg}`); + } + explicitRunId = arg; } return { @@ -409,9 +415,13 @@ function consumePositiveIntFlag(args, index, flag) { if (arg !== flag) { return null; } + const rawValue = args[index + 1]; + if (!rawValue || rawValue.startsWith("--")) { + throw new Error(`${flag} requires a value`); + } return { nextIndex: index + 1, - value: parsePositiveInt(args[index + 1], flag), + value: parsePositiveInt(rawValue, flag), }; } diff --git a/test/scripts/ci-run-timings.test.ts b/test/scripts/ci-run-timings.test.ts index 5d4942f801f..73c0c5ba0ea 100644 --- a/test/scripts/ci-run-timings.test.ts +++ b/test/scripts/ci-run-timings.test.ts @@ -257,9 +257,23 @@ describe("scripts/ci-run-timings.mjs", () => { ["--limit=1e3"], ["--recent", "recent"], ["--recent", "0"], - ["--recent"], ]) { expect(() => parseRunTimingArgs(args)).toThrow("must be a positive integer"); } }); + + it("rejects missing monitor limits instead of treating flags as values", () => { + for (const args of [["--limit"], ["--limit", "--recent", "4"], ["--recent"]]) { + expect(() => parseRunTimingArgs(args)).toThrow("requires a value"); + } + }); + + it("rejects unknown monitor flags and duplicate run ids", () => { + expect(() => parseRunTimingArgs(["--run-id", "123456"])).toThrow( + "Unknown CI run timing option: --run-id", + ); + expect(() => parseRunTimingArgs(["123456", "789012"])).toThrow( + "Unexpected CI run id argument: 789012", + ); + }); });