You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test: probe for a free pid instead of assuming 4242 is dead
Nine sites across three suites stood in for an exited process with a
hardcoded pid:
const deadPid = process.pid === 4242 ? 4243 : 4242;
The code under test asks the kernel whether that owner is still alive, so
the pid is only dead until an unrelated process happens to hold it. Then
production answers correctly, the test reads that as a miss, and the
failure looks like a defect in the feature rather than in the fixture.
That is not hypothetical. On the macOS host where this was found, pid
4242 was `liveactivitiesd`, and five tests failed together on a clean
`dev` checkout: `periodic reclaim frees abandoned temps without any
continuation access`, both `doctor reclaim wiring (end to end)` cases,
and both `status reports stale process records end to end` cases. The
three files together went 186 pass / 5 fail before this change and 191
pass / 0 fail after it, with pid 4242 still held by `liveactivitiesd`
across both runs.
The probe already existed. `tests/responses-state.test.ts` did it inline
for one test, with a comment naming this exact hazard on a shared CI
runner, while four sites in the same file and four more in
`tests/cli-status-json.test.ts` and `tests/doctor.test.ts` kept the
assumption. This lifts that probe into `tests/helpers/dead-pid.ts` and
uses it at every site, so the knowledge lives in one place rather than in
a comment beside one of nine copies.
The helper throws rather than returning a sentinel: the inline version
needed `expect(deadPid).toBeGreaterThan(0)` at its call site, and a throw
gives every caller that guarantee without repeating the assertion. ESRCH
is the only accepted answer — a successful `kill(pid, 0)` means alive and
EPERM means alive but owned by somebody else.
Other `4242` literals in the suite are injected fixture data read through
mocked accessors, never probed against the kernel, and are left alone.
Verified on macOS: bun run typecheck clean, bun run privacy:scan passed,
bun run test 16514 pass / 0 fail across 998 files.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
0 commit comments