fix(test): reject loose env report limits · openclaw/openclaw@e6f41a4
vincentkoc
·
2026-06-21
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -397,11 +397,7 @@ function parseArgs(argv: string[]): {
|
397 | 397 | continue; |
398 | 398 | } |
399 | 399 | 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]); |
405 | 401 | index += 1; |
406 | 402 | continue; |
407 | 403 | } |
@@ -420,6 +416,17 @@ function parseArgs(argv: string[]): {
|
420 | 416 | return { help, includeAllowed, json, limit, repoRoot }; |
421 | 417 | } |
422 | 418 | |
| 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 | + |
423 | 430 | function printHelp(): void { |
424 | 431 | process.stdout.write(`OpenClaw test env mutation report |
425 | 432 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -182,4 +182,29 @@ describe("collectTestEnvMutationReport", () => {
|
182 | 182 | expect(result.status).toBe(1); |
183 | 183 | expect(result.stderr).toContain("--repo-root expects a path"); |
184 | 184 | }); |
| 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 | +}); |
185 | 210 | }); |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。