Skip to content

Commit c41fd5c

Browse files
wahaha1223steipete
authored andcommitted
fix(cli): force-stop stalled root-help renderers
1 parent ea6ed38 commit c41fd5c

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎scripts/write-cli-startup-metadata.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ function renderSourceRootHelpText(
626626
cwd: rootDir,
627627
encoding: "utf8",
628628
env: renderContext.env,
629+
killSignal: "SIGKILL",
629630
timeout: ROOT_HELP_RENDER_TIMEOUT_MS,
630631
},
631632
);
@@ -879,6 +880,7 @@ function hasAllPrecomputedSubcommandHelpText(value: unknown): boolean {
879880
}
880881

881882
export const testing = {
883+
renderSourceRootHelpText,
882884
signalCliStartupMetadataProcessTree,
883885
spawnText,
884886
};

‎test/scripts/write-cli-startup-metadata.test.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Write Cli Startup Metadata tests cover write cli startup metadata script behavior.
2-
import { spawn } from "node:child_process";
2+
import { spawn, spawnSync } from "node:child_process";
33
import { EventEmitter } from "node:events";
44
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
55
import path from "node:path";
@@ -10,6 +10,11 @@ import { resolveWindowsTaskkillPath } from "../../scripts/lib/windows-taskkill.m
1010
import { __testing, writeCliStartupMetadata } from "../../scripts/write-cli-startup-metadata.ts";
1111
import { createScriptTestHarness } from "./test-helpers.js";
1212

13+
vi.mock("node:child_process", async (importOriginal) => {
14+
const actual = await importOriginal<typeof import("node:child_process")>();
15+
return { ...actual, spawnSync: vi.fn(actual.spawnSync) };
16+
});
17+
1318
// These subprocess tests use explicit ready/close signals; timeout only catches broken fixtures.
1419
const LOAD_SENSITIVE_PROCESS_TIMEOUT_MS = process.env.CI ? 30_000 : 15_000;
1520

@@ -114,6 +119,28 @@ async function waitForChildClose(
114119
describe("write-cli-startup-metadata", () => {
115120
const { createTempDir } = createScriptTestHarness();
116121

122+
it("hard-kills synchronous source root help after its timeout", () => {
123+
const spawnSyncMock = vi.mocked(spawnSync);
124+
const successfulRender = {
125+
error: undefined,
126+
output: [null, "Usage: openclaw\n", ""],
127+
pid: 123,
128+
signal: null,
129+
status: 0,
130+
stderr: "",
131+
stdout: "Usage: openclaw\n",
132+
};
133+
spawnSyncMock.mockReturnValueOnce(successfulRender);
134+
135+
expect(__testing.renderSourceRootHelpText()).toBe("Usage: openclaw\n");
136+
137+
expect(spawnSyncMock).toHaveBeenCalledOnce();
138+
expect(spawnSyncMock.mock.calls[0]?.[2]).toMatchObject({
139+
killSignal: "SIGKILL",
140+
timeout: 120_000,
141+
});
142+
});
143+
117144
it("fails command help rendering when captured output exceeds the byte limit", async () => {
118145
await expect(
119146
__testing.spawnText(["--eval", "process.stdout.write('x'.repeat(2048))"], {

0 commit comments

Comments
 (0)