Skip to content

Vitest unit-test infrastructure + 90% coverage for components and core modules #1245

@cliffhall

Description

@cliffhall

Background

AGENTS.md mandates 90% test coverage for all code: "Ensure all code has corresponding tests. Ensure test coverage for each file is at least 90%." The Phase 1-5 component refactor explicitly deferred unit tests as out-of-scope, deferring the full coverage push to a single follow-up effort once the interface dust settled.

There is currently no Vitest config, no test runner, no test files in clients/web/. The root package.json has a placeholder "test": "echo \"Error: no test specified\" && exit 1". Coverage is effectively zero.

Scope

Test infrastructure:

  • Add Vitest, @testing-library/react, @testing-library/jest-dom, jsdom (or happy-dom) to clients/web/package.json devDependencies.
  • Add vitest.config.ts configured for React + TypeScript with the existing tsconfig.app.json.
  • Add npm run test and npm run test:coverage scripts to clients/web/package.json and surface them at the root.
  • Configure c8 / built-in coverage reporter with the 90% threshold per AGENTS.md, failing the script when uncovered.

Component tests (62 components):

  • Each component under clients/web/src/components/{elements,groups,screens,views}/ has a <Name>.test.tsx file.
  • Tests exercise: render with minimal props, render with each documented prop variant, callback firing on user interaction, accessible role/label assertions where relevant.
  • Per AGENTS.md: "In unit tests that expect error output, suppress it from the console."

Core module tests (under core/):

  • core/mcp/types.ts — type-only file; covered by usage in component tests, not separate.
  • core/mcp/elicitationCreateMessage.ts — schema validation tests.
  • core/mcp/taskNotificationSchemas.ts — schema validation tests.
  • clients/web/src/utils/jsonUtils.ts, schemaUtils.ts — pure-logic tests against AJV-validated fixtures.
  • clients/web/src/components/groups/historyUtils.tsextractMethod happy-path and synthetic-response branch.

Acceptance criteria

  • npm run test runs the full suite headlessly and exits 0 on a clean tree.
  • npm run test:coverage reports ≥90% line coverage on every file under clients/web/src/components/ and core/mcp/.
  • CI (.github/workflows/main.yml) is updated to run npm run test:coverage on every PR; failure blocks merge.
  • AGENTS.md is updated to point at the now-real npm run test command (no longer "aspirational").

Test plan

  • Run npm run test:coverage locally; manually inspect a sample of generated test files for quality (not just coverage padding).
  • CI run on a draft PR confirms the coverage gate fires when coverage drops.
  • npm run format && npm run lint && npm run build continues clean.

Out of scope

  • E2E / browser tests (Playwright or similar) — would be a third tier.
  • Storybook interaction tests — already exercised manually.
  • Performance / load tests.
  • Tests for the v2 core/ hook layer (its own tests live with the hook layer issue).

Independent of

  • This effort can run in parallel with the v2 core hook layer effort. Tests for existing dumb components don't depend on hooks landing.

Related

Metadata

Metadata

Assignees

Labels

v2Issues and PRs for v2

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions