mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-24 10:58:37 +00:00
fix(scripts): clamp run-with-env kill timer
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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",
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user