mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-09 15:59:30 +00:00
fix(scripts): clamp run-with-env kill timer
This commit is contained in:
parent
29eba5aaef
commit
095a44c8de
2 changed files with 12 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ import { resolveWindowsTaskkillPath } from "./lib/windows-taskkill.mjs";
|
||||||
|
|
||||||
const ENV_ASSIGNMENT_RE = /^[A-Za-z_][A-Za-z0-9_]*=/u;
|
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 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.
|
* Detects help requests before the command separator.
|
||||||
|
|
@ -78,7 +79,7 @@ export function resolveForceKillDelayMs(env = process.env) {
|
||||||
if (!Number.isSafeInteger(parsed) || parsed < 1) {
|
if (!Number.isSafeInteger(parsed) || parsed < 1) {
|
||||||
throw new Error("OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS must be a positive integer");
|
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 { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
import { MAX_TIMER_TIMEOUT_MS } from "@openclaw/normalization-core/number-coercion";
|
||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
import {
|
import {
|
||||||
isRunWithEnvHelpRequest,
|
isRunWithEnvHelpRequest,
|
||||||
|
|
@ -152,6 +153,11 @@ describe("run-with-env", () => {
|
||||||
it("rejects malformed force-kill grace configuration before spawning", () => {
|
it("rejects malformed force-kill grace configuration before spawning", () => {
|
||||||
expect(resolveForceKillDelayMs({})).toBe(5_000);
|
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: "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"]) {
|
for (const value of ["0", "-1", "1e3", "100ms"]) {
|
||||||
expect(() => resolveForceKillDelayMs({ OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS: value })).toThrow(
|
expect(() => resolveForceKillDelayMs({ OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS: value })).toThrow(
|
||||||
"OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS must be a positive integer",
|
"OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS must be a positive integer",
|
||||||
|
|
@ -393,7 +399,10 @@ describe("run-with-env", () => {
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
cwd: process.cwd(),
|
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",
|
stdio: "ignore",
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue