Skip to content

test: raise unit test coverage to 100% and enforce it - #1632

Merged
joshunrau merged 173 commits into
DouglasNeuroInformatics:mainfrom
joshunrau:test-cov
Oct 5, 2026
Merged

joshunrau merged 173 commits into
DouglasNeuroInformatics:mainfrom
joshunrau:test-cov

Conversation

@joshunrau

@joshunrau joshunrau commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Raises unit-test coverage from about 50% to 100% on every metric across apps/{api,gateway,web} and packages/*, then makes 100% the gate locally and in CI.

Coverage

Metric Before After
Lines 50.14% (4380/8736) 100.00% (8704/8704)
Statements 50.32% (4659/9258) 100.00% (9129/9129)
Functions 45.81% (1311/2862) 100.00% (2695/2695)
Branches 45.72% (2257/4937) 100.00% (4775/4775)
By workspace (lines / branches)
Workspace Lines before Lines after Branches before Branches after
apps/api 69.18 100.00 67.42 100.00
apps/gateway 14.02 100.00 7.06 100.00
apps/web 28.07 100.00 23.44 100.00
packages/demo 100.00 100.00 100.00 100.00
packages/instrument-bundler 97.07 100.00 88.72 100.00
packages/instrument-interpreter 100.00 100.00 100.00 100.00
packages/instrument-library 0.00 100.00 0.00 100.00
packages/instrument-stubs 38.18 100.00 0.00 100.00
packages/instrument-utils 99.22 100.00 98.89 100.00
packages/licenses 100.00 100.00 100.00 100.00
packages/playground-url 100.00 100.00 93.55 100.00
packages/react-core 91.28 100.00 84.47 100.00
packages/release-info 100.00 100.00 100.00 100.00
packages/runtime-bundler 98.64 100.00 91.23 100.00
packages/runtime-core 0.00 100.00 0.00 100.00
packages/runtime-internal 11.65 100.00 5.26 100.00
packages/runtime-meta 100.00 100.00 100.00 100.00
packages/schemas 100.00 100.00 97.06 100.00
packages/serve-instrument 88.02 100.00 81.58 100.00
packages/subject-utils 100.00 100.00 100.00 100.00
packages/vite-plugin-runtime 100.00 100.00 100.00 100.00

"Before" is the c6bf765b4 run, recomputed under this PR's coverage scope (see below). The before denominators are larger: they include the phantom SWC entries fixed here and the dead code deleted here. Now 392 test files and 4,392 tests, plus 5 it.fails pinning filed bugs.

What changed

  • Unit tests under each workspace's __tests__/, one commit per batch (test(<scope>): …). Each batch was written by one agent, reviewed by a second, adversarial agent and fixed before it was committed.

  • Dead code removed (refactor(api|web|react-core|instrument-utils|runtime-internal)). The last ~50 uncovered branches were code no input can reach. Each was proved dead from the types, every caller, or the library contract, then deleted or restructured so the impossible state cannot be written. tsc, the unit suite and e2e confirm nothing reachable went:

    • Radix onOpenChange on dialogs without a trigger (Radix only ever passes false);
    • ?? [] / ?? {} fallbacks on non-null values;
    • guards that repeat an earlier guard;
    • .otherwise(() => null) after exhaustive matches, now .exhaustive();
    • zod 4's never-produced int type name.

    One deletion was wrong and a test caught it before commit: a preview code path shared the expression. It was restored.

  • fix(api): the in-memory replica set is now stopped on shutdown (In-memory replica set is never stopped when the api shuts down under NODE_ENV=test #1651).

  • Enforcement:

    • The root vitest config sets coverage.thresholds: { 100: true }.
    • CI's unit step runs pnpm test:coverage.
    • A new root AGENTS.md hard rule: uncoverable code is proved dead and deleted, never ignored or excluded. "Before you are done", odc-done, odc-testing, the testing strategy and the playbooks now name pnpm test:coverage.
  • New vitest projects for runtime-core, instrument-library and instrument-stubs. instrument-library maps /runtime/v1/* imports to source, so its tests need no build.

  • Catalog devDeps: happy-dom and @testing-library/{react,dom} added to gateway, runtime-core and instrument-library, plus react/react-dom workspace links in instrument-library. pnpm install also bumped @testing-library/dom 10.4.1 → 10.4.2 and ws 8.21.0 → 8.22.0 in the lockfile.

  • Coverage scope: excludes test fixtures and helpers (__tests__, __mocks__, apps/web/src/testing), the generated route-tree.ts, and the bare entrypoints (web main.tsx, gateway entry-client.tsx and main.ts).

  • apps/api/vitest.config.ts: SWC now transforms only apps/api sources. Before this, SWC also transformed the workspace packages the api imports, and the merged report counted each of their functions twice with one copy never hit.

  • packages/react-core/vitest.config.ts: sets happy-dom's disableIframePageLoading, so InteractiveContent tests no longer make real requests to localhost:3000.

Bugs found

Verified and filed as #1633–#1653. #1651 is fixed in this PR. The others are pinned by tests: it.fails asserts the correct behaviour, and the remaining tests are named as defects. Each issue says which test to flip when it is fixed.

Verification

  • pnpm lint: green (34/34 tasks).
  • pnpm test:coverage: green at 100% on all four metrics. vitest list --filesOnly collects every added test file.
  • pnpm test:e2e: 277/277 passed.

Exception: no new testing/ spec. The tests and the dead-code removal change no reachable behaviour, and the existing suite passes unchanged.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

joshunrau and others added 30 commits October 4, 2026 21:39
…erage

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…outes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ialog

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…el downloads

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…alogs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ve dialog

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…strument card

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…efaults

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…strument-stubs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
joshunrau and others added 6 commits October 4, 2026 22:38
… summary fixtures

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e counts each function once

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ge from localhost

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eir agent docs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 5, 2026
@joshunrau
joshunrau merged commit 50bb8db into DouglasNeuroInformatics:main Oct 5, 2026
2 checks passed
@joshunrau joshunrau changed the title test: raise unit test coverage to over 99% on every metric test: raise unit test coverage to 100% and enforce it Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant