@@ -57,6 +57,8 @@ describe("mutation testing workflow", () => {
5757 assert . ok ( ! workflow . includes ( "ref: ${{ github.event.pull_request.head.sha }}" ) )
5858 assert . ok ( workflow . includes ( "HEAD_SHA: ${{ github.sha }}" ) )
5959 assert . ok ( ! workflow . includes ( "HEAD_SHA: ${{ github.event.pull_request.head.sha }}" ) )
60+ assert . ok ( workflow . includes ( 'BASE_SHA="$(git rev-parse "$HEAD_SHA^1")"' ) )
61+ assert . ok ( ! workflow . includes ( "github.event.pull_request.base.sha" ) )
6062 assert . ok ( workflow . includes ( "steps.mutation_report.outputs.artifact-url" ) )
6163 assert . ok ( workflow . includes ( "open the package's mutation.html file" ) )
6264 assert . ok ( workflow . includes ( "Enforce executable-line scope and run advisory mutation testing" ) )
@@ -444,6 +446,49 @@ describe("selectFromGit", () => {
444446 fs . rmSync ( repo , { recursive : true , force : true } )
445447 }
446448 } )
449+
450+ it ( "does not charge intervening base-branch changes to the pull request" , ( ) => {
451+ const repo = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "stryker-stale-base-" ) )
452+ const runGit = ( ...args ) => execFileSync ( "git" , args , { cwd : repo , encoding : "utf8" } ) . trim ( )
453+
454+ try {
455+ runGit ( "init" , "--initial-branch=main" )
456+ runGit ( "config" , "user.name" , "Mutation Test" )
457+ runGit ( "config" , "user.email" , "[email protected] " ) 458+ fs . mkdirSync ( path . join ( repo , "packages/core/src" ) , { recursive : true } )
459+ fs . writeFileSync ( path . join ( repo , "packages/core/src/pr.ts" ) , "export const pr = false\n" )
460+ fs . writeFileSync ( path . join ( repo , "packages/core/src/base.ts" ) , "export const base = false\n" )
461+ runGit ( "add" , "." )
462+ runGit ( "commit" , "-m" , "initial" )
463+ const staleBaseSha = runGit ( "rev-parse" , "HEAD" )
464+
465+ runGit ( "checkout" , "-b" , "feature" )
466+ fs . writeFileSync ( path . join ( repo , "packages/core/src/pr.ts" ) , "export const pr = true\n" )
467+ runGit ( "commit" , "-am" , "change pull request" )
468+
469+ runGit ( "checkout" , "main" )
470+ fs . writeFileSync ( path . join ( repo , "packages/core/src/base.ts" ) , "export const base = true\n" )
471+ runGit ( "commit" , "-am" , "advance base branch" )
472+ const currentBaseSha = runGit ( "rev-parse" , "HEAD" )
473+ runGit ( "merge" , "--no-ff" , "feature" , "-m" , "synthetic pull request merge" )
474+ const mergeSha = runGit ( "rev-parse" , "HEAD" )
475+ const mergeResultBaseSha = runGit ( "rev-parse" , `${ mergeSha } ^1` )
476+ assert . equal ( mergeResultBaseSha , currentBaseSha )
477+
478+ assert . deepEqual (
479+ selectFromGit ( repo , staleBaseSha , mergeSha ) . packages [ 0 ] . files . map ( ( { path : filePath } ) => filePath ) ,
480+ [ "packages/core/src/base.ts" , "packages/core/src/pr.ts" ] ,
481+ )
482+ assert . deepEqual (
483+ selectFromGit ( repo , mergeResultBaseSha , mergeSha ) . packages [ 0 ] . files . map (
484+ ( { path : filePath } ) => filePath ,
485+ ) ,
486+ [ "packages/core/src/pr.ts" ] ,
487+ )
488+ } finally {
489+ fs . rmSync ( repo , { recursive : true , force : true } )
490+ }
491+ } )
447492} )
448493
449494describe ( "mutation exclusions" , ( ) => {
0 commit comments