Description
Several correctness-critical functions have zero or insufficient test coverage:
-
monitor.ts — Zero unit tests. The daemon lifecycle manager handles spawning, crash recovery, signal handling, exponential backoff, SIGHUP reload. Only covered by integration script test-recovery.sh.
-
MetricsStore.getModelStats() — 90-line function computing p50/p95 latency, success rates, tokens/sec, cache hit rates, provider breakdowns. Only indirectly tested via getSummary() basic structure.
-
recordConnectionError()/getConnectionErrors() — Track stall/TTFB/connection errors. Called from proxy.ts stall/timeout handlers. No test coverage.
-
cleanOrphanedToolMessages() (proxy.ts:324-388) — Removes orphaned tool_use/tool_result blocks during fallback. Correctness-critical for multi-provider tool use. Never tested.
-
nextState()/transitionStreamState() (types.ts:190-252) — Stream state machine with specific valid/invalid transition rules. Never directly tested.
-
pruneWarmupStates() (pool.ts:51-58) — Removes stale warmup entries during config hot-reload. Never tested.
Suggested Fix
Create dedicated test files or test sections for each:
monitor.test.ts (mock child_process, net, fs)
describe("getModelStats") in metrics.test.ts
describe("recordConnectionError") in metrics.test.ts
stream-state.test.ts for state machine transitions
- Test
cleanOrphanedToolMessages via integration tests with tool_use blocks
- Test
pruneWarmupStates in pool.test.ts
Description
Several correctness-critical functions have zero or insufficient test coverage:
monitor.ts— Zero unit tests. The daemon lifecycle manager handles spawning, crash recovery, signal handling, exponential backoff, SIGHUP reload. Only covered by integration scripttest-recovery.sh.MetricsStore.getModelStats()— 90-line function computing p50/p95 latency, success rates, tokens/sec, cache hit rates, provider breakdowns. Only indirectly tested viagetSummary()basic structure.recordConnectionError()/getConnectionErrors()— Track stall/TTFB/connection errors. Called from proxy.ts stall/timeout handlers. No test coverage.cleanOrphanedToolMessages()(proxy.ts:324-388) — Removes orphaned tool_use/tool_result blocks during fallback. Correctness-critical for multi-provider tool use. Never tested.nextState()/transitionStreamState()(types.ts:190-252) — Stream state machine with specific valid/invalid transition rules. Never directly tested.pruneWarmupStates()(pool.ts:51-58) — Removes stale warmup entries during config hot-reload. Never tested.Suggested Fix
Create dedicated test files or test sections for each:
monitor.test.ts(mock child_process, net, fs)describe("getModelStats")inmetrics.test.tsdescribe("recordConnectionError")inmetrics.test.tsstream-state.test.tsfor state machine transitionscleanOrphanedToolMessagesvia integration tests with tool_use blockspruneWarmupStatesinpool.test.ts