fix(docker): bound package capture output

This commit is contained in:
Vincent Koc
2026-05-28 14:01:02 +02:00
parent da551463e3
commit cee364e2f6
2 changed files with 93 additions and 6 deletions

View File

@@ -155,6 +155,62 @@ describe("package-openclaw-for-docker", () => {
}
});
it("keeps fallback SIGKILL armed for descendants after the direct child exits", async () => {
if (process.platform === "win32") {
return;
}
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-package-descendant-"));
const childPidPath = path.join(tempDir, "child.pid");
let childPid = 0;
try {
const childScript = ["process.on('SIGTERM', () => {});", "setInterval(() => {}, 1000);"].join(
"",
);
const parentScript = [
"const { spawn } = require('node:child_process');",
"const fs = require('node:fs');",
`const child = spawn(process.execPath, ['-e', ${JSON.stringify(childScript)}], { stdio: 'ignore' });`,
"fs.writeFileSync(process.env.OPENCLAW_TEST_CHILD_PID, String(child.pid));",
"setInterval(() => {}, 1000);",
].join("");
await expect(
runCommandForTest(process.execPath, ["-e", parentScript], process.cwd(), {
env: { ...process.env, OPENCLAW_TEST_CHILD_PID: childPidPath },
killAfterMs: 50,
timeoutMs: 2000,
}),
).rejects.toThrow(/timed out after 2000ms/u);
await waitForFile(childPidPath, 2000);
childPid = Number(fs.readFileSync(childPidPath, "utf8"));
await waitForDead(childPid, 2000);
} finally {
if (childPid && isProcessAlive(childPid)) {
process.kill(childPid, "SIGKILL");
}
fs.rmSync(tempDir, { force: true, recursive: true });
}
});
it("fails captured commands that exceed the stdout limit", async () => {
const script = [
"process.stdout.write('x'.repeat(2048));",
"process.on('SIGTERM', () => {});",
"setInterval(() => {}, 1000);",
].join("");
await expect(
runCommandForTest(process.execPath, ["-e", script], process.cwd(), {
captureStdout: true,
killAfterMs: 50,
maxCapturedStdoutBytes: 1024,
timeoutMs: 5000,
}),
).rejects.toThrow(/exceeded captured stdout limit \(1024 bytes\)/u);
});
it("forwards external termination to active child process groups", async () => {
if (process.platform === "win32") {
return;