mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
fix(test): reject malformed group report numeric flags
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
renderGroupedTestComparison,
|
||||
renderGroupedTestReport,
|
||||
} from "./lib/test-group-report.mjs";
|
||||
import { parsePositiveInt } from "./lib/numeric-options.mjs";
|
||||
import { formatMs } from "./lib/vitest-report-cli-utils.mjs";
|
||||
import { resolveVitestNodeArgs } from "./run-vitest.mjs";
|
||||
import {
|
||||
@@ -55,11 +56,6 @@ function usage() {
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
function parsePositiveInt(value, fallback) {
|
||||
const parsed = Number.parseInt(value ?? "", 10);
|
||||
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
||||
}
|
||||
|
||||
export function parseTestGroupReportArgs(argv) {
|
||||
const args = {
|
||||
allowFailures: false,
|
||||
@@ -130,32 +126,32 @@ export function parseTestGroupReportArgs(argv) {
|
||||
continue;
|
||||
}
|
||||
if (arg === "--limit") {
|
||||
args.limit = parsePositiveInt(argv[index + 1], args.limit);
|
||||
args.limit = parsePositiveInt(argv[index + 1], "--limit");
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
if (arg === "--max-test-ms") {
|
||||
args.maxTestMs = parsePositiveInt(argv[index + 1], args.maxTestMs);
|
||||
args.maxTestMs = parsePositiveInt(argv[index + 1], "--max-test-ms");
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
if (arg === "--timeout-ms") {
|
||||
args.timeoutMs = parsePositiveInt(argv[index + 1], args.timeoutMs);
|
||||
args.timeoutMs = parsePositiveInt(argv[index + 1], "--timeout-ms");
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
if (arg === "--kill-grace-ms") {
|
||||
args.killGraceMs = parsePositiveInt(argv[index + 1], args.killGraceMs);
|
||||
args.killGraceMs = parsePositiveInt(argv[index + 1], "--kill-grace-ms");
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
if (arg === "--concurrency") {
|
||||
args.concurrency = parsePositiveInt(argv[index + 1], args.concurrency);
|
||||
args.concurrency = parsePositiveInt(argv[index + 1], "--concurrency");
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
if (arg === "--top-files") {
|
||||
args.topFiles = parsePositiveInt(argv[index + 1], args.topFiles);
|
||||
args.topFiles = parsePositiveInt(argv[index + 1], "--top-files");
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -319,6 +319,24 @@ describe("scripts/test-group-report arg parsing", () => {
|
||||
timeoutMs: 5000,
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects malformed positive integer flags", () => {
|
||||
for (const flag of [
|
||||
"--limit",
|
||||
"--top-files",
|
||||
"--max-test-ms",
|
||||
"--timeout-ms",
|
||||
"--kill-grace-ms",
|
||||
"--concurrency",
|
||||
]) {
|
||||
expect(() => parseTestGroupReportArgs([flag, "20x"])).toThrow(
|
||||
`${flag} must be a positive integer`,
|
||||
);
|
||||
expect(() => parseTestGroupReportArgs([flag, "0"])).toThrow(
|
||||
`${flag} must be a positive integer`,
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("scripts/test-group-report child process guard", () => {
|
||||
|
||||
Reference in New Issue
Block a user