惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
Martin Fowler
Martin Fowler
B
Blog RSS Feed
D
DataBreaches.Net
L
LangChain Blog
月光博客
月光博客
S
SegmentFault 最新的问题
阮一峰的网络日志
阮一峰的网络日志
V
Visual Studio Blog
美团技术团队
Jina AI
Jina AI
博客园 - 司徒正美
雷峰网
雷峰网
Last Week in AI
Last Week in AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
IT之家
IT之家
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
小众软件
小众软件
罗磊的独立博客
博客园_首页
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(test): preserve lifecycle probe timeout failures · op...
vincentkoc · 2026-06-20 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -16,6 +16,8 @@ type MatrixEnv = NodeJS.ProcessEnv & ProbeEnv;

1616

interface CommandOptions {

1717

env?: NodeJS.ProcessEnv;

1818

outputFile?: string;

19+

spawnImpl?: typeof spawn;

20+

timeoutKillGraceMs?: number;

1921

timeoutMs?: number;

2022

}

2123

@@ -231,37 +233,56 @@ async function runCommand(command: string, args: readonly string[], options: Com

231233

options.outputFile === undefined ? undefined : fs.openSync(options.outputFile, "a");

232234

try {

233235

await new Promise<void>((resolve, reject) => {

234-

const child = spawn(command, args, {

236+

const spawnImpl = options.spawnImpl ?? spawn;

237+

const child = spawnImpl(command, args, {

235238

cwd: process.cwd(),

236239

env: options.env ?? process.env,

237240

stdio: outputFd === undefined ? "inherit" : (["ignore", outputFd, outputFd] as const),

238241

});

239242

let settled = false;

240-

const timer =

243+

let forceKillTimer: NodeJS.Timeout | undefined;

244+

let timeoutTimer: NodeJS.Timeout | undefined;

245+

let timeoutError: Error | undefined;

246+

const clearTimers = () => {

247+

if (timeoutTimer) {

248+

clearTimeout(timeoutTimer);

249+

}

250+

if (forceKillTimer) {

251+

clearTimeout(forceKillTimer);

252+

}

253+

};

254+

timeoutTimer =

241255

options.timeoutMs === undefined

242256

? undefined

243257

: setTimeout(() => {

258+

timeoutError = new Error(

259+

`${command} ${args.join(" ")} timed out after ${options.timeoutMs}ms`,

260+

);

244261

child.kill("SIGTERM");

245-

setTimeout(() => child.kill("SIGKILL"), 2_000).unref();

262+

forceKillTimer = setTimeout(

263+

() => child.kill("SIGKILL"),

264+

options.timeoutKillGraceMs ?? 2_000,

265+

);

266+

forceKillTimer.unref();

246267

}, options.timeoutMs);

247-

timer?.unref();

268+

timeoutTimer?.unref();

248269

child.once("error", (error) => {

249270

if (settled) {

250271

return;

251272

}

252273

settled = true;

253-

if (timer) {

254-

clearTimeout(timer);

255-

}

274+

clearTimers();

256275

reject(error);

257276

});

258277

child.once("exit", (code, signal) => {

259278

if (settled) {

260279

return;

261280

}

262281

settled = true;

263-

if (timer) {

264-

clearTimeout(timer);

282+

clearTimers();

283+

if (timeoutError) {

284+

reject(timeoutError);

285+

return;

265286

}

266287

if (code === 0 && !signal) {

267288

resolve();

@@ -532,6 +553,8 @@ export async function runPluginLifecycleMatrix() {

532553

}

533554

}

534555
556+

export const testing = { runCommand };

557+
535558

const isLifecycleMatrixCli = process.argv[2] === "--lifecycle-matrix";

536559
537560

if (isLifecycleMatrixCli) {

Original file line numberDiff line numberDiff line change

@@ -1,12 +1,14 @@

11

// Plugin Lifecycle Probe tests cover QA Lab plugin lifecycle evidence.

2+

import { EventEmitter } from "node:events";

23

import { mkdirSync, writeFileSync } from "node:fs";

34

import path from "node:path";

4-

import { afterEach, describe, expect, it } from "vitest";

5+

import { afterEach, describe, expect, it, vi } from "vitest";

56

import { createTempDirTracker } from "../../../helpers/temp-dir.js";

67

import {

78

assertInspectLoaded,

89

assertUninstalled,

910

parseDurationMs,

11+

testing as probeTesting,

1012

} from "./plugin-lifecycle-probe-runtime.js";

1113
1214

const tempDirs = createTempDirTracker();

@@ -15,6 +17,18 @@ function makeTempDir(): string {

1517

return tempDirs.make("openclaw-plugin-lifecycle-probe-");

1618

}

1719
20+

class FakeCommandChild extends EventEmitter {

21+

readonly signals: string[] = [];

22+
23+

kill(signal?: NodeJS.Signals | number): boolean {

24+

this.signals.push(String(signal));

25+

if (signal === "SIGTERM") {

26+

queueMicrotask(() => this.emit("exit", 0, null));

27+

}

28+

return true;

29+

}

30+

}

31+
1832

afterEach(tempDirs.cleanup);

1933
2034

describe("plugin lifecycle matrix probe", () => {

@@ -70,4 +84,29 @@ describe("plugin lifecycle matrix probe", () => {

7084

it("preserves disabled npm install timeout semantics", () => {

7185

expect(parseDurationMs("0", "600s")).toBeUndefined();

7286

});

87+
88+

it("rejects timed commands that exit cleanly during kill grace", async () => {

89+

vi.useFakeTimers();

90+

try {

91+

const child = new FakeCommandChild();

92+

const runPromise = probeTesting.runCommand("fake-command", ["install"], {

93+

spawnImpl: (() => child) as unknown as typeof import("node:child_process").spawn,

94+

timeoutKillGraceMs: 100,

95+

timeoutMs: 10,

96+

});

97+

const runError = runPromise.catch((error: unknown) => error);

98+
99+

await vi.advanceTimersByTimeAsync(10);

100+
101+

const error = await runError;

102+

expect(error).toBeInstanceOf(Error);

103+

expect((error as Error).message).toBe("fake-command install timed out after 10ms");

104+

expect(child.signals).toEqual(["SIGTERM"]);

105+
106+

await vi.advanceTimersByTimeAsync(100);

107+

expect(child.signals).toEqual(["SIGTERM"]);

108+

} finally {

109+

vi.useRealTimers();

110+

}

111+

});

73112

});