Skip to content

Commit 25c6ba3

Browse files
committed
fix(test): include workspace packages in changed-line coverage
The full Vitest coverage run instruments both root `src/` and `packages/*/src/**`, but the changed-line gate's prefilter rejected every package path before consulting LCOV. A PR could add uncovered lines to contracts, selectors, kernel, or provider packages while the 70% changed-line gate reported no package denominator. Make the source-root predicate package-generic so it accepts both coverage roots, while package tests (`.test.ts`, `__tests__/`), package-level `test/`, and `.tsx` stay excluded as before. Scoring, waivers, the excluded-line tally, and branch reporting are unchanged. Pinned at both levels: the classification matrix and a pure-model scoring regression in model.test.ts, plus a temporary-repository regression in run.test.ts proving the executable gate fails and names the uncovered package path and line. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HgngjVMdk2eSKQ9d1gYLGo
1 parent 057f0e6 commit 25c6ba3

3 files changed

Lines changed: 53 additions & 8 deletions

File tree

‎scripts/coverage-changed/model.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ test('source/test classification matches the coverage include glob', () => {
8989
assert.equal(isIncludableSource('src/core/__tests__/x.ts'), false);
9090
assert.equal(isIncludableSource('scripts/y.ts'), false);
9191
assert.equal(isIncludableSource('src/core/x.tsx'), false);
92+
// Workspace packages are the second coverage root.
93+
assert.equal(isIncludableSource('packages/contracts/src/x.ts'), true);
94+
assert.equal(isIncludableSource('packages/contracts/src/deep/x.ts'), true);
95+
assert.equal(isIncludableSource('packages/contracts/src/x.test.ts'), false);
96+
assert.equal(isIncludableSource('packages/contracts/src/__tests__/x.ts'), false);
97+
assert.equal(isIncludableSource('packages/contracts/src/x.tsx'), false);
98+
assert.equal(isIncludableSource('packages/contracts/test/x.ts'), false);
99+
assert.equal(isIncludableSource('packages/contracts/x.ts'), false);
92100
assert.equal(isTestFile('src/a.test.ts'), true);
93101
assert.equal(isTestFile('src/__tests__/a.ts'), true);
94102
assert.equal(isTestFile('src/a.ts'), false);
@@ -147,6 +155,23 @@ test('gate fails when changed-line coverage is below threshold and lists offende
147155
assert.equal(result.branch.covered, 1);
148156
});
149157

158+
test('workspace package source counts toward the gate like root source', () => {
159+
const packageCoverage = parseLcov(
160+
['SF:packages/contracts/src/feature.ts', 'DA:1,4', 'DA:2,0', 'end_of_record'].join('\n'),
161+
);
162+
const result = computeChangedCoverage({
163+
diffs: [diff('packages/contracts/src/feature.ts', [1, 2])],
164+
coverage: packageCoverage,
165+
fileLines: () => null,
166+
});
167+
// 1/2 = 50% < 70: a package change can now fail the gate on its own.
168+
assert.equal(result.totalLines, 2);
169+
assert.equal(result.coveredLines, 1);
170+
assert.equal(result.passed, false);
171+
assert.equal(result.offenders[0]?.path, 'packages/contracts/src/feature.ts');
172+
assert.deepEqual(result.offenders[0]?.uncoveredLines, [2]);
173+
});
174+
150175
test('non-executable added lines (absent from DA) never enter the denominator', () => {
151176
const result = computeChangedCoverage({
152177
diffs: [diff('src/covered.ts', [1, 3, 99])],

‎scripts/coverage-changed/model.ts‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
// the gate is deterministic against renames and deletes. run.ts owns all I/O.
55
//
66
// The coverable universe is the lcov report itself, not a second copy of
7-
// vitest's exclude globs: coverage runs with `all` on, so every includable
8-
// `src/**/*.ts` file appears in lcov even when untested. A changed includable
9-
// file ABSENT from lcov was dropped by an exclude glob — reported (non-gating)
10-
// so exclusions cannot silently absorb new logic.
7+
// vitest's exclude globs: coverage runs with `all` on, so every includable file
8+
// under either coverage root (`src/**/*.ts` and `packages/*/src/**/*.ts`)
9+
// appears in lcov even when untested. A changed includable file ABSENT from
10+
// lcov was dropped by an exclude glob — reported (non-gating) so exclusions
11+
// cannot silently absorb new logic.
1112

1213
// Single source of truth for the gate. Changed-line coverage below this
1314
// percentage fails the Coverage CI job (unless waived).
@@ -149,15 +150,20 @@ export function parseUnifiedDiff(diff: string): ChangedFileDiff[] {
149150
return files;
150151
}
151152

152-
// Vitest coverage `include` is `src/**/*.ts`. Test files are excluded there and
153-
// carry no product logic, so they never count toward the gate or the excluded
154-
// tally (which exists to surface hidden logic, not test code).
153+
// Vitest coverage `include` spans two roots: `src/**/*.ts` and
154+
// `packages/*/src/**/*.ts`. Test files are excluded there and carry no product
155+
// logic, so they never count toward the gate or the excluded tally (which
156+
// exists to surface hidden logic, not test code).
155157
export function isTestFile(path: string): boolean {
156158
return /\.test\.ts$/.test(path) || /(^|\/)__tests__\//.test(path);
157159
}
158160

161+
// Both coverage roots, package-generic so a new workspace needs no edit here.
162+
// Anything outside them — scripts, package-level `test/`, `.tsx` — stays out.
163+
const SOURCE_ROOT = /^(?:packages\/[^/]+\/)?src\/.*\.ts$/;
164+
159165
export function isIncludableSource(path: string): boolean {
160-
return /^src\/.*\.ts$/.test(path) && !isTestFile(path);
166+
return SOURCE_ROOT.test(path) && !isTestFile(path);
161167
}
162168

163169
// A changed line looks like product code (not blank, not a comment-only line).

‎scripts/coverage-changed/run.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ test('fails when a changed source line is uncovered and names that line', () =>
8383
assert.match(out, /`src\/feature\.ts`: 2/);
8484
});
8585

86+
test('fails when a changed workspace package line is uncovered and names that line', () => {
87+
write(
88+
'packages/contracts/src/feature.ts',
89+
'export const covered = 1;\nexport const uncovered = 2;\n',
90+
);
91+
git('add', '-A');
92+
git('commit', '-q', '-m', 'package feature');
93+
writeLcov('SF:packages/contracts/src/feature.ts\nDA:1,3\nDA:2,0\nend_of_record\n');
94+
const { code, out } = capture(() => run(['--base', 'main'], repo));
95+
assert.equal(code, 1);
96+
assert.match(out, /Changed-line coverage gate: FAIL/);
97+
assert.match(out, /`packages\/contracts\/src\/feature\.ts`: 2/);
98+
});
99+
86100
test('waiver env keeps the job green, still reporting numbers to the job summary', () => {
87101
write('src/feature.ts', 'export const covered = 1;\nexport const uncovered = 2;\n');
88102
git('add', '-A');

0 commit comments

Comments
 (0)