Repository navigation
Description
Summary
shutdown and reconcileBoot hold the ordering behind many past fixes, but they are not exported and index.ts runs main() on import, so no test can exercise them. index.ts is the second most changed source file.
Where
src/index.ts:28-72src/index.ts:81-109src/index.ts:113-131src/index.ts:135-170src/index.ts:181-191
Details
shutdown (index.ts:135-170) aborts edit jobs, waits up to 10 s for in-flight starts, disarms triggers, stops every recording with an ffprobe-backed duration probe, then calls process.exit. reconcileBoot (81-109) reaps orphans, sweeps pinned windows and removes replay dirs. Neither is exported. The module runs main() or runCli() on import (181-191), so a test cannot load it without starting a server. index.ts is the second-most-changed source file: 38 of the last 500 commits. Its history has fixes for #76, #207, #229, #237, #285, #289, #294, #336 and #358 here. The only related test, src/tests/startGuard.test.ts, covers context.ts's start guard, not this ordering.
Impact
The code that stops a capture when the client disconnects or the process crashes is the privacy backstop: a recording must never keep running. That ordering (disarm before stop, abort edits before exit, settle in-flight starts) is protected only by comments. The next change here (WGC parity #316, remote capture #273) has no regression net.
Suggested fix
Incremental plan. Step 1: move shutdown, reconcileBoot and installServerHandlers unchanged into src/serverLifecycle.ts. Export them and have index.ts import them; index.ts keeps only the argv dispatch. Step 2: give shutdown a deps parameter ({ store, abortEditJobs, startsSettled, disarmAll, stopAll, probe, exit, log }) that defaults to the real modules. Step 3: do the same for reconcileBoot. Tests first, after step 1 and before step 2: tests that call shutdown with fakes and assert the call order (abortEditJobs, startsSettled, disarmAll, stopAll, exit), idempotence (a second call is a no-op), that a throwing stopAll still exits with the given code, and that a missing ffprobe still stops recordings. For reconcileBoot: a failing reap does not skip the pin sweep or the replay cleanup.
Acceptance criteria
-
shutdownandreconcileBootmove to a module that can be imported without starting a server - Tests cover the shutdown order: abort edit jobs, settle in-flight starts, disarm triggers, stop recordings, exit
Getting started
- Relevant files:
src/index.ts - Run tests:
npm test(alsonpm run typecheckandnpm run lint); see CONTRIBUTING.md - If you change a tool's schema or description, run
npm run docs
Filed by repo-audit/full-audit at f0e5ebd. Severity: medium. Effort: M. audit-key: tech-debt|src/index.ts|shutdown
Activity