[Testing 18] test(frontend): API-client/SSE tests + coverage ratchet

✅ merged · #255 · open-legal-products/mike ← amal66/mike · opened 3mo ago by amal66 · merged 3mo ago by willchen96 · +1,336-18 across 9 files · ↗ on GitHub

From the PR description

This gives the frontend the same safety net the backend already has: unit tests over the client library plus a coverage floor that fails CI if a change drops tested behavior.

What's tested

  • mikeApi.ts - the API client every page goes through: auth headers, how server errors become readable messages (including the MFA-required case), file downloads, how stored chat events become the messages you see, and the four streaming endpoints.
  • The SSE stream reader in useAssistantChat - the code that turns the backend's live stream into text on screen. The network is allowed to cut events into arbitrary pieces, so the tests feed it streams chopped mid-JSON, several events in one chunk, error events, garbage lines, and streams that end without a final newline. This is the frontend half of the SSE contract; the backend half is tested on its side.
  • Upload validation (which file types are accepted) and model availability (which models light up for your API keys) - both now at 100%.

The ratchet - same idea as the backend one: vitest.config.mts now enforces coverage floors over src/app/lib/** set just below today's measured numbers (54/73/32/52 for statements/branches/functions/lines). They're a floor, not a target: never lower them; raise them in the same PR whenever you add tests. docs/frontend-testing.md explains how to run everything and lists what to test next, in priority order - assistant message rendering and tabular review state are the top two.

CI - the frontend test step now runs npm run test:coverage --if-present, so the floor check gates every PR; on a tree without the script it still no-ops. No other CI changes.

One new devDependency: @vitest/coverage-v8 (installed via npm; lockfile npm-managed).

Verified locally: 94 tests green with the floors enforced, npm run lint 0 errors, npm run build green.

🤖 Generated with Claude Code

Our analysis

Add frontend test coverage ratchet — read the full analysis →

Think the analysis missed something the PR description covers?

Commits in this PR (1)

SHA Subject Author Date
2392e677 test(frontend): SSE/client unit tests + coverage ratchet Amalanand Muthukumaran 2026-07-25 ↗ GitHub
commit body
Unit tests for the frontend client library and the SSE stream consumer,
plus a v8 coverage ratchet over src/app/lib/** mirroring the backend's
(floors just below measured, only ever raised):

- mikeApi.ts: request/auth/error plumbing, blob downloads, getChat and
  mapTRMessages mapping, and all four streaming endpoints (the frontend
  half of the SSE contract - raw Response passed through unconsumed).
- useAssistantChat: SSE parse loop against real ReadableStream bodies -
  chunk-boundary reassembly, multi-event chunks, reasoning/content
  interleave, error events, malformed lines, EOF without trailing newline.
- documentUploadValidation.ts and modelAvailability.ts: full coverage.
- test:coverage script + @vitest/coverage-v8; CI frontend test step now
  runs it (still --if-present).
- docs/frontend-testing.md: how to run, ratchet rules, TODO backlog.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Capture this PR into my fork

Download a Markdown prompt that tells Claude how to port every commit in this PR into your working tree. Run it via claude -p < capture-pull-255.md from inside the repo you want the changes in.

⬇ Download capture-pull-255.md