fix(scripts): bound Docker E2E JSON helpers

This commit is contained in:
Vincent Koc
2026-06-16 07:30:48 +02:00
parent 325d0208d0
commit 9a0aefb73f
3 changed files with 101 additions and 4 deletions
+27 -1
View File
@@ -2,6 +2,10 @@
// Converts scheduler JSON into GitHub Actions outputs and compact markdown
// summaries so the workflow does not duplicate Docker E2E planning logic.
import fs from "node:fs";
import { parsePositiveInt } from "./lib/numeric-options.mjs";
const JSON_ARTIFACT_MAX_BYTES_ENV = "OPENCLAW_DOCKER_E2E_JSON_ARTIFACT_MAX_BYTES";
const DEFAULT_JSON_ARTIFACT_MAX_BYTES = 16 * 1024 * 1024;
function usage() {
return [
@@ -13,7 +17,29 @@ function usage() {
}
function readJson(file) {
return JSON.parse(fs.readFileSync(file, "utf8"));
return JSON.parse(readJsonArtifactText(file));
}
function readJsonArtifactText(file) {
const maxBytes = readPositiveIntEnv(JSON_ARTIFACT_MAX_BYTES_ENV, DEFAULT_JSON_ARTIFACT_MAX_BYTES);
const stat = fs.statSync(file);
if (!stat.isFile()) {
throw new Error(`JSON artifact is not a file: ${file}`);
}
if (stat.size > maxBytes) {
throw new Error(`JSON artifact exceeded ${maxBytes} bytes: ${file} (${stat.size} bytes)`);
}
const text = fs.readFileSync(file, "utf8");
const bytes = Buffer.byteLength(text, "utf8");
if (bytes > maxBytes) {
throw new Error(`JSON artifact exceeded ${maxBytes} bytes: ${file} (${bytes} bytes)`);
}
return text;
}
function readPositiveIntEnv(name, fallback) {
const raw = process.env[name];
return raw === undefined || raw === "" ? fallback : parsePositiveInt(raw, name);
}
function boolOutput(value) {