Skip to content

fix(coverage): include core/ files in v8 per-file gate (#1301) - #1305

Merged
cliffhall merged 2 commits into
v2/mainfrom
v2/coverage-core-include-1301
May 15, 2026
Merged

cliffhall merged 2 commits into
v2/mainfrom
v2/coverage-core-include-1301

Conversation

@cliffhall

Copy link
Copy Markdown
Member

Summary

Fixes #1301. Two distinct problems were preventing coverage.include's ../../core/** globs from actually measuring files under core/:

  1. allowExternal: false (the default) — vitest drops any file whose absolute path doesn't start with the project root (clients/web/) before applying the include filter. The ../../core/... globs never had a chance to match.
  2. Coverage transformer only reaches files inside a project root — for everything outside, getSources falls back to reading the raw .ts file and feeding it to rolldown's parser, which can't handle TS-only syntax like import type {…}. Untested core files were being silently dropped via Failed to parse … Excluding it from coverage — bypassing the per-file gate.

Fixes in clients/web/vite.config.ts:

  • Set coverage.allowExternal: true and rewrite the cross-package globs as absolute paths so both tinyglobby (used by getUntestedFiles) and picomatch (used by isIncluded) match correctly.
  • Root the unit vitest project at the repo root so the coverage transformer reaches core/. Adjust include / setupFiles paths and add an explicit react alias (the repo root has no node_modules/ of its own to walk up to).
  • Exclude four pure-type core modules (samplingCreateMessage, sessionStorage, inspectorClientProtocol, inspectorClientEventTarget) with a comment — they have no executable code, mirroring the existing exclusions for types.ts / elicitationCreateMessage.ts.

Verification

  • coverage-summary.json now contains 31 entries under core/mcp/ and core/react/ (was 0).
  • Per-file gate is enforced for those files (all currently at 100% lines).
  • Verified by dropping a probe file core/mcp/__coverageProbe.ts with one untested function — npm run test:coverage exited with code 1 and emitted four ERROR: Coverage for X (0%) does not meet global threshold (Y%) for ../../core/mcp/__coverageProbe.ts lines. Removed afterwards.

Test plan

  • npm run validate (format, lint, build, test:coverage) passes — exit 0
  • npm run test:storybook passes — 298 tests across 67 files
  • Untested core file with TS syntax fails the gate (verified via probe)
  • All 937 unit tests still pass

🤖 Generated with Claude Code

Two issues prevented coverage.include's '../../core/...' globs from
reaching core/ files:

1. allowExternal defaults to false — v8 drops any file whose absolute
   path doesn't start with the project root (clients/web/) before the
   include filter runs. Set allowExternal: true, and switch the globs
   to absolute paths so tinyglobby + picomatch handle them correctly.

2. vitest's coverage transformer only processes files inside a project
   root; for everything else it falls back to raw-TS parsing in
   rolldown, which can't handle TS-only syntax (e.g. import type) —
   silently dropping untested core/ files and bypassing the gate.
   Root the unit project at the repo root so the transformer reaches
   core/. The repo root has no node_modules, so add an explicit react
   alias and shift include/setupFiles paths accordingly.

Also add the four pure-type core files (samplingCreateMessage,
sessionStorage, inspectorClientProtocol, inspectorClientEventTarget)
to the exclude list with a comment — they have no executable code.

Verified by introducing an untested probe file, confirming exit=1 with
threshold errors, then removing it.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@cliffhall cliffhall added the v2 Issues and PRs for v2 label May 14, 2026
@cliffhall

Copy link
Copy Markdown
Member Author

@claude review

@claude

claude Bot commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @cliffhall's task in 1m 39s —— View job


Code Review

  • Read changed file (clients/web/vite.config.ts)
  • Inspect the diff against origin/v2/main
  • Verify the claims about allowExternal and the transformer project-root issue
  • Check the excluded core modules really have no executable code
  • Post review feedback

Overall

Solid, well-explained fix. The PR description accurately diagnoses both issues (default allowExternal: false + transformer's project-root boundary) and the comments in the diff preserve that reasoning where future readers will actually see it. The four newly excluded core modules are genuinely pure-type declarations (verified — see below). No blocking issues; a few nits and one thing worth confirming below.

Verified claims

  • core/mcp/samplingCreateMessage.ts, sessionStorage.ts, inspectorClientProtocol.ts: only import type / export type / interface — zero runtime statements. ✔
  • core/mcp/inspectorClientEventTarget.ts: type declarations + class InspectorClientEventTarget extends TypedEventTarget<InspectorClientEventMap> {} with an empty body. The inline comment in vite.config.ts:60-61 correctly notes that v8/istanbul records 0 statements. ✔
  • core/mcp/typedEventTarget.ts (the file the empty class extends) is not excluded — it has real runtime code. ✔
  • Repo root has no node_modules/, so the explicit react alias at vite.config.ts:84 is load-bearing (bare react imports from core/react/*.ts would otherwise fail to resolve once root moves up). ✔

Nits / follow-ups

1. Duplicate resolve.alias + dedupe between top-level and unit project (vite.config.ts:16-25 vs vite.config.ts:76-87)

Vitest projects don't merge resolve from the parent config — the unit project redeclares @inspector/core and dedupe: ['react', 'react-dom'] so they apply with the new root: repoRoot. This is intentional and necessary, but the duplication is a drift hazard (e.g. if a new core/* alias gets added at the top level and someone forgets to mirror it below, the unit suite will silently miss it). Worth either (a) a short comment on the top-level resolve noting that the unit project overrides it, or (b) extracting the shared alias object to a const and spreading it in both places.

2. Is allowExternal: true still required now that root = repoRoot for the unit project?

Once the unit project's root is repoRoot, core/ is no longer "external" from that project's perspective. coverage.* is a top-level setting, so it still applies to other projects where the root stays at clients/web/ — but the storybook project doesn't collect coverage, so in practice this may be belt-and-suspenders. Not suggesting you remove it (the comment is helpful either way), just worth confirming it matches your mental model. If you've already verified coverage still works with allowExternal: false once the root moved, the comment should probably say "kept defensive-ly in case another project is added that collects coverage from outside its root."

3. inspectorClientEventTarget.ts exclusion is safe today, but will rot

The empty-body class will stop being "0 statements" the moment any method or field body is added (the v1.5 port in #1243 mentions more surface landing later). Consider a TODO(#1243) inline so this exclusion is revisited when the class gets real behavior — otherwise an untested method could slip past the gate behind the exclusion.

Questions (non-blocking)

  • The PR excludes core/mcp/inspectorClientProtocol.ts even though it's a .ts file with only type declarations, which the transformer should handle now that the root moved. Was this exclusion needed because v8 still reported a 0/0 row for it, or was it precautionary? (Fine either way — clarifying would help future readers decide whether to drop the exclusion when the protocol gets a runtime implementation.)

Nothing blocking — recommend merge after the two comment-level nits above, whichever you prefer to action. The coverage gate is now actually doing what it says on the tin for core/, which is the important outcome.
· Branch: v2/coverage-core-include-1301

- Drop allowExternal: true — with the unit project rooted at repoRoot,
  core/ files are no longer "external" to any project that collects
  coverage (the storybook project doesn't), so the flag is redundant.
- Extract sharedAliases / sharedDedupe constants and reference them
  from both the top-level resolve and the unit project resolve, so
  the two stay in sync if a new core/* alias is added.
- Add TODO(#1243) on the inspectorClientEventTarget.ts exclusion so
  it's revisited once the class gains real behavior in the
  InspectorClient port.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@cliffhall

Copy link
Copy Markdown
Member Author

Thanks for the careful review @claude — pushed 161e9c9 addressing all three.

1. Duplicate resolve.alias + dedupe — went with option (b): extracted sharedAliases and sharedDedupe constants at the top of the file and spread them in both places. Added a NOTE: comment on the top-level resolve pointing at the unit-project override.

2. Is allowExternal: true still required? — Great catch, it wasn't. Verified by temporarily removing it and re-running test:coverage: all 31 core/ files still appear in coverage-summary.json. The reasoning matches what you laid out — once root = repoRoot for the unit project, every core/ file passes the roots.every((root) => !filename.startsWith(root)) filter (the unit project's root is a prefix). And the storybook project doesn't collect coverage. So I dropped the flag outright rather than keeping it defensively — easier to add back with intent than to keep an unused flag whose purpose decays.

3. inspectorClientEventTarget.ts will rot — agreed, added TODO(#1243): drop this exclusion once the class gains real behavior on the exclude entry.

On the question about inspectorClientProtocol.ts — precautionary, not necessary. After moving the unit project root, the transformer can process it and v8 would surface it as a 0/0 row (which istanbul reports as 100% via percent(0, 0) → 100). I grouped it with the other pure-type files for consistency and to keep the report tidy, but you're right that the exclusion can come off when the protocol gets a runtime implementation — same TODO(#1243) applies. I left the comment generic ("Pure-type modules: ... no runtime statements") rather than adding individual TODOs per file, but happy to make each one explicit if you'd prefer.

Validate + storybook both still green (937 + 298 tests).

@claude

claude Bot commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @cliffhall's task in 37s —— View job


Follow-up review — 161e9c9

All three items land cleanly. Quick verification pass:

1. Shared alias/dedupe extraction (vite.config.ts:13-20, :27/:32, :89/:92) — sharedAliases + sharedDedupe defined once, referenced from the top-level resolve and spread into the unit project's resolve. The leading comment spells out why the duplication exists (vitest projects don't inherit resolve) and the NOTE: on the top-level alias points at the override. This is exactly the drift-prevention I was angling at — good call preferring option (b).

2. allowExternal dropped — verified it's gone from the config. Your analysis matches mine: once root = repoRoot, the unit project's root is a prefix of every core/ file, so vitest's internal roots.every((root) => !filename.startsWith(root)) check passes without the flag. And since coverage only applies where a project actually collects it (the storybook project doesn't), there's no second consumer to defend against. Agreed that dropping outright is better than keeping a dormant flag whose original purpose decays from the comment next to it.

3. TODO(#1243) on inspectorClientEventTarget.ts (vite.config.ts:63-67) — clear and tied to the issue that will actually trigger revisiting it.

On inspectorClientProtocol.ts — your reasoning is sound and the generic comment at :55-57 ("Pure-type modules: ... no runtime statements ... would otherwise surface as misleading 0/0 rows") carries enough intent that future readers will know to drop individual entries when the modules gain runtime behavior. No need to scatter per-file TODOs — one TODO(#1243) anchor on the class-that-will-grow is the right level of granularity.

Nothing further from me — LGTM, ready to merge. Coverage gate now actually gates core/, the config is self-documenting, and the one remaining exclusion that will need to come back has a tracked trigger.


  • Check out latest and inspect diff against previous SHA
  • Verify sharedAliases / sharedDedupe extraction
  • Confirm allowExternal was dropped
  • Confirm TODO(#1243) comment added on the exclude entry
  • Post review
    · Branch: v2/coverage-core-include-1301

@cliffhall
cliffhall merged commit e154378 into v2/main May 15, 2026
1 check passed
@cliffhall
cliffhall deleted the v2/coverage-core-include-1301 branch May 15, 2026 00:17
@cliffhall cliffhall self-assigned this May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Issues and PRs for v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant