mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-03 04:36:21 +00:00
fix(docker): bound package capture output
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user