@@ -5,12 +5,8 @@ import os from 'node:os';
55import path from 'node:path' ;
66import { afterEach , beforeEach , test } from 'node:test' ;
77import { run } from './run.ts' ;
8- import {
9- beginCoverageRun ,
10- finishCoverageRun ,
11- type CoverageConfig ,
12- type RunSelection ,
13- } from '../coverage-crap/stamp.ts' ;
8+ import { beginCoverageRun , finishCoverageRun , type RunSelection } from '../coverage-crap/stamp.ts' ;
9+ import { COVERAGE_CONFIG } from './fixtures.ts' ;
1410import { beginStderrCapture , beginStdoutCapture } from '@agent-device/test-kit' ;
1511
1612let repo : string ;
@@ -29,23 +25,6 @@ function writeLcov(records: string): void {
2925 write ( 'coverage/lcov.info' , records ) ;
3026}
3127
32- /**
33- * What the fixture's coverage pass was told to instrument. Mirrors the
34- * `test.coverage` include/exclude in `vitest.config.ts` for the paths these
35- * tests exercise: both coverage roots, test files out, `src/sdk/**` out.
36- */
37- const COVERAGE_CONFIG : CoverageConfig = {
38- include : [ 'src/**/*.ts' , 'packages/*/src/**/*.ts' ] ,
39- exclude : [
40- '**/*.test.ts' ,
41- '**/__tests__/**' ,
42- '**/*-types.ts' ,
43- '**/types.ts' ,
44- 'src/sdk/**' ,
45- 'src/bin.ts' ,
46- ] ,
47- } ;
48-
4928/** What `pnpm test:coverage` leaves beside its reports: the stamp naming the run that wrote them. */
5029function writeStamp ( runSelection : RunSelection = 'full' ) : void {
5130 const outcome = finishCoverageRun (
@@ -252,6 +231,27 @@ test('refuses a report with no stamp beside it instead of scoring it', () => {
252231 assert . doesNotMatch ( out , / C h a n g e d - l i n e c o v e r a g e g a t e : / ) ;
253232} ) ;
254233
234+ test ( 'refusal fires before the waiver when the report has no stamp' , ( ) => {
235+ write ( 'src/feature.ts' , 'export const covered = 1;\nexport const uncovered = 2;\n' ) ;
236+ git ( 'add' , '-A' ) ;
237+ git ( 'commit' , '-q' , '-m' , 'feature' ) ;
238+ writeLcov ( 'SF:src/feature.ts\nDA:1,3\nDA:2,0\nend_of_record\n' ) ;
239+ // No stamp beside the report: the numbers are unattributable, so the waiver
240+ // has nothing to waive — it skips a failure, it does not bless a report.
241+ const previous = process . env . AGENT_DEVICE_COVERAGE_WAIVER ;
242+ process . env . AGENT_DEVICE_COVERAGE_WAIVER = 'true' ;
243+ try {
244+ const { code, out } = capture ( ( ) => run ( [ '--base' , 'main' ] , repo ) ) ;
245+ assert . equal ( code , 1 ) ;
246+ assert . match ( out , / n o t r u s t w o r t h y v e r d i c t / ) ;
247+ assert . match ( out , / c a r r i e s n o c o v e r a g e - r u n - s t a m p \. j s o n / ) ;
248+ assert . doesNotMatch ( out , / C h a n g e d - l i n e c o v e r a g e g a t e : / ) ;
249+ } finally {
250+ if ( previous === undefined ) delete process . env . AGENT_DEVICE_COVERAGE_WAIVER ;
251+ else process . env . AGENT_DEVICE_COVERAGE_WAIVER = previous ;
252+ }
253+ } ) ;
254+
255255test ( 'refuses a report whose stamp names an earlier commit' , ( ) => {
256256 write ( 'src/feature.ts' , 'export const covered = 1;\nexport const uncovered = 2;\n' ) ;
257257 git ( 'add' , '-A' ) ;
@@ -305,10 +305,12 @@ test('refuses a report written in another checkout instead of passing it as clea
305305 git ( 'commit' , '-q' , '-m' , 'feature' ) ;
306306 // Two checkouts of one commit share HEAD and bytes, so no stamp can tell them apart: the lcov
307307 // paths themselves must name the foreign root. A map like this joins none of this checkout's
308- // files, which without the check reads as "no file was measured" and passes 0/0.
308+ // files, which without the check reads as "no file was measured" and passes 0/0. The stamp here
309+ // is valid for this tree, so the foreign paths are the only defect the run can see.
309310 const foreign = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'cov-changed-foreign-' ) ) ;
310311 try {
311312 writeLcov ( `SF:${ foreign } /src/feature.ts\nDA:1,3\nDA:2,0\nend_of_record\n` ) ;
313+ writeStamp ( ) ;
312314 const { code, out } = capture ( ( ) => run ( [ '--base' , 'main' ] , repo ) ) ;
313315 assert . equal ( code , 1 ) ;
314316 assert . match ( out , / n o t r u s t w o r t h y v e r d i c t / ) ;
@@ -319,17 +321,19 @@ test('refuses a report written in another checkout instead of passing it as clea
319321 }
320322} ) ;
321323
322- test ( 'a file the stamp excludes is out of scope , not tallied as excluded ' , ( ) => {
324+ test ( 'a file the stamp excludes is tallied as excluded , not gated ' , ( ) => {
323325 write ( 'src/sdk/thing.ts' , 'export const kept = 1;\n' ) ;
324326 git ( 'add' , '-A' ) ;
325327 git ( 'commit' , '-q' , '-m' , 'sdk change' ) ;
326328 // No record for it in lcov: the run never measured it, by declaration. The
327- // gate owes nothing for it — neither a denominator line nor a tally entry.
329+ // gate owes nothing for it — but the added line still shows in the
330+ // non-gating excluded tally, so new logic under an exclude entry is visible.
328331 writeLcov ( 'SF:src/base.ts\nDA:1,1\nend_of_record\n' ) ;
329332 writeStamp ( ) ;
330333 const { code, out } = capture ( ( ) => run ( [ '--base' , 'main' ] , repo ) ) ;
331334 assert . equal ( code , 0 ) ;
332335 assert . match ( out , / C h a n g e d - l i n e c o v e r a g e g a t e : P A S S / ) ;
333336 assert . match ( out , / 0 \/ 0 \( n \/ a \) / ) ;
334- assert . match ( out , / C h a n g e d e x e c u t a b l e l i n e s e x c l u d e d \( n o n - g a t i n g \) \| 0 \| / ) ;
337+ assert . match ( out , / C h a n g e d e x e c u t a b l e l i n e s e x c l u d e d \( n o n - g a t i n g \) \| 1 \| / ) ;
338+ assert . match ( out , / e x c l u d e d ` s r c \/ s d k \/ t h i n g \. t s ` \[ e x c l u d e d - p a t h \] : 1 / ) ;
335339} ) ;
0 commit comments