Files
openclaw/scripts/lib/docker-e2e-json-artifacts.mts
T
Peter Steinberger c70aee247e refactor(scripts): migrate JavaScript tools to TypeScript (#121005)
* refactor(scripts): migrate JavaScript tools to TypeScript

* fix(ci): keep changed-scope preflight zero-install

* fix(ci): preserve zero-install script owners

* fix(ci): complete script migration follow-through

* fix(release): keep stable closeout zero-install

* fix(scripts): preserve standalone execution boundaries

* fix(scripts): repair standalone loader boundaries

* fix(scripts): normalize gateway observation ids

* fix(scripts): keep Docker packager standalone

* test(scripts): preserve rebase cleanup helpers

* test(sessions): use tracked temp directory
2026-08-09 07:21:35 -07:00

32 lines
1.2 KiB
TypeScript

import fs from "node:fs";
import { parsePositiveInt } from "./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;
export function readDockerE2eJsonArtifact(file: string): unknown {
return JSON.parse(readDockerE2eJsonArtifactText(file));
}
function readDockerE2eJsonArtifactText(file: string): string {
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: string, fallback: number): number {
const raw = process.env[name];
return raw === undefined || raw === "" ? fallback : parsePositiveInt(raw, name);
}