test(plugins): harness-watch-w2 re-check P3-3: the claude capture's stop test now has a background child that keeps the stdout pipe open, so it fails when a stop kills only the parent, and a new test does the same for pi's version capture on a stop (#1873, lane harness-watch-w2)
This commit is contained in:
1 parent
f2463ab36d
commit
a4d06b95c6
1 file changed
+18
-3
@@ -15,7 +15,7 @@ import { piStandIn } from "../../harness/tests/pi-stand-in.mjs";
|
||||
import { piFit } from "../../harness/src/pi-fit.mjs";
|
||||
import { sandboxProblem, UNSHARE } from "../../seat/src/sandbox.mjs";
|
||||
import * as pi from "../harness/pi/index.mjs";
|
||||
import { locate } from "../harness/pi/binary.mjs";
|
||||
import { locate, printedVersion } from "../harness/pi/binary.mjs";
|
||||
import * as claude from "../harness/claude-code/index.mjs";
|
||||
|
||||
const REPO = resolve(fileURLToPath(new URL("../../../", import.meta.url)));
|
||||
@@ -336,12 +336,12 @@ test("W2 claude-code: a capture stops what the binary left in the background, on
|
||||
writeFileSync(bin, [
|
||||
"#!/bin/sh", 'case "$1" in',
|
||||
`--version) sleep 30 >/dev/null 2>&1 & echo $! > '${left}'; echo '9.9.9';;`,
|
||||
`--help) sleep 30 >/dev/null 2>&1 & echo $! > '${held}'; wait;;`,
|
||||
`--help) sleep 30 2>/dev/null & echo $! > '${held}' 2>/dev/null; wait;;`,
|
||||
"*) exit 3;;", "esac", "",
|
||||
].join("\n"), { mode: 0o755 });
|
||||
const stop = new AbortController();
|
||||
const r = claude.inspect({ env: { MOSAIC_CLAUDE_BIN: bin }, scratch: scratch(t), signal: stop.signal });
|
||||
assert.ok(await until(() => existsSync(held)), "--help started");
|
||||
assert.ok(await until(() => existsSync(held) && readFileSync(held, "utf8").trim() !== ""), "--help started");
|
||||
stop.abort();
|
||||
const out = await r;
|
||||
assert.match(out.line, /--help was stopped/);
|
||||
@@ -349,6 +349,21 @@ test("W2 claude-code: a capture stops what the binary left in the background, on
|
||||
for (const pid of pids) assert.ok(await until(() => !alive(pid)), `process ${pid} left by a capture is gone`);
|
||||
});
|
||||
|
||||
// Re-check P3-3: pi's version capture kills its group on a stop too. The background child keeps
|
||||
// the stdout pipe open, so killing the parent alone would leave it running.
|
||||
test("W2 pi: a stopped version capture stops what the binary left in the background", async (t) => {
|
||||
const dir = scratch(t);
|
||||
const bin = join(dir, "pi"), held = join(dir, "held");
|
||||
writeFileSync(bin, `#!/bin/sh\nsleep 30 2>/dev/null & echo $! > '${held}' 2>/dev/null\nwait\n`, { mode: 0o755 });
|
||||
const stop = new AbortController();
|
||||
const r = printedVersion(bin, { signal: stop.signal });
|
||||
assert.ok(await until(() => existsSync(held) && readFileSync(held, "utf8").trim() !== ""), "--version started");
|
||||
stop.abort();
|
||||
assert.equal(await r, null);
|
||||
const pid = Number(readFileSync(held, "utf8").trim());
|
||||
assert.ok(await until(() => !alive(pid)), `process ${pid} left by the capture is gone`);
|
||||
});
|
||||
|
||||
// Review P3-6: an already aborted signal starts nothing and decides nothing.
|
||||
test("W2 claude-code: an inspect with an already aborted signal runs nothing and is unknown", async (t) => {
|
||||
const dir = scratch(t);
|
||||
|
||||
Reference in new issue
Block a user