fix(release): reject loose Docker package timeouts

This commit is contained in:
Vincent Koc
2026-06-17 02:05:43 +02:00
parent f684527085
commit f3f8ca3d92
2 changed files with 29 additions and 3 deletions

View File

@@ -53,11 +53,14 @@ function resolveTimeoutMs(envName, defaultValue) {
if (raw === undefined || raw === "") {
return defaultValue;
}
const parsed = Number(raw);
if (!Number.isFinite(parsed) || parsed <= 0) {
if (!/^[0-9]+$/u.test(raw)) {
throw new Error(`${envName} must be a positive timeout in milliseconds`);
}
return Math.trunc(parsed);
const parsed = Number(raw);
if (!Number.isSafeInteger(parsed) || parsed <= 0) {
throw new Error(`${envName} must be a positive timeout in milliseconds`);
}
return parsed;
}
function readOptionValue(argv, index, optionName) {

View File

@@ -146,6 +146,29 @@ describe("package-openclaw-for-docker", () => {
]);
});
it("rejects loose package artifact timeout env values", async () => {
const previousTimeout = process.env.OPENCLAW_DOCKER_PACKAGE_BUILD_TIMEOUT_MS;
try {
for (const value of ["1e3", "123.9", "9007199254740993", "0"]) {
process.env.OPENCLAW_DOCKER_PACKAGE_BUILD_TIMEOUT_MS = value;
await expect(
buildPackageArtifacts("/repo", {
runImpl: async () => undefined,
}),
).rejects.toThrow(
"OPENCLAW_DOCKER_PACKAGE_BUILD_TIMEOUT_MS must be a positive timeout in milliseconds",
);
}
} finally {
if (previousTimeout === undefined) {
delete process.env.OPENCLAW_DOCKER_PACKAGE_BUILD_TIMEOUT_MS;
} else {
process.env.OPENCLAW_DOCKER_PACKAGE_BUILD_TIMEOUT_MS = previousTimeout;
}
}
});
it("trims and restores the changelog around ignore-scripts package artifacts", async () => {
const calls: string[] = [];
const tarball = await packOpenClawPackageForDocker("/repo", "/out", {