Commit Graph

1 Commits

Author SHA1 Message Date
Tycho 505da32def test(plugin-worker-manager): cover stdin command-channel supervision
Adds the missing test for the supervision added in this PR: a worker whose
host->worker stdin pipe dies while the process itself stays alive.

New suite server/src/__tests__/plugin-worker-stdin-supervision.test.ts, plus a
plugin-worker-persistent.cjs fixture that deliberately survives stdin EOF (ref'd
keep-alive timer, readline "close" is a no-op) so nothing but the host
supervision can end it. It spawns a real child through the existing fixture
pattern and captures it by wrapping node:child_process.fork with a
pass-through mock; the fork is real.

Two cases:

1. stdin destroyed with EPIPE while the process is alive -> the manager
   SIGKILLs the child and schedules a restart (crash event willRestart=true,
   status "backoff", diagnostics().nextRestartAt in the future). SIGKILL is the
   discriminator: this fixture never exits on its own inside the test window and
   exits 0 when asked politely, so only the supervision path can produce a
   signalled exit here.

2. Negative control for the risky arm: stdin destroyed *during* an intentional
   stop must not force-kill or restart. The fixture defers its exit after acking
   shutdown, which opens the window; the test waits for status "stopping" and
   for the shutdown to drain out of the host before killing the pipe, so it
   cannot pass by dropping the shutdown instead.

Verified by mutation, not just by going green:

- reverting plugin-worker-manager.ts to the pre-fix parent fails case 1 only
  ("worker was left alive and uncommandable after its command channel died")
  and leaves case 2 green;
- removing only the `intentionalStop ||` guard fails case 2 only
  ("expected 'SIGKILL' to be null") and leaves case 1 green.

Lives in its own file because vi.mock is file-scoped and the sibling
plugin-worker-manager.test.ts keeps an unmocked fork; that suite still passes
(30 tests across both files). Server typecheck clean. The suite is picked up by
the glob-based general-server sharding and lands in exactly one of the four
shards.
2026-08-05 12:50:11 -06:00