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

推荐订阅源

WordPress大学
WordPress大学
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
腾讯CDC
IT之家
IT之家
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
U
Unit 42
爱范儿
爱范儿
博客园 - 聂微东
F
Fortinet All Blogs
V
Visual Studio Blog
Blog — PlanetScale
Blog — PlanetScale
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
L
LangChain Blog
雷峰网
雷峰网
B
Blog RSS Feed
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Engineering at Meta
Engineering at Meta
H
Hackread – Cybersecurity News, Data Breaches, AI and More

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(crabbox): clean wrapper child trees on parent signal ...
vincentkoc · 2026-06-20 · via Recent Commits to openclaw:main
11

// Crabbox Wrapper tests cover crabbox wrapper script behavior.

2-

import { spawnSync } from "node:child_process";

2+

import { spawn, spawnSync } from "node:child_process";

33

import {

44

chmodSync,

5+

existsSync,

56

mkdirSync,

67

mkdtempSync,

8+

readFileSync,

79

readdirSync,

810

rmSync,

911

statSync,

1012

writeFileSync,

1113

} from "node:fs";

1214

import { tmpdir } from "node:os";

1315

import path from "node:path";

16+

import { setTimeout as delay } from "node:timers/promises";

1417

import { afterAll, beforeAll, describe, expect, it } from "vitest";

15181619

const tempDirs: string[] = [];

@@ -44,6 +47,12 @@ function writeFakeCrabbox(binDir: string, helpText: string): string {

4447

const helperPath = path.join(binDir, "fake-crabbox-json.cjs");

45484649

if (process.platform !== "win32") {

50+

const signalIgnoringDescendantScript = [

51+

"process.on('SIGHUP', () => {});",

52+

"process.on('SIGINT', () => {});",

53+

"process.on('SIGTERM', () => {});",

54+

"setInterval(() => {}, 1000);",

55+

].join("");

4756

const script = [

4857

"#!/bin/sh",

4958

'if [ "$1" = "--version" ]; then',

@@ -116,6 +125,12 @@ function writeFakeCrabbox(binDir: string, helpText: string): string {

116125

" fi",

117126

' cd "$deleted_cwd" || exit 1',

118127

"fi",

128+

'if [ -n "${OPENCLAW_FAKE_CRABBOX_DESCENDANT_PID_PATH:-}" ]; then',

129+

` ${shellSingleQuote(process.execPath)} --input-type=module --eval ${shellSingleQuote(signalIgnoringDescendantScript)} &`,

130+

' printf "%s" "$!" > "$OPENCLAW_FAKE_CRABBOX_DESCENDANT_PID_PATH"',

131+

' trap "exit 0" INT TERM HUP',

132+

" while :; do sleep 1; done",

133+

"fi",

119134

'printf "%s\\0" "__OPENCLAW_FAKE_CRABBOX_V1__"',

120135

'printf "%s\\0" "$PWD"',

121136

'printf "%s\\0" "$#"',

@@ -280,47 +295,57 @@ function shellArgListCondition(args: string[]): string {

280295

return checks.join(" && ");

281296

}

282297283-

function runWrapper(

284-

helpText: string,

285-

args: string[],

286-

options: {

287-

configJson?: Record<string, unknown>;

288-

configStatus?: number;

289-

env?: Record<string, string>;

290-

extraPathEntries?: string[];

291-

gitResponses?: Record<string, { status?: number; stdout?: string; stderr?: string }>;

292-

input?: string;

293-

} = {},

294-

) {

295-

const binDir = makeFakeCrabbox(helpText);

296-

const gitResponses = { ...defaultGitResponses, ...options.gitResponses };

297-

const gitBinDir = makeFakeGit(gitResponses);

298+

function runWrapper(helpText: string, args: string[], options: WrapperOptions = {}) {

298299

return spawnSync(process.execPath, ["scripts/crabbox-wrapper.mjs", ...args], {

299300

cwd: repoRoot,

300301

encoding: "utf8",

301302

input: options.input,

302-

env: {

303-

...process.env,

304-

PATH: [...(options.extraPathEntries ?? []), binDir, gitBinDir, process.env.PATH ?? ""]

305-

.filter(Boolean)

306-

.join(path.delimiter),

307-

CRABBOX_PROVIDER: "",

308-

OPENCLAW_CRABBOX_ALLOW_DIRECT_AWS: "",

309-

OPENCLAW_CRABBOX_SYNC_MIN_FREE_BYTES: "0",

310-

OPENCLAW_CRABBOX_WRAPPER_IGNORE_REPO_BINARY: "1",

311-

...(options.configJson

312-

? { OPENCLAW_FAKE_CRABBOX_CONFIG_JSON: JSON.stringify(options.configJson) }

313-

: {}),

314-

...(options.configStatus

315-

? { OPENCLAW_FAKE_CRABBOX_CONFIG_STATUS: String(options.configStatus) }

316-

: {}),

317-

...options.env,

318-

OPENCLAW_FAKE_GIT_RESPONSES: JSON.stringify(gitResponses),

319-

},

303+

env: wrapperEnv(helpText, options),

320304

timeout: 10_000,

321305

});

322306

}

323307308+

type WrapperOptions = {

309+

configJson?: Record<string, unknown>;

310+

configStatus?: number;

311+

env?: Record<string, string>;

312+

extraPathEntries?: string[];

313+

gitResponses?: Record<string, { status?: number; stdout?: string; stderr?: string }>;

314+

input?: string;

315+

};

316+317+

function spawnWrapper(helpText: string, args: string[], options: WrapperOptions = {}) {

318+

return spawn(process.execPath, ["scripts/crabbox-wrapper.mjs", ...args], {

319+

cwd: repoRoot,

320+

env: wrapperEnv(helpText, options),

321+

stdio: ["ignore", "pipe", "pipe"],

322+

});

323+

}

324+325+

function wrapperEnv(helpText: string, options: WrapperOptions): NodeJS.ProcessEnv {

326+

const binDir = makeFakeCrabbox(helpText);

327+

const gitResponses = { ...defaultGitResponses, ...options.gitResponses };

328+

const gitBinDir = makeFakeGit(gitResponses);

329+

return {

330+

...process.env,

331+

PATH: [...(options.extraPathEntries ?? []), binDir, gitBinDir, process.env.PATH ?? ""]

332+

.filter(Boolean)

333+

.join(path.delimiter),

334+

CRABBOX_PROVIDER: "",

335+

OPENCLAW_CRABBOX_ALLOW_DIRECT_AWS: "",

336+

OPENCLAW_CRABBOX_SYNC_MIN_FREE_BYTES: "0",

337+

OPENCLAW_CRABBOX_WRAPPER_IGNORE_REPO_BINARY: "1",

338+

...(options.configJson

339+

? { OPENCLAW_FAKE_CRABBOX_CONFIG_JSON: JSON.stringify(options.configJson) }

340+

: {}),

341+

...(options.configStatus

342+

? { OPENCLAW_FAKE_CRABBOX_CONFIG_STATUS: String(options.configStatus) }

343+

: {}),

344+

...options.env,

345+

OPENCLAW_FAKE_GIT_RESPONSES: JSON.stringify(gitResponses),

346+

};

347+

}

348+324349

function parseFakeCrabboxOutput(result: ReturnType<typeof runWrapper>): {

325350

args: string[];

326351

cwd: string;

@@ -355,6 +380,76 @@ function normalizeShellLineEndings(value: string): string {

355380

return value.replace(/\r\n/g, "\n");

356381

}

357382383+

async function waitForCondition(predicate: () => boolean, timeoutMs = 8_000): Promise<void> {

384+

const started = Date.now();

385+

while (Date.now() - started < timeoutMs) {

386+

if (predicate()) {

387+

return;

388+

}

389+

await delay(50);

390+

}

391+

throw new Error("timed out waiting for condition");

392+

}

393+394+

async function waitForProcessExit(

395+

child: ReturnType<typeof spawnWrapper>,

396+

timeoutMs = 12_000,

397+

): Promise<{ status: number | null; signal: NodeJS.Signals | null }> {

398+

return await Promise.race([

399+

new Promise<{ status: number | null; signal: NodeJS.Signals | null }>((resolve, reject) => {

400+

child.once("error", reject);

401+

child.once("exit", (status, signal) => resolve({ status, signal }));

402+

}),

403+

delay(timeoutMs).then(() => {

404+

throw new Error("timed out waiting for wrapper process exit");

405+

}),

406+

]);

407+

}

408+409+

function isProcessAlive(pid: number): boolean {

410+

try {

411+

process.kill(pid, 0);

412+

return true;

413+

} catch {

414+

return false;

415+

}

416+

}

417+418+

async function runSignalCleanupProof(sendSignals: (pid: number) => Promise<void>): Promise<void> {

419+

const root = mkdtempSync(path.join(tmpdir(), "openclaw-crabbox-descendant-"));

420+

tempDirs.push(root);

421+

const descendantPidPath = path.join(root, "descendant.pid");

422+

let descendantPid = 0;

423+

const runner = spawnWrapper(

424+

"provider: hetzner, aws, local-container, blacksmith-testbox, or cloudflare\n",

425+

["run", "--provider", "aws", "--", "echo ok"],

426+

{

427+

env: {

428+

OPENCLAW_FAKE_CRABBOX_DESCENDANT_PID_PATH: descendantPidPath,

429+

},

430+

},

431+

);

432+433+

try {

434+

await waitForCondition(() => existsSync(descendantPidPath));

435+

descendantPid = Number.parseInt(readFileSync(descendantPidPath, "utf8"), 10);

436+

expect(Number.isInteger(descendantPid)).toBe(true);

437+

expect(isProcessAlive(descendantPid)).toBe(true);

438+439+

const runnerExit = waitForProcessExit(runner);

440+

await sendSignals(runner.pid!);

441+

await expect(runnerExit).resolves.toEqual({ status: 143, signal: null });

442+

await waitForCondition(() => !isProcessAlive(descendantPid));

443+

} finally {

444+

if (runner.pid && isProcessAlive(runner.pid)) {

445+

runner.kill("SIGKILL");

446+

}

447+

if (descendantPid && isProcessAlive(descendantPid)) {

448+

process.kill(descendantPid, "SIGKILL");

449+

}

450+

}

451+

}

452+358453

function testCrabboxConfigDir(home: string): string {

359454

if (process.platform === "darwin") {

360455

return path.join(home, "Library", "Application Support", "crabbox");

@@ -3041,6 +3136,26 @@ describe.concurrent("scripts/crabbox-wrapper", () => {

30413136

}

30423137

});

304331383139+

(process.platform === "win32" ? it.skip : it)(

3140+

"terminates Crabbox descendants before parent signal exit",

3141+

async () => {

3142+

await runSignalCleanupProof(async (runnerPid) => {

3143+

process.kill(runnerPid, "SIGTERM");

3144+

});

3145+

},

3146+

);

3147+3148+

(process.platform === "win32" ? it.skip : it)(

3149+

"keeps cleanup active after repeated parent signals",

3150+

async () => {

3151+

await runSignalCleanupProof(async (runnerPid) => {

3152+

process.kill(runnerPid, "SIGTERM");

3153+

await delay(50);

3154+

process.kill(runnerPid, "SIGTERM");

3155+

});

3156+

},

3157+

);

3158+30443159

(process.platform === "win32" ? it.skip : it)(

30453160

"terminates when sparse-sync temporary full checkouts disappear while Crabbox is running",

30463161

() => {