Skip to content

[Test] Missing test coverage for critical functions #169

@kianwoon

Description

@kianwoon

Description

Several correctness-critical functions have zero or insufficient test coverage:

  1. 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.

  2. 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.

  3. recordConnectionError()/getConnectionErrors() — Track stall/TTFB/connection errors. Called from proxy.ts stall/timeout handlers. No test coverage.

  4. cleanOrphanedToolMessages() (proxy.ts:324-388) — Removes orphaned tool_use/tool_result blocks during fallback. Correctness-critical for multi-provider tool use. Never tested.

  5. nextState()/transitionStreamState() (types.ts:190-252) — Stream state machine with specific valid/invalid transition rules. Never directly tested.

  6. 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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions