From 04cdc337317252bee5240e1dd505155301203baf Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 20 Apr 2026 23:34:21 +0100 Subject: [PATCH] test: fix unit coverage scope --- docs/reference/test.md | 2 +- test/vitest/vitest.shared.config.ts | 1 - test/vitest/vitest.unit.config.ts | 17 ++++++++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/docs/reference/test.md b/docs/reference/test.md index 2752ddf0b4d..d636f2fecb0 100644 --- a/docs/reference/test.md +++ b/docs/reference/test.md @@ -10,7 +10,7 @@ title: "Tests" - Full testing kit (suites, live, Docker): [Testing](/help/testing) - `pnpm test:force`: Kills any lingering gateway process holding the default control port, then runs the full Vitest suite with an isolated gateway port so server tests don’t collide with a running instance. Use this when a prior gateway run left port 18789 occupied. -- `pnpm test:coverage`: Runs the unit suite with V8 coverage (via `vitest.unit.config.ts`). Global thresholds are 70% lines/branches/functions/statements. Coverage excludes integration-heavy entrypoints (CLI wiring, gateway/telegram bridges, webchat static server) to keep the target focused on unit-testable logic. +- `pnpm test:coverage`: Runs the unit suite with V8 coverage (via `vitest.unit.config.ts`). This is a loaded-file unit coverage gate, not whole-repo all-file coverage. Thresholds are 70% lines/functions/statements and 55% branches. Because `coverage.all` is false, the gate measures files loaded by the unit coverage suite instead of treating every split-lane source file as uncovered. - `pnpm test:coverage:changed`: Runs unit coverage only for files changed since `origin/main`. - `pnpm test:changed`: expands changed git paths into scoped Vitest lanes when the diff only touches routable source/test files. Config/setup changes still fall back to the native root projects run so wiring edits rerun broadly when needed. - `pnpm changed:lanes`: shows the architectural lanes triggered by the diff against `origin/main`. diff --git a/test/vitest/vitest.shared.config.ts b/test/vitest/vitest.shared.config.ts index 86d3a050ee7..6b752e79131 100644 --- a/test/vitest/vitest.shared.config.ts +++ b/test/vitest/vitest.shared.config.ts @@ -254,7 +254,6 @@ export const sharedVitestConfig = { branches: 55, statements: 70, }, - include: ["./src/**/*.ts"], exclude: [ `${BUNDLED_PLUGIN_ROOT_DIR}/**`, "apps/**", diff --git a/test/vitest/vitest.unit.config.ts b/test/vitest/vitest.unit.config.ts index 4e39c34d9e6..583d7129972 100644 --- a/test/vitest/vitest.unit.config.ts +++ b/test/vitest/vitest.unit.config.ts @@ -1,4 +1,4 @@ -import { defineProject } from "vitest/config"; +import { defineConfig } from "vitest/config"; import { loadPatternListFromEnv, narrowIncludePatternsForCli } from "./vitest.pattern-file.ts"; import { resolveVitestIsolation } from "./vitest.scoped-config.ts"; import { @@ -50,7 +50,8 @@ export function createUnitVitestConfigWithOptions( } return ![...protectedIncludeFiles].some((file) => pattern === file || pattern.endsWith("/**")); }); - return defineProject({ + const extraExcludePatterns = options.extraExcludePatterns ?? []; + return defineConfig({ ...sharedVitestConfig, test: { ...sharedTest, @@ -70,10 +71,20 @@ export function createUnitVitestConfigWithOptions( ...exclude, ...baseExcludePatterns, ...unitFastTestFiles, - ...(options.extraExcludePatterns ?? []), + ...extraExcludePatterns, ...loadExtraExcludePatternsFromEnv(env), ]), ], + coverage: { + ...sharedTest.coverage, + exclude: [ + ...new Set([ + ...(sharedTest.coverage?.exclude ?? []), + ...baseExcludePatterns, + ...extraExcludePatterns, + ]), + ], + }, ...(cliIncludePatterns !== null ? { passWithNoTests: true } : {}), }, });