test: repair route harness error rendering + stop AI-checker spawning real processes in tests#97
Merged
Conversation
added 2 commits
May 25, 2026 20:15
…sertions
The route test harness built a bare Fastify instance without the production
global error handler (server.ts), so structured errors thrown by route helpers
(findSessionOrFail → 404, parseBody → 400) fell through to Fastify's default
handler — yielding a `{statusCode,error,message}` body instead of the
`{success:false,...}` shape, and the tests asserted the old implicit-200
behavior. 51 route tests across 7 files were red.
- Extract the handler into src/web/route-error-handler.ts; server.ts and the
test harness now install the identical handler (single source of truth).
- Correct stale assertions across route test files: throw-based error paths
now assert 404 (unknown session) / 400 (invalid body); genuine in-handler
`return createErrorResponse(...)` paths (200 + success:false) left untouched.
- Reformat a few test files prettier flagged (pre-existing non-compliance).
Route suite: 307/307 passing (was 256/307). No production behavior change.
…cesses respawn-controller.test.ts drives the AI idle checker (ai-checker-base), whose runCheck() spawns a real `tmux new-session` running `claude -p`. The AI-enabled tests only assert the ai_checking state transition (then cancel/stop), so the spawn produced stray real tmux sessions and claude processes on every run — the reason `npm test` (full suite) was unsafe to run inside a managed session. Mock node:child_process here (mirroring ai-idle-checker.test.ts), spreading the real module so `exec` stays intact for transitively-imported modules (tmux-manager calls promisify(exec) at load). With this, the full non-mobile suite runs without spawning any real tmux/claude.
Owner
|
Thank you very much for this, @TeigenZhang — this is an excellent, well-documented contribution. 🙏 I reviewed it carefully and verified both claims locally:
CI (Typecheck & Lint) is green. Merging now — thanks again for making the suite both correct and safe to run! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two fixes that make the route test suite correct and safe to run.
1. Render structured route errors in the test harness + fix stale assertions
Route helpers (
findSessionOrFail→ 404,parseBody→ 400) throw structured{ statusCode, body }errors that the production server converts via a globalsetErrorHandler. The route test harness built a bare Fastify instance without that handler, so thrown errors fell through to Fastify's default handler — yielding a{statusCode,error,message}body instead of{success:false,...}, while the tests still asserted the old implicit-200 behavior. 51 route tests across 7 files were red.src/web/route-error-handler.ts; the server and the test harness now install the identical handler (single source of truth — no production behavior change).return createErrorResponse(...)paths (200 +success:false) left untouched.2. Stop the AI idle checker from spawning real processes in tests
respawn-controller.test.tsdrives the AI idle checker, whoserunCheck()spawns a realtmux new-sessionrunningclaude -p. The AI-enabled tests only assert theai_checkingstate transition (then cancel/stop), so the spawn leaked stray tmux sessions +claudeprocesses on every run — the reason the full suite was unsafe to run inside a managed session. Mocknode:child_processhere (mirroringai-idle-checker.test.ts), spreading the real module soexecstays intact for transitively-imported modules.Test plan
tsc --noEmitcleannpm test -- test/routes/→ 305 passing (was 254/305)npm test -- test/respawn-controller.test.ts→ 162 passing, zero real tmux/claude spawned (verified via before/after tmux session diff)🤖 Generated with Claude Code