





















@@ -45,13 +45,51 @@ afterEach(() => {
4545});
46464747describe("plugin lifecycle resource sampler", () => {
48+it("rejects loose numeric env values instead of parsing prefixes", () => {
49+const dir = makeTempDir();
50+const summary = path.join(dir, "summary.tsv");
51+const result = spawnSync("node", [scriptPath, summary, "invalid-env", "--", "node", "-e", ""], {
52+cwd: process.cwd(),
53+encoding: "utf8",
54+env: {
55+ ...process.env,
56+OPENCLAW_PLUGIN_LIFECYCLE_PHASE_TIMEOUT_MS: "150ms",
57+},
58+timeout: 5000,
59+});
60+61+expect(result.status).not.toBe(0);
62+expect(result.stderr).toContain(
63+"OPENCLAW_PLUGIN_LIFECYCLE_PHASE_TIMEOUT_MS must be a positive integer; got: 150ms",
64+);
65+});
66+67+it("rejects zero lifecycle timeouts instead of disabling the guard", () => {
68+const dir = makeTempDir();
69+const summary = path.join(dir, "summary.tsv");
70+const result = spawnSync("node", [scriptPath, summary, "invalid-env", "--", "node", "-e", ""], {
71+cwd: process.cwd(),
72+encoding: "utf8",
73+env: {
74+ ...process.env,
75+OPENCLAW_PLUGIN_LIFECYCLE_PHASE_TIMEOUT_MS: "0",
76+},
77+timeout: 5000,
78+});
79+80+expect(result.status).not.toBe(0);
81+expect(result.stderr).toContain(
82+"OPENCLAW_PLUGIN_LIFECYCLE_PHASE_TIMEOUT_MS must be a positive integer; got: 0",
83+);
84+});
85+4886it("configures a phase timeout with process-group cleanup", () => {
4987const script = readFileSync(scriptPath, "utf8");
50885189expect(script).toContain("OPENCLAW_PLUGIN_LIFECYCLE_PHASE_TIMEOUT_MS");
5290expect(script).toContain("OPENCLAW_PLUGIN_LIFECYCLE_TIMEOUT_KILL_GRACE_MS");
5391expect(script).toContain("detached: true");
54-expect(script).toContain('process.kill(-child.pid, signal)');
92+expect(script).toContain("process.kill(-child.pid, signal)");
5593expect(script).toContain('const summarySignal = timedOut ? "timeout"');
5694expect(script).toContain("process.exit(124)");
5795});
@@ -78,7 +116,9 @@ describe("plugin lifecycle resource sampler", () => {
7811679117expect(result.status).toBe(124);
80118expect(result.stdout).toContain("signal=timeout");
81-expect(readFileSync(summary, "utf8")).toMatch(/^wedged\t\d+\t[\d.]+\t\d+\t[\d.]+\ttimeout$/mu);
119+expect(readFileSync(summary, "utf8")).toMatch(
120+/^wedged\t\d+\t[\d.]+\t\d+\t[\d.]+\ttimeout$/mu,
121+);
82122},
83123);
84124此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。