Skip to content

Commit e6f41a4

Browse files
committed
fix(test): reject loose env report limits
1 parent b7fef7f commit e6f41a4

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

scripts/test-env-mutation-report.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,7 @@ function parseArgs(argv: string[]): {
397397
continue;
398398
}
399399
if (arg === "--limit") {
400-
const value = Number(argv[index + 1]);
401-
if (!Number.isInteger(value) || value < 0) {
402-
throw new Error("--limit expects a non-negative integer");
403-
}
404-
limit = value;
400+
limit = readNonNegativeIntArg(argv[index + 1]);
405401
index += 1;
406402
continue;
407403
}
@@ -420,6 +416,17 @@ function parseArgs(argv: string[]): {
420416
return { help, includeAllowed, json, limit, repoRoot };
421417
}
422418

419+
function readNonNegativeIntArg(raw: string | undefined): number {
420+
if (!raw || raw.startsWith("--") || !/^\d+$/u.test(raw)) {
421+
throw new Error("--limit expects a non-negative integer");
422+
}
423+
const value = Number(raw);
424+
if (!Number.isSafeInteger(value)) {
425+
throw new Error("--limit expects a non-negative integer");
426+
}
427+
return value;
428+
}
429+
423430
function printHelp(): void {
424431
process.stdout.write(`OpenClaw test env mutation report
425432

test/scripts/test-env-mutation-report.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,29 @@ describe("collectTestEnvMutationReport", () => {
182182
expect(result.status).toBe(1);
183183
expect(result.stderr).toContain("--repo-root expects a path");
184184
});
185+
186+
it("rejects loose CLI limits before scanning the repository", () => {
187+
for (const limit of ["1e3", ""]) {
188+
const result = spawnSync(
189+
process.execPath,
190+
[
191+
"--import",
192+
"tsx",
193+
path.join(process.cwd(), "scripts/test-env-mutation-report.ts"),
194+
"--",
195+
"--limit",
196+
limit,
197+
"--repo-root",
198+
createTempDir("openclaw-env-limit-"),
199+
],
200+
{
201+
encoding: "utf8",
202+
},
203+
);
204+
205+
expect(result.status).toBe(1);
206+
expect(result.stderr).toContain("--limit expects a non-negative integer");
207+
expect(result.stdout).not.toContain("Scanned files:");
208+
}
209+
});
185210
});

0 commit comments

Comments
 (0)