fix(qa): reject duplicate abort leak controls

This commit is contained in:
Vincent Koc 2026-06-23 16:46:39 +02:00
parent bde5be874a
commit e9b017d9dc
No known key found for this signature in database
2 changed files with 35 additions and 0 deletions

View file

@ -34,6 +34,16 @@ type Options = {
quiet: boolean; quiet: boolean;
}; };
const VALUE_FLAGS = new Set([
"--iters",
"--batches",
"--snap-dir",
"--mode",
"--max-rss-growth-mb",
"--max-tracked-retention",
"--scope-bytes",
]);
function readValue(raw: string | undefined, flag: string): string { function readValue(raw: string | undefined, flag: string): string {
const value = raw?.trim() ?? ""; const value = raw?.trim() ?? "";
if (!value || value.startsWith("-")) { if (!value || value.startsWith("-")) {
@ -53,9 +63,16 @@ function parseArgs(argv: string[]): Options {
scopeBytes: 2_000_000, scopeBytes: 2_000_000,
quiet: false, quiet: false,
}; };
const seenValueFlags = new Set<string>();
for (let i = 0; i < argv.length; i += 1) { for (let i = 0; i < argv.length; i += 1) {
const arg = argv[i]; const arg = argv[i];
const next = argv[i + 1]; const next = argv[i + 1];
if (VALUE_FLAGS.has(arg)) {
if (seenValueFlags.has(arg)) {
fail(`${arg} was provided more than once`);
}
seenValueFlags.add(arg);
}
switch (arg) { switch (arg) {
case "--iters": case "--iters":
opts.iters = parsePositiveInt(next, arg); opts.iters = parsePositiveInt(next, arg);

View file

@ -53,6 +53,24 @@ describe("scripts/embedded-run-abort-leak", () => {
expect(readdirSync(looseThresholdProbe.snapDir)).toEqual([]); expect(readdirSync(looseThresholdProbe.snapDir)).toEqual([]);
}); });
it("rejects duplicate thresholds before writing heap snapshots", () => {
const snapDir = makeTempRoot();
const result = runHarness([
"--snap-dir",
snapDir,
"--iters",
"1",
"--iters",
"2",
"--quiet",
]);
expect(result.status).toBe(2);
expect(result.stdout).toBe("");
expect(result.stderr).toContain("error: --iters was provided more than once");
expect(readdirSync(snapDir)).toEqual([]);
});
it("rejects missing snapshot directories before writing heap snapshots", () => { it("rejects missing snapshot directories before writing heap snapshots", () => {
const result = runHarness(["--snap-dir", "--quiet", "--iters", "1", "--batches", "1"]); const result = runHarness(["--snap-dir", "--quiet", "--iters", "1", "--batches", "1"]);