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

推荐订阅源

L
LangChain Blog
有赞技术团队
有赞技术团队
博客园_首页
IT之家
IT之家
爱范儿
爱范儿
量子位
小众软件
小众软件
Jina AI
Jina AI
WordPress大学
WordPress大学
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 聂微东
The Cloudflare Blog
博客园 - 司徒正美
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
大猫的无限游戏
大猫的无限游戏
月光博客
月光博客
雷峰网
雷峰网
V
Visual Studio Blog
博客园 - Franky
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
Last Week in AI
Last Week in AI
S
SegmentFault 最新的问题

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

@@ -4,6 +4,7 @@ import { EventEmitter } from "node:events";

44

import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";

55

import os from "node:os";

66

import path from "node:path";

7+

import { pathToFileURL } from "node:url";

78

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

89

import {

910

checkUnusedFiles,

@@ -65,6 +66,21 @@ async function waitForDead(pid: number, timeoutMs: number): Promise<void> {

6566

throw new Error(`process still alive: ${pid}`);

6667

}

676869+

function waitForChildClose(

70+

child: ReturnType<typeof spawn>,

71+

timeoutMs = 5_000,

72+

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

73+

return new Promise((resolve, reject) => {

74+

const timeout = setTimeout(() => {

75+

reject(new Error("child did not close before timeout"));

76+

}, timeoutMs);

77+

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

78+

clearTimeout(timeout);

79+

resolve({ code, signal });

80+

});

81+

});

82+

}

83+6884

describe("check-deadcode-unused-files", () => {

6985

it("parses the compact Knip unused-file section", () => {

7086

expect(

@@ -366,6 +382,71 @@ src/a.ts: src/a.ts

366382

},

367383

);

368384385+

it.skipIf(process.platform === "win32")(

386+

"cleans active Knip descendants before forwarding parent SIGTERM",

387+

async () => {

388+

const root = mkdtempSync(path.join(os.tmpdir(), "openclaw-knip-parent-signal-"));

389+

const childPidPath = path.join(root, "child.pid");

390+

const readyPath = path.join(root, "child.ready");

391+

const scriptUrl = pathToFileURL(path.resolve("scripts/check-deadcode-unused-files.mjs")).href;

392+

let childPid = 0;

393+

let runner: ReturnType<typeof spawn> | undefined;

394+395+

try {

396+

const childScript = [

397+

"const fs = require('node:fs');",

398+

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

399+

`fs.writeFileSync(${JSON.stringify(childPidPath)}, String(process.pid));`,

400+

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

401+

].join("");

402+

const parentScript = [

403+

"const { spawn } = require('node:child_process');",

404+

`spawn(process.execPath, ['-e', ${JSON.stringify(childScript)}], { stdio: 'ignore' });`,

405+

`require('node:fs').writeFileSync(${JSON.stringify(readyPath)}, 'ready');`,

406+

"process.on('SIGTERM', () => process.exit(0));",

407+

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

408+

].join("");

409+

const runnerScript = [

410+

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

411+

`import { runKnipUnusedFiles } from ${JSON.stringify(scriptUrl)};`,

412+

"await runKnipUnusedFiles({",

413+

" spawnCommand(_command, _args, options) {",

414+

` return spawn(process.execPath, ['-e', ${JSON.stringify(parentScript)}], options);`,

415+

" },",

416+

" timeoutMs: 60_000,",

417+

" writeStatus: () => {},",

418+

"});",

419+

].join("\n");

420+421+

runner = spawn(process.execPath, ["--input-type=module", "-e", runnerScript], {

422+

cwd: process.cwd(),

423+

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

424+

});

425+426+

await waitForFile(readyPath, 2_000);

427+

await waitForFile(childPidPath, 2_000);

428+

childPid = Number.parseInt(readFileSync(childPidPath, "utf8"), 10);

429+

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

430+431+

runner.kill("SIGTERM");

432+433+

await expect(waitForChildClose(runner)).resolves.toEqual({

434+

code: null,

435+

signal: "SIGTERM",

436+

});

437+

await waitForDead(childPid, 2_000);

438+

} finally {

439+

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

440+

runner.kill("SIGKILL");

441+

}

442+

if (childPid && isProcessAlive(childPid)) {

443+

process.kill(childPid, "SIGKILL");

444+

}

445+

rmSync(root, { recursive: true, force: true });

446+

}

447+

},

448+

);

449+369450

it("keeps output delivered after process exit but before stdio close", async () => {

370451

const child = new FakeKnipProcess();

371452

const resultPromise = runKnipUnusedFiles({