Frontend Unit Test Audit
Date: 2026-04-19
Scope
Audit of frontend unit-test coverage for:
frontend/src/lib/api.tsfrontend/src/lib/guards.tsfrontend/src/lib/operate-contracts.tsfrontend/src/lib/operate-events.ts
Current Baseline
- Runner: Vitest (
vitest run --config vitest.config.ts). - Tests focus on deterministic unit behavior with explicit boundary mocking.
- Coverage reporting is enabled and threshold-gated in CI.
- Browser smoke tests (Playwright) remain complementary and do not replace deterministic unit checks for parser/normalizer edge cases.
Gaps Identified
api.ts:downloadBlobbehavior required explicit validation.fetchJsonerror branches needed coverage for:- non-JSON success payload
- non-JSON error payload
- empty error payload fallback
guards.ts:- negative/no-prompt paths needed explicit assertions.
- project-switch warning suppression cases needed explicit assertions.
operate-contracts.ts:- many exported normalizers/parsers required coverage across invalid/partial payloads.
- branch-heavy validation (
coerceParameterValue) required bounds and unsupported-type checks. renderBtOutlinerequired direct unit coverage.
operate-events.ts:- reconnect/parse-error/init-failure branches required explicit tests.
- status transitions and timer-driven stale detection required explicit assertions.
Test Strategy
- Keep tests deterministic:
- mock only external boundaries (
fetch,EventSource, timers, DOM shims). - avoid asserting implementation trivia when behavior-level assertions are possible.
- mock only external boundaries (
- Cover success + failure branches for each exported function in
frontend/src/lib/*. - Maintain a coverage gate focused on
frontend/src/lib/**/*so migration decisions are based on measured confidence.
Coverage Gate
Enforced thresholds for frontend/src/lib/**/*:
- statements: 85%
- branches: 75%
- functions: 85%
- lines: 85%
These thresholds are intentionally non-trivial and can be raised once the TypeScript migration and release path are stable.
Out of Scope for This Pass
- Full component-level unit tests for Svelte routes/components.
- Contract-level backend API integration (already covered by Python contract tests).
- End-to-end browser workflow coverage expansion (already partly covered by Playwright smoke lane).
Implementation Status
Completed in this pass:
- Vitest runner configured (
frontend/vitest.config.ts) with V8 coverage + thresholds. - Frontend test scripts added in
frontend/package.json:test:unittest:unit:watchtest:unit:coverage
- Unit tests migrated to TypeScript under
frontend/tests/unit/:api.test.tsguards.test.tsoperate-contracts.test.tsoperate-events.test.ts
- Legacy Node-runner
.mjsfrontend unit tests removed fromtests/unit/. - CI test lane switched to Vitest coverage execution.
- Frontend library modules migrated from JS to TS and imports updated across app + tests.
Verification snapshot:
- Vitest:
38 passed. - Coverage (
frontend/src/lib/**/*aggregate):- statements:
98.65% - branches:
82.78% - functions:
95.55% - lines:
98.65%
- statements:
npm run check:0 errors,29 warnings(existing Svelte a11y label association warnings).
