Skip to content

Commit 38cefb6

Browse files
Mossakaclaude
andauthored
fix: validate AWF_BENCHMARK_ITERATIONS env var input (#1873)
If AWF_BENCHMARK_ITERATIONS is non-numeric (NaN) or <= 0, the benchmark script would produce an empty values array causing stats() to throw. Validate and clamp to a positive integer, falling back to the default (30) with a clear stderr warning when the input is invalid. Follow-up to #1870 addressing Copilot review feedback. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a554e4a commit 38cefb6

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

scripts/ci/benchmark-performance.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,26 @@ import { stats, parseMb, checkRegressions, BenchmarkResult, BenchmarkReport } fr
2020

2121
// ── Configuration ──────────────────────────────────────────────────
2222

23-
const ITERATIONS = parseInt(process.env.AWF_BENCHMARK_ITERATIONS || '30', 10);
23+
const DEFAULT_ITERATIONS = 30;
24+
25+
function getIterations(): number {
26+
const raw = process.env.AWF_BENCHMARK_ITERATIONS;
27+
if (raw === undefined) {
28+
return DEFAULT_ITERATIONS;
29+
}
30+
31+
const parsed = Number.parseInt(raw, 10);
32+
if (!Number.isInteger(parsed) || parsed <= 0) {
33+
console.error(
34+
`Invalid AWF_BENCHMARK_ITERATIONS=${JSON.stringify(raw)}; using default ${DEFAULT_ITERATIONS}.`
35+
);
36+
return DEFAULT_ITERATIONS;
37+
}
38+
39+
return parsed;
40+
}
41+
42+
const ITERATIONS = getIterations();
2443
const AWF_CMD = "sudo awf --build-local";
2544
const ALLOWED_DOMAIN = "api.github.com";
2645
const CLEANUP_CMD = "sudo docker compose down -v 2>/dev/null; sudo docker rm -f awf-squid awf-agent awf-iptables-init 2>/dev/null; sudo docker network prune -f 2>/dev/null";

0 commit comments

Comments
 (0)