@@ -162,6 +162,48 @@ describe("test 3") {}
162162 expect ( report . byDomain [ 'auth' ] ?. hasDrift ) . toBe ( true ) ;
163163 } ) ;
164164
165+ it ( 'ignores tags pointing at scenarios that do not exist in the parsed specs' , async ( ) => {
166+ // Regression: example/fixture tags (e.g. a foreign "billing" domain) living
167+ // in the test suite must NOT count as coverage, must not appear in `covered`,
168+ // and must not inflate coveragePercent.
169+ const testDir = join ( tmpDir , 'spec-tests' , 'auth' ) ;
170+ await mkdir ( testDir , { recursive : true } ) ;
171+ await writeFile (
172+ join ( testDir , 'mixed.spec.ts' ) ,
173+ [
174+ // real
175+ '// openlore: {"domain":"auth","requirement":"UserLogin","scenario":"SuccessfulLogin"}' ,
176+ // bogus — domain/requirement/scenario not in AUTH_SPEC
177+ '// openlore: {"domain":"billing","requirement":"Invoice","scenario":"Paid"}' ,
178+ '// openlore: {"domain":"auth","requirement":"UserLogin","scenario":"DoesNotExist"}' ,
179+ ] . join ( '\n' )
180+ ) ;
181+
182+ const report = await analyzeTestCoverage ( { rootPath : tmpDir , testDirs : [ 'spec-tests' ] } ) ;
183+
184+ expect ( report . coveredScenarios ) . toBe ( 1 ) ; // only the real one
185+ expect ( report . coveragePercent ) . toBe ( 33.3 ) ; // 1 / 3, not 3/3
186+ expect ( report . covered . map ( ( c ) => c . scenarioName ) ) . toEqual ( [ 'SuccessfulLogin' ] ) ;
187+ expect ( report . covered . some ( ( c ) => c . domain === 'billing' ) ) . toBe ( false ) ;
188+ // invariant: covered + uncovered = total
189+ expect ( report . coveredScenarios + report . uncovered . length ) . toBe ( report . totalScenarios ) ;
190+ } ) ;
191+
192+ it ( 'dedupes a scenario tagged by multiple files' , async ( ) => {
193+ const testDir = join ( tmpDir , 'spec-tests' , 'auth' ) ;
194+ await mkdir ( testDir , { recursive : true } ) ;
195+ const tag = '// openlore: {"domain":"auth","requirement":"UserLogin","scenario":"SuccessfulLogin"}' ;
196+ await writeFile ( join ( testDir , 'a.spec.ts' ) , tag + '\ndescribe("a") {}' ) ;
197+ await writeFile ( join ( testDir , 'b.spec.ts' ) , tag + '\ndescribe("b") {}' ) ;
198+
199+ const report = await analyzeTestCoverage ( { rootPath : tmpDir , testDirs : [ 'spec-tests' ] } ) ;
200+
201+ expect ( report . coveredScenarios ) . toBe ( 1 ) ;
202+ expect ( report . taggedScenarios ) . toBe ( 1 ) ;
203+ expect ( report . covered ) . toHaveLength ( 1 ) ;
204+ expect ( report . byDomain [ 'auth' ] . covered ) . toBe ( 1 ) ;
205+ } ) ;
206+
165207 it ( 'supports Python # openlore: tags' , async ( ) => {
166208 const testDir = join ( tmpDir , 'spec-tests' , 'auth' ) ;
167209 await mkdir ( testDir , { recursive : true } ) ;
0 commit comments