From 9523a9025b6d91763b07f6c94b496767e160b8e1 Mon Sep 17 00:00:00 2001 From: cliffhall Date: Thu, 14 May 2026 19:10:29 -0400 Subject: [PATCH 1/2] fix(coverage): include core/ files in v8 per-file gate (#1301) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- clients/web/vite.config.ts | 48 ++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/clients/web/vite.config.ts b/clients/web/vite.config.ts index ee587774f8..b5f28cdc5a 100644 --- a/clients/web/vite.config.ts +++ b/clients/web/vite.config.ts @@ -8,6 +8,7 @@ import { fileURLToPath } from 'node:url'; import { storybookTest } from '@storybook/addon-vitest/vitest-plugin'; import { playwright } from '@vitest/browser-playwright'; const dirname = typeof __dirname !== 'undefined' ? __dirname : path.dirname(fileURLToPath(import.meta.url)); +const repoRoot = path.resolve(dirname, '../..'); // More info at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon export default defineConfig({ @@ -31,11 +32,15 @@ export default defineConfig({ coverage: { provider: 'v8', reporter: ['text', 'html', 'json-summary'], + // Files under core/ live outside this project's root (clients/web/), so + // vitest's default project-root prefix filter would drop them before the + // include glob runs. allowExternal lets the include filter apply to them. + allowExternal: true, include: [ 'src/components/**/*.{ts,tsx}', 'src/utils/**/*.{ts,tsx}', - '../../core/mcp/**/*.{ts,tsx}', - '../../core/react/**/*.{ts,tsx}', + path.join(repoRoot, 'core/mcp/**/*.{ts,tsx}'), + path.join(repoRoot, 'core/react/**/*.{ts,tsx}'), ], exclude: [ '**/*.stories.{ts,tsx}', @@ -43,9 +48,19 @@ export default defineConfig({ '**/*.fixtures.{ts,tsx}', '**/index.{ts,tsx}', 'src/components/**/types.ts', - '../../core/mcp/types.ts', - '../../core/mcp/elicitationCreateMessage.ts', - '../../core/mcp/__tests__/**', + // Pure-type modules: `interface`/`type` declarations only, no runtime + // statements. Coverage tools either silently drop them (rolldown can't + // parse raw `import type {...}` syntax) or surface them as misleading + // 0/0 rows. Excluding them keeps the report clean. + path.join(repoRoot, 'core/mcp/types.ts'), + path.join(repoRoot, 'core/mcp/elicitationCreateMessage.ts'), + path.join(repoRoot, 'core/mcp/samplingCreateMessage.ts'), + path.join(repoRoot, 'core/mcp/sessionStorage.ts'), + path.join(repoRoot, 'core/mcp/inspectorClientProtocol.ts'), + // inspectorClientEventTarget.ts is types + a single empty-body class + // (extends TypedEventTarget). v8/istanbul records 0 statements for it. + path.join(repoRoot, 'core/mcp/inspectorClientEventTarget.ts'), + path.join(repoRoot, 'core/mcp/__tests__/**'), ], thresholds: { perFile: true, @@ -58,15 +73,34 @@ export default defineConfig({ projects: [ { extends: true, + resolve: { + alias: { + '@inspector/core': path.resolve(dirname, '../../core'), + // Bare-module override: core/react/* imports "react", which vite + // resolves by walking up from the file looking for node_modules/. + // We move the unit project root to repoRoot below, and the repo + // root has no node_modules of its own — so without this alias, + // imports from core/ can't find react. + react: path.resolve(dirname, 'node_modules/react'), + }, + dedupe: ['react', 'react-dom'], + }, test: { name: 'unit', environment: 'happy-dom', + // Root the unit project at the repo root so vitest's coverage + // transformer (which only processes files inside a project root) + // can reach core/ modules. Without this, untested core/ files fall + // back to raw-TS parsing in rolldown, which can't handle TS-only + // syntax (e.g. `import type`) — silently dropping them and bypassing + // the per-file gate. + root: repoRoot, // No `globals: true` — every test file imports `describe`, `it`, // `expect`, `vi` explicitly from "vitest". This keeps the pattern // consistent and avoids relying on auto-cleanup tied to Vitest's // global lifecycle hooks; cleanup is invoked manually in setup.ts. - include: ['src/**/*.test.{ts,tsx}'], - setupFiles: ['./src/test/setup.ts'], + include: ['clients/web/src/**/*.test.{ts,tsx}'], + setupFiles: [path.join(dirname, 'src/test/setup.ts')], }, }, { From 161e9c92e222edc49e497959e8d2f66f662c075e Mon Sep 17 00:00:00 2001 From: cliffhall Date: Thu, 14 May 2026 19:26:24 -0400 Subject: [PATCH 2/2] refactor(coverage): address review feedback on #1305 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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) --- clients/web/vite.config.ts | 44 ++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/clients/web/vite.config.ts b/clients/web/vite.config.ts index b5f28cdc5a..2aae7a6aa4 100644 --- a/clients/web/vite.config.ts +++ b/clients/web/vite.config.ts @@ -10,18 +10,26 @@ import { playwright } from '@vitest/browser-playwright'; const dirname = typeof __dirname !== 'undefined' ? __dirname : path.dirname(fileURLToPath(import.meta.url)); const repoRoot = path.resolve(dirname, '../..'); +// Aliases shared between the top-level resolve and the unit vitest project. +// Vitest projects don't inherit `resolve` from the parent, so the unit project +// redeclares them — keeping a single source here prevents the two from drifting +// (e.g. if a new core/* alias is added). +const sharedAliases = { + '@inspector/core': path.resolve(dirname, '../../core'), +}; +const sharedDedupe = ['react', 'react-dom']; + // More info at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon export default defineConfig({ plugins: [react()], resolve: { - alias: { - '@inspector/core': path.resolve(dirname, '../../core'), - }, + // NOTE: the unit vitest project (below) overrides this — see comment there. + alias: sharedAliases, // Source files in core/ import bare modules (react, @testing-library/react, // etc.) that only exist in clients/web/node_modules. Dedupe ensures Vite // resolves them from this package rather than walking up from core/'s // location (which has no node_modules of its own yet). - dedupe: ['react', 'react-dom'], + dedupe: sharedDedupe, }, server: { fs: { @@ -32,10 +40,6 @@ export default defineConfig({ coverage: { provider: 'v8', reporter: ['text', 'html', 'json-summary'], - // Files under core/ live outside this project's root (clients/web/), so - // vitest's default project-root prefix filter would drop them before the - // include glob runs. allowExternal lets the include filter apply to them. - allowExternal: true, include: [ 'src/components/**/*.{ts,tsx}', 'src/utils/**/*.{ts,tsx}', @@ -49,16 +53,17 @@ export default defineConfig({ '**/index.{ts,tsx}', 'src/components/**/types.ts', // Pure-type modules: `interface`/`type` declarations only, no runtime - // statements. Coverage tools either silently drop them (rolldown can't - // parse raw `import type {...}` syntax) or surface them as misleading - // 0/0 rows. Excluding them keeps the report clean. + // statements. Excluding them keeps the report clean (would otherwise + // surface as misleading 0/0 rows). path.join(repoRoot, 'core/mcp/types.ts'), path.join(repoRoot, 'core/mcp/elicitationCreateMessage.ts'), path.join(repoRoot, 'core/mcp/samplingCreateMessage.ts'), path.join(repoRoot, 'core/mcp/sessionStorage.ts'), path.join(repoRoot, 'core/mcp/inspectorClientProtocol.ts'), // inspectorClientEventTarget.ts is types + a single empty-body class - // (extends TypedEventTarget). v8/istanbul records 0 statements for it. + // (extends TypedEventTarget). v8/istanbul records 0 statements for it + // today. TODO(#1243): drop this exclusion once the class gains real + // behavior as the v1.5 InspectorClient port progresses. path.join(repoRoot, 'core/mcp/inspectorClientEventTarget.ts'), path.join(repoRoot, 'core/mcp/__tests__/**'), ], @@ -73,17 +78,18 @@ export default defineConfig({ projects: [ { extends: true, + // Vitest projects don't inherit `resolve` from the parent, so we + // redeclare the shared aliases here. The extra `react` alias is + // required because we move the unit project root to repoRoot below + // (so vitest's coverage transformer can reach core/), and the repo + // root has no node_modules of its own — bare `react` imports from + // core/react/*.ts would otherwise fail to resolve. resolve: { alias: { - '@inspector/core': path.resolve(dirname, '../../core'), - // Bare-module override: core/react/* imports "react", which vite - // resolves by walking up from the file looking for node_modules/. - // We move the unit project root to repoRoot below, and the repo - // root has no node_modules of its own — so without this alias, - // imports from core/ can't find react. + ...sharedAliases, react: path.resolve(dirname, 'node_modules/react'), }, - dedupe: ['react', 'react-dom'], + dedupe: sharedDedupe, }, test: { name: 'unit',