fix(scripts): clamp run-with-env kill timer

This commit is contained in:
Vincent Koc
2026-06-22 03:15:26 +02:00
parent 29eba5aaef
commit 095a44c8de
2 changed files with 12 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ import { resolveWindowsTaskkillPath } from "./lib/windows-taskkill.mjs";
const ENV_ASSIGNMENT_RE = /^[A-Za-z_][A-Za-z0-9_]*=/u;
const USAGE = "Usage: node scripts/run-with-env.mjs KEY=value [KEY=value ...] -- command [args...]";
const MAX_TIMER_TIMEOUT_MS = 2_147_000_000;
/**
* Detects help requests before the command separator.
@@ -78,7 +79,7 @@ export function resolveForceKillDelayMs(env = process.env) {
if (!Number.isSafeInteger(parsed) || parsed < 1) {
throw new Error("OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS must be a positive integer");
}
return parsed;
return Math.min(parsed, MAX_TIMER_TIMEOUT_MS);
}
/**

View File

@@ -3,6 +3,7 @@ import { spawn, spawnSync, type ChildProcess } from "node:child_process";
import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { MAX_TIMER_TIMEOUT_MS } from "@openclaw/normalization-core/number-coercion";
import { describe, expect, it, vi } from "vitest";
import {
isRunWithEnvHelpRequest,
@@ -152,6 +153,11 @@ describe("run-with-env", () => {
it("rejects malformed force-kill grace configuration before spawning", () => {
expect(resolveForceKillDelayMs({})).toBe(5_000);
expect(resolveForceKillDelayMs({ OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS: "250" })).toBe(250);
expect(
resolveForceKillDelayMs({
OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS: String(MAX_TIMER_TIMEOUT_MS + 1),
}),
).toBe(MAX_TIMER_TIMEOUT_MS);
for (const value of ["0", "-1", "1e3", "100ms"]) {
expect(() => resolveForceKillDelayMs({ OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS: value })).toThrow(
"OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS must be a positive integer",
@@ -393,7 +399,10 @@ describe("run-with-env", () => {
],
{
cwd: process.cwd(),
env: { ...process.env, OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS: "1000" },
env: {
...process.env,
OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS: String(MAX_TIMER_TIMEOUT_MS + 1),
},
stdio: "ignore",
},
);