@@ -460,26 +460,36 @@ export function formatAdvisoryCommand(advisory) {
460460
461461export function formatAnnotations ( blockingMutants , packageRoot , state = { total : 0 , perFile : new Map ( ) } ) {
462462 const annotations = [ ]
463+ const mutantsByLocation = new Map ( )
463464
464- for ( const mutant of blockingMutants . sort ( ( left , right ) => {
465+ for ( const mutant of [ ... blockingMutants ] . sort ( ( left , right ) => {
465466 const pathOrder = left . filePath . localeCompare ( right . filePath )
466467 return pathOrder || left . location . start . line - right . location . start . line
467468 } ) ) {
468469 const repositoryPath = path . posix . join ( packageRoot , mutant . filePath . replaceAll ( "\\" , "/" ) )
469470 const key = `${ repositoryPath } :${ mutant . location . start . line } `
471+ const group = mutantsByLocation . get ( key ) ?? { repositoryPath, mutants : [ ] }
472+ group . mutants . push ( mutant )
473+ mutantsByLocation . set ( key , group )
474+ }
475+
476+ for ( const [ key , { repositoryPath, mutants } ] of mutantsByLocation ) {
470477 const fileCount = state . perFile . get ( repositoryPath ) ?? 0
471- if ( annotations . some ( ( annotation ) => annotation . key === key ) || fileCount >= 7 || state . total >= 20 ) continue
478+ if ( fileCount >= 7 || state . total >= 20 ) continue
472479
480+ const mutant = mutants [ 0 ]
473481 const replacement = String ( mutant . replacement ?? "" )
474482 . replace ( / \s + / g, " " )
475483 . trim ( )
476484 . slice ( 0 , 160 )
485+ const location = `${ repositoryPath } :${ mutant . location . start . line } `
486+ const detail = `${ mutant . status } ${ mutant . mutatorName } mutant${ replacement ? ` (replacement: ${ replacement } )` : "" } `
477487 annotations . push ( {
478488 key,
479489 file : repositoryPath ,
480490 line : mutant . location . start . line ,
481491 message :
482- `${ mutant . status } ${ mutant . mutatorName } mutant ${ replacement ? ` (replacement: ${ replacement } )` : "" } . ` +
492+ `${ location } : ${ mutants . length === 1 ? detail : ` ${ mutants . length } mutation test gaps; example: ${ detail } ` } . ` +
483493 "See the job summary for the complete list and resolution guidance." ,
484494 } )
485495 state . perFile . set ( repositoryPath , fileCount + 1 )
@@ -652,16 +662,18 @@ export function evaluateReport(report, packageEntry) {
652662 "The result is inconclusive; consider fixing flaky or slow tests, or reducing the changed scope." ,
653663 )
654664 }
655- if ( counts . blocking . length > 0 ) {
656- advisories . push (
657- `${ packageEntry . id } has ${ counts . survived } surviving and ${ counts . noCoverage } uncovered changed-code mutants. ` +
658- "Consider adding or strengthening focused tests." ,
659- )
660- }
661665 return { ...counts , advisories }
662666}
663667
664- export function runManifest ( repoRoot , manifest , reportRoot ) {
668+ export function runManifest (
669+ repoRoot ,
670+ manifest ,
671+ reportRoot ,
672+ {
673+ runMutation = runStryker ,
674+ readMutationReport = ( reportPath ) => JSON . parse ( fs . readFileSync ( reportPath , "utf8" ) ) ,
675+ } = { } ,
676+ ) {
665677 const rows = [ ]
666678 const advisories = [ ...( manifest . advisories ?? [ ] ) ]
667679 const annotationState = { total : 0 , perFile : new Map ( ) }
@@ -677,7 +689,7 @@ export function runManifest(repoRoot, manifest, reportRoot) {
677689 if ( packageEntry . discoverRelatedTests ) {
678690 packageEntry . testFiles = discoverRelatedTestFiles ( repoRoot , packageEntry , reportDirectory )
679691 }
680- const preflightOutput = stripAnsi ( runStryker ( repoRoot , packageEntry , reportRoot , true ) )
692+ const preflightOutput = stripAnsi ( runMutation ( repoRoot , packageEntry , reportRoot , true ) )
681693 const mutantMatch = / I n s t r u m e n t e d \d + s o u r c e f i l e \( s \) w i t h ( \d + ) m u t a n t \( s \) / . exec ( preflightOutput )
682694 if ( ! mutantMatch ) throw new Error ( `${ packageEntry . id } preflight did not report a mutant count` )
683695 const generatedMutants = Number ( mutantMatch [ 1 ] )
@@ -707,9 +719,9 @@ export function runManifest(repoRoot, manifest, reportRoot) {
707719 continue
708720 }
709721
710- runStryker ( repoRoot , packageEntry , reportRoot , false )
722+ runMutation ( repoRoot , packageEntry , reportRoot , false )
711723 const jsonReportPath = path . join ( reportRoot , packageEntry . id , "mutation.json" )
712- const report = JSON . parse ( fs . readFileSync ( jsonReportPath , "utf8" ) )
724+ const report = readMutationReport ( jsonReportPath )
713725 packageEntry . testFiles = testsFromMutationReport ( report , packageEntry . testFiles )
714726 counts = evaluateReport ( report , packageEntry )
715727 for ( const annotation of formatAnnotations (
@@ -729,7 +741,7 @@ export function runManifest(repoRoot, manifest, reportRoot) {
729741 reportPath,
730742 changedLines : packageEntry . changedExecutableLines ,
731743 ...counts ,
732- result : counts . advisories . length > 0 ? "Advisory findings" : "Passed" ,
744+ result : counts . blocking . length > 0 || counts . advisories . length > 0 ? "Advisory findings" : "Passed" ,
733745 } )
734746 } catch ( error ) {
735747 advisories . push ( error . message )
0 commit comments