@@ -5,10 +5,9 @@ import {
55 CHANGED_LINE_COVERAGE_THRESHOLD ,
66 computeChangedCoverage ,
77 ignoredLineSet ,
8- isIncludableSource ,
9- isTestFile ,
108 parseLcov ,
119} from './model.ts' ;
10+ import { isInstrumentedPath , type CoverageConfig } from '../coverage-crap/stamp.ts' ;
1211
1312test ( 'parseLcov reads DA hits and BRDA taken, treating "-" as not taken' , ( ) => {
1413 const lcov = [
@@ -34,23 +33,39 @@ test('parseLcov reads DA hits and BRDA taken, treating "-" as not taken', () =>
3433 assert . equal ( index . get ( 'src/b.ts' ) ?. lineHits . get ( 10 ) , 1 ) ;
3534} ) ;
3635
37- test ( 'source/test classification matches the coverage include glob' , ( ) => {
38- assert . equal ( isIncludableSource ( 'src/core/x.ts' ) , true ) ;
39- assert . equal ( isIncludableSource ( 'src/core/x.test.ts' ) , false ) ;
40- assert . equal ( isIncludableSource ( 'src/core/__tests__/x.ts' ) , false ) ;
41- assert . equal ( isIncludableSource ( 'scripts/y.ts' ) , false ) ;
42- assert . equal ( isIncludableSource ( 'src/core/x.tsx' ) , false ) ;
36+ // The stamp's include/exclude, mirroring `test.coverage` in `vitest.config.ts`
37+ // for the paths these tests exercise: both coverage roots, test files and the
38+ // config's named exclusions out.
39+ const COVERAGE_CONFIG : CoverageConfig = {
40+ include : [ 'src/**/*.ts' , 'packages/*/src/**/*.ts' ] ,
41+ exclude : [
42+ '**/*.test.ts' ,
43+ '**/__tests__/**' ,
44+ '**/*-types.ts' ,
45+ '**/types.ts' ,
46+ 'src/sdk/**' ,
47+ 'src/bin.ts' ,
48+ ] ,
49+ } ;
50+
51+ test ( 'source/test classification matches the verified stamp selection' , ( ) => {
52+ assert . equal ( isInstrumentedPath ( 'src/core/x.ts' , COVERAGE_CONFIG ) , true ) ;
53+ assert . equal ( isInstrumentedPath ( 'src/core/x.test.ts' , COVERAGE_CONFIG ) , false ) ;
54+ assert . equal ( isInstrumentedPath ( 'src/core/__tests__/x.ts' , COVERAGE_CONFIG ) , false ) ;
55+ assert . equal ( isInstrumentedPath ( 'scripts/y.ts' , COVERAGE_CONFIG ) , false ) ;
56+ assert . equal ( isInstrumentedPath ( 'src/core/x.tsx' , COVERAGE_CONFIG ) , false ) ;
4357 // Workspace packages are the second coverage root.
44- assert . equal ( isIncludableSource ( 'packages/contracts/src/x.ts' ) , true ) ;
45- assert . equal ( isIncludableSource ( 'packages/contracts/src/deep/x.ts' ) , true ) ;
46- assert . equal ( isIncludableSource ( 'packages/contracts/src/x.test.ts' ) , false ) ;
47- assert . equal ( isIncludableSource ( 'packages/contracts/src/__tests__/x.ts' ) , false ) ;
48- assert . equal ( isIncludableSource ( 'packages/contracts/src/x.tsx' ) , false ) ;
49- assert . equal ( isIncludableSource ( 'packages/contracts/test/x.ts' ) , false ) ;
50- assert . equal ( isIncludableSource ( 'packages/contracts/x.ts' ) , false ) ;
51- assert . equal ( isTestFile ( 'src/a.test.ts' ) , true ) ;
52- assert . equal ( isTestFile ( 'src/__tests__/a.ts' ) , true ) ;
53- assert . equal ( isTestFile ( 'src/a.ts' ) , false ) ;
58+ assert . equal ( isInstrumentedPath ( 'packages/contracts/src/x.ts' , COVERAGE_CONFIG ) , true ) ;
59+ assert . equal ( isInstrumentedPath ( 'packages/contracts/src/deep/x.ts' , COVERAGE_CONFIG ) , true ) ;
60+ assert . equal ( isInstrumentedPath ( 'packages/contracts/src/x.test.ts' , COVERAGE_CONFIG ) , false ) ;
61+ assert . equal ( isInstrumentedPath ( 'packages/contracts/src/__tests__/x.ts' , COVERAGE_CONFIG ) , false ) ;
62+ assert . equal ( isInstrumentedPath ( 'packages/contracts/src/x.tsx' , COVERAGE_CONFIG ) , false ) ;
63+ assert . equal ( isInstrumentedPath ( 'packages/contracts/test/x.ts' , COVERAGE_CONFIG ) , false ) ;
64+ assert . equal ( isInstrumentedPath ( 'packages/contracts/x.ts' , COVERAGE_CONFIG ) , false ) ;
65+ // What the stamp excludes is out of scope by declaration, not merely unscored.
66+ assert . equal ( isInstrumentedPath ( 'src/sdk/thing.ts' , COVERAGE_CONFIG ) , false ) ;
67+ assert . equal ( isInstrumentedPath ( 'src/core/x-types.ts' , COVERAGE_CONFIG ) , false ) ;
68+ assert . equal ( isInstrumentedPath ( 'src/bin.ts' , COVERAGE_CONFIG ) , false ) ;
5469} ) ;
5570
5671test ( 'ignoredLineSet handles next, next N and start/stop ranges' , ( ) => {
@@ -98,6 +113,7 @@ test('gate fails when changed-line coverage is below threshold and lists offende
98113 const result = computeChangedCoverage ( {
99114 diffs : [ diff ( 'src/covered.ts' , [ 1 , 2 , 3 ] ) ] ,
100115 coverage,
116+ stamp : COVERAGE_CONFIG ,
101117 fileLines : ( ) => null ,
102118 } ) ;
103119 // lines 1 & 3 covered, line 2 uncovered -> 2/3 = 66.67% < 70.
@@ -118,6 +134,7 @@ test('workspace package source counts toward the gate like root source', () => {
118134 const result = computeChangedCoverage ( {
119135 diffs : [ diff ( 'packages/contracts/src/feature.ts' , [ 1 , 2 ] ) ] ,
120136 coverage : packageCoverage ,
137+ stamp : COVERAGE_CONFIG ,
121138 fileLines : ( ) => null ,
122139 } ) ;
123140 // 1/2 = 50% < 70: a package change can now fail the gate on its own.
@@ -132,6 +149,7 @@ test('non-executable added lines (absent from DA) never enter the denominator',
132149 const result = computeChangedCoverage ( {
133150 diffs : [ diff ( 'src/covered.ts' , [ 1 , 3 , 99 ] ) ] ,
134151 coverage,
152+ stamp : COVERAGE_CONFIG ,
135153 fileLines : ( ) => null ,
136154 } ) ;
137155 assert . equal ( result . totalLines , 2 ) ;
@@ -144,6 +162,7 @@ test('deleted files and docs-only changes are a trivial pass with null pct', ()
144162 const result = computeChangedCoverage ( {
145163 diffs : [ diff ( 'src/covered.ts' , [ 1 ] , true ) , diff ( 'README.md' , [ 1 , 2 ] ) ] ,
146164 coverage,
165+ stamp : COVERAGE_CONFIG ,
147166 fileLines : ( ) => null ,
148167 } ) ;
149168 assert . equal ( result . pct , null ) ;
@@ -155,6 +174,7 @@ test('waiver forces a pass but still reports the numbers', () => {
155174 const result = computeChangedCoverage ( {
156175 diffs : [ diff ( 'src/covered.ts' , [ 1 , 2 , 3 ] ) ] ,
157176 coverage,
177+ stamp : COVERAGE_CONFIG ,
158178 waived : true ,
159179 fileLines : ( ) => null ,
160180 } ) ;
@@ -163,7 +183,7 @@ test('waiver forces a pass but still reports the numbers', () => {
163183 assert . equal ( result . pct , 66.67 ) ;
164184} ) ;
165185
166- test ( 'an includable path whose new side is a symlink or gitlink is skipped, not read' , ( ) => {
186+ test ( 'an instrumented path whose new side is a symlink or gitlink is skipped, not read' , ( ) => {
167187 // A committed symlink like `tools/helper-tests/Sources -> ../helper/Sources` shows in the
168188 // diff as added text (its target), so it reaches this loop by path shape. Its working-tree
169189 // entry resolves to a directory, so a content read dies on EISDIR; reading the
@@ -176,6 +196,7 @@ test('an includable path whose new side is a symlink or gitlink is skipped, not
176196 diff ( 'src/covered.ts' , [ 1 , 2 , 3 ] ) ,
177197 ] ,
178198 coverage,
199+ stamp : COVERAGE_CONFIG ,
179200 fileLines : ( path ) => {
180201 readPaths . push ( path ) ;
181202 return null ;
@@ -188,10 +209,11 @@ test('an includable path whose new side is a symlink or gitlink is skipped, not
188209 assert . deepEqual ( result . excluded . files , [ ] ) ;
189210} ) ;
190211
191- test ( 'includable source absent from lcov counts as excluded-path code lines' , ( ) => {
212+ test ( 'instrumented source absent from lcov counts as excluded-path code lines' , ( ) => {
192213 const result = computeChangedCoverage ( {
193- diffs : [ diff ( 'src/sdk/thing .ts' , [ 1 , 2 , 3 ] ) ] ,
214+ diffs : [ diff ( 'src/missing .ts' , [ 1 , 2 , 3 ] ) ] ,
194215 coverage,
216+ stamp : COVERAGE_CONFIG ,
195217 fileLines : ( ) => [ 'const kept = 1;' , '' , '// a comment' ] ,
196218 } ) ;
197219 assert . equal ( result . totalLines , 0 ) ;
@@ -200,11 +222,25 @@ test('includable source absent from lcov counts as excluded-path code lines', ()
200222 assert . deepEqual ( result . excluded . files [ 0 ] ?. lines , [ 1 ] ) ;
201223} ) ;
202224
225+ test ( 'a path the stamp excludes is out of scope, not tallied' , ( ) => {
226+ const result = computeChangedCoverage ( {
227+ diffs : [ diff ( 'src/sdk/thing.ts' , [ 1 , 2 , 3 ] ) ] ,
228+ coverage,
229+ stamp : COVERAGE_CONFIG ,
230+ fileLines : ( ) => [ 'const kept = 1;' , '' , '// a comment' ] ,
231+ } ) ;
232+ assert . equal ( result . totalLines , 0 ) ;
233+ assert . equal ( result . excluded . totalLines , 0 ) ;
234+ assert . deepEqual ( result . excluded . files , [ ] ) ;
235+ assert . equal ( result . passed , true ) ;
236+ } ) ;
237+
203238test ( 'changed line suppressed by an ignore directive is tallied, not gated' , ( ) => {
204239 const cov = parseLcov ( [ 'SF:src/x.ts' , 'DA:1,1' , 'end_of_record' ] . join ( '\n' ) ) ;
205240 const result = computeChangedCoverage ( {
206241 diffs : [ diff ( 'src/x.ts' , [ 1 , 3 ] ) ] ,
207242 coverage : cov ,
243+ stamp : COVERAGE_CONFIG ,
208244 fileLines : ( ) => [ 'const a = 1;' , '/* v8 ignore next */' , 'const suppressed = 3;' ] ,
209245 } ) ;
210246 // Line 3 is code-like, dropped from DA by the directive on line 2, and inside
@@ -279,6 +315,7 @@ test('rename-only hunks owe no changed-line coverage; edited moves owe their edi
279315 uncoveredRecord ( 'src/moved-pure.ts' , 30 ) ,
280316 ] . join ( '\n' ) ,
281317 ) ,
318+ stamp : COVERAGE_CONFIG ,
282319 fileLines : ( ) => null ,
283320 } ) ;
284321 // 2 ordinary edits + 3 edited move lines; the 30-line pure move owes nothing.
0 commit comments