





























@@ -15,9 +15,6 @@ import { afterEach, describe, expect, it } from "vitest";
15151616const tempDirs: string[] = [];
1717const scriptPath = "scripts/e2e/lib/plugin-lifecycle-matrix/measure.mjs";
18-const hasTimeoutCommand =
19-process.platform === "linux" &&
20-spawnSync("bash", ["-lc", "command -v timeout >/dev/null 2>&1"]).status === 0;
21182219function makeTempDir(): string {
2320const dir = mkdtempSync(path.join(tmpdir(), "openclaw-plugin-lifecycle-measure-"));
@@ -317,8 +314,8 @@ describe("plugin lifecycle resource sampler", () => {
317314encoding: "utf8",
318315env: {
319316 ...process.env,
320-OPENCLAW_PLUGIN_LIFECYCLE_PHASE_TIMEOUT_MS: "150",
321-OPENCLAW_PLUGIN_LIFECYCLE_TIMEOUT_KILL_GRACE_MS: "100",
317+OPENCLAW_PLUGIN_LIFECYCLE_PHASE_TIMEOUT_MS: "1000",
318+OPENCLAW_PLUGIN_LIFECYCLE_TIMEOUT_KILL_GRACE_MS: "200",
322319PID_FILE: pidFile,
323320},
324321timeout: 5000,
@@ -340,49 +337,51 @@ describe("plugin lifecycle resource sampler", () => {
340337},
341338);
342339343-it.runIf(hasTimeoutCommand)("forwards external termination to the measured process group", () => {
344-const dir = makeTempDir();
345-const summary = path.join(dir, "summary.tsv");
346-const pidFile = path.join(dir, "descendant.pid");
347-let descendantPid;
340+it.runIf(process.platform === "linux")(
341+"forwards external termination to the measured process group",
342+async () => {
343+const dir = makeTempDir();
344+const summary = path.join(dir, "summary.tsv");
345+const pidFile = path.join(dir, "descendant.pid");
346+let descendantPid;
348347349-try {
350-const result = spawnSync(
351-"timeout",
352-[
353-"--kill-after=1s",
354-"0.2s",
355-"node",
356-scriptPath,
357-summary,
358-"external-stop",
359-"--",
360-"bash",
361-"-lc",
362-'bash -c \'trap "" TERM; printf "%s\\n" "$$" >"$PID_FILE"; while :; do sleep 1; done\' & wait',
363-],
364-{
365-cwd: process.cwd(),
366-encoding: "utf8",
367-env: {
368- ...process.env,
369-OPENCLAW_PLUGIN_LIFECYCLE_PHASE_TIMEOUT_MS: "5000",
370-OPENCLAW_PLUGIN_LIFECYCLE_TIMEOUT_KILL_GRACE_MS: "100",
371-PID_FILE: pidFile,
348+try {
349+const result = spawn(
350+process.execPath,
351+[
352+scriptPath,
353+summary,
354+"external-stop",
355+"--",
356+"bash",
357+"-lc",
358+'bash -c \'trap "" TERM; printf "%s\\n" "$$" >"$PID_FILE"; while :; do sleep 1; done\' & wait',
359+],
360+{
361+cwd: process.cwd(),
362+env: {
363+ ...process.env,
364+OPENCLAW_PLUGIN_LIFECYCLE_PHASE_TIMEOUT_MS: "5000",
365+OPENCLAW_PLUGIN_LIFECYCLE_TIMEOUT_KILL_GRACE_MS: "200",
366+PID_FILE: pidFile,
367+},
368+stdio: "ignore",
372369},
373-timeout: 5000,
374-},
375-);
370+);
376371377-descendantPid = Number.parseInt(readFileSync(pidFile, "utf8"), 10);
378-expect(result.status).toBe(124);
379-expect(waitForPidExit(descendantPid, 1000)).toBe(true);
380-} finally {
381-if (descendantPid > 0 && pidExists(descendantPid)) {
382-process.kill(descendantPid, "SIGKILL");
372+expect(waitForPath(pidFile, 2000)).toBe(true);
373+descendantPid = Number.parseInt(readFileSync(pidFile, "utf8"), 10);
374+result.kill("SIGTERM");
375+const close = await waitForChildClose(result, 5000);
376+expect(close.signal).toBe("SIGTERM");
377+expect(waitForPidExit(descendantPid, 1000)).toBe(true);
378+} finally {
379+if (descendantPid > 0 && pidExists(descendantPid)) {
380+process.kill(descendantPid, "SIGKILL");
381+}
383382}
384-}
385-});
383+},
384+);
386385387386it.runIf(process.platform === "linux")(
388387"exits promptly when externally terminated phases stop during grace",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。