From 12% to 55% test coverage without breaking the suite
12% test coverage is a tax on every change. Reaching 55% across a 2,830-test suite meant fixing the environment before writing tests.

12% test coverage is a tax on every change. Reaching 55% across a 2,830-test suite meant fixing the environment before writing a single test.
Fix the base first
The suite was failing with "React duplicate instance" errors in the stores — a known pnpm problem. Adding resolve.dedupe for react and react-dom cleared 169 failures in one go. Without that, no amount of test writing mattered.
Layers from the contract upward
Phase one targeted server routes and auth with security-focused tests. Phase two covered the shared package: typed contracts, branded IDs, output sanitization. Phase three handled frontend hooks. Phase four touched only critical-path components — login, 2FA, the job pipeline forms.
Each phase had its own gate. The shared package tests even assert that mixing a site ID with a job ID fails to compile.
Shared scaffolding made it repeatable
Two enablers did the heavy lifting: shared auth and logger mocks so every test file used one setup pattern, and Redis key isolation with per-run scope prefixes so suites didn't contaminate each other's state.
The result: 2,830 tests, zero failures, clean strict typecheck. The constraint I kept: optimistic update logic stayed untested rather than forcing a fragile mock. See the V5 Hub build.
See also: How I use AI for premium design without losing judgment and MCP tool security: when the AI is the attacker.