@@ -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" ) )
@@ -524,6 +526,49 @@ describe("selectFromGit", () => {
524526 fs . rmSync ( repo , { recursive : true , force : true } )
525527 }
526528 } )
529+
530+ it ( "does not charge intervening base-branch changes to the pull request" , ( ) => {
531+ const repo = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "stryker-stale-base-" ) )
532+ const runGit = ( ...args ) => execFileSync ( "git" , args , { cwd : repo , encoding : "utf8" } ) . trim ( )
533+
534+ try {
535+ runGit ( "init" , "--initial-branch=main" )
536+ runGit ( "config" , "user.name" , "Mutation Test" )
537+ runGit ( "config" , "user.email" , "[email protected] " ) 538+ fs . mkdirSync ( path . join ( repo , "packages/core/src" ) , { recursive : true } )
539+ fs . writeFileSync ( path . join ( repo , "packages/core/src/pr.ts" ) , "export const pr = false\n" )
540+ fs . writeFileSync ( path . join ( repo , "packages/core/src/base.ts" ) , "export const base = false\n" )
541+ runGit ( "add" , "." )
542+ runGit ( "commit" , "-m" , "initial" )
543+ const staleBaseSha = runGit ( "rev-parse" , "HEAD" )
544+
545+ runGit ( "checkout" , "-b" , "feature" )
546+ fs . writeFileSync ( path . join ( repo , "packages/core/src/pr.ts" ) , "export const pr = true\n" )
547+ runGit ( "commit" , "-am" , "change pull request" )
548+
549+ runGit ( "checkout" , "main" )
550+ fs . writeFileSync ( path . join ( repo , "packages/core/src/base.ts" ) , "export const base = true\n" )
551+ runGit ( "commit" , "-am" , "advance base branch" )
552+ const currentBaseSha = runGit ( "rev-parse" , "HEAD" )
553+ runGit ( "merge" , "--no-ff" , "feature" , "-m" , "synthetic pull request merge" )
554+ const mergeSha = runGit ( "rev-parse" , "HEAD" )
555+ const mergeResultBaseSha = runGit ( "rev-parse" , `${ mergeSha } ^1` )
556+ assert . equal ( mergeResultBaseSha , currentBaseSha )
557+
558+ assert . deepEqual (
559+ selectFromGit ( repo , staleBaseSha , mergeSha ) . packages [ 0 ] . files . map ( ( { path : filePath } ) => filePath ) ,
560+ [ "packages/core/src/base.ts" , "packages/core/src/pr.ts" ] ,
561+ )
562+ assert . deepEqual (
563+ selectFromGit ( repo , mergeResultBaseSha , mergeSha ) . packages [ 0 ] . files . map (
564+ ( { path : filePath } ) => filePath ,
565+ ) ,
566+ [ "packages/core/src/pr.ts" ] ,
567+ )
568+ } finally {
569+ fs . rmSync ( repo , { recursive : true , force : true } )
570+ }
571+ } )
527572} )
528573
529574describe ( "mutation exclusions" , ( ) => {
0 commit comments