ā test(kavach): run-child's pipe test waits for the descendant, not 0.5 s
packages/kavach/corpus/run-child.test.ts, "cuts the pipes a descendant outside the group holds open", now waits for the descendant on an observed event instead of a fixed 0.5 s. A local root pnpm check passes all the way on this Mac. The failure was reported in #147.
Cause
The child ran python3 ⦠& sleep 0.5; echo started. Python had to call setsid() and print "left" within that 0.5 s. On this Mac, python3 is the pyenv shim, and it takes 460 to 1100 ms to start. So the shell printed "started" and exited first, and runChild's group kill took python while it was still in the group. stdout was 'started\n' on every run.
This is not about macOS process-group or pipe semantics:
- With
/usr/binfirst onPATH, the same command gives'left\nstarted\n'. - CI's ubuntu runner starts python quickly, and the test passes there (1.5 s on main).
Change
The test file is the only change; run-child.ts is untouched.
- Once python has left the group, it writes its pid to a file: it writes a temp file, then renames it. The shell polls for that file before
echo started. A 20 stimeoutMsis a hang guard only. - The old
took < 2900bound counted python's start-up, so a 1.5 s start would still have broken it. It is replaced by the property itself: the holder is still alive when the outcome returns, so the pipes were cut. The holder is SIGKILLed int.after. - The drain's lower bound is now timed from the record's mtime, not from the spawn, so start-up time cannot stand in for the drain.
Checked
- The test file passes alone, with the pyenv shim first on
PATH. - It passes with a
PATHshim that sleeps 1.5 s before exec-ing the realpython3, asdocs/lessons/testing.mdprescribes. The old test fails with plain pyenv. - With the drain's
destroy()calls inrun-child.tsdisabled, the new test fails: the holder had exited, sokillreturned ESRCH. - The root
pnpm checkexits 0 on this Mac. kavach passed 759 tests, sarathi 305, pariksha 3527, dvara 328, shuddhi 2804 and agnipariksha 91. That run used the first commit. The second commit changes only assertion order and the drain's anchor, and that file was re-run alone and under the shim.
Slice: #149
š¤ Generated with Claude Code
Summary by cubic
Fixes the flaky run-child pipe test so it passes on Macs where python3 is a pyenv shim that takes up to 1.1 s to start.
The test previously waited a fixed 0.5 s for the descendant to leave the process group; slow python startup meant the shell exited first and the group kill hit python while still in the group. Now the descendant writes its pid to a temp file (renamed once it has left the group), and the shell polls for that file before exiting. A 20 s timeoutMs is only a hang guard.
- Replaces the old
took < 2900bound with the property itself: the holder is still alive when the outcome returns, so the pipes were cut; the holder is SIGKILLed int.after. - Times the drain's lower bound from the record's mtime, so python's start-up can't count as the drain.
- Only
packages/kavach/corpus/run-child.test.tschanges;run-child.tsis untouched.