@@ -43,7 +43,7 @@ function fixture() {
4343 const pr = {
4444 state : 'open' ,
4545 head : { ref : 'foundation' , sha : head , repo : { full_name : 'example/repo' } } ,
46- base : { sha : base } ,
46+ base : { ref : 'parent' , sha : base } ,
4747 }
4848 return { root, repo, base, before, head, pr }
4949}
@@ -96,6 +96,17 @@ describe('diff audit base selection', () => {
9696 expect ( git ( data . repo , 'diff' , '--name-only' , data . before , 'HEAD' ) ) . toBe ( 'upstream.sql' )
9797 } )
9898
99+ it ( 'pins the current base branch when the PR snapshot still reports an older base SHA' , ( ) => {
100+ const data = fixture ( )
101+ const cachedBase = git ( data . repo , 'rev-parse' , `${ data . base } ^` )
102+ const result = resolveBase ( data , {
103+ PR_RESPONSE : JSON . stringify ( [ [ { ...data . pr , base : { ...data . pr . base , sha : cachedBase } } ] ] ) ,
104+ } )
105+ expect ( result . status , result . stderr ) . toBe ( 0 )
106+ expect ( result . output ) . toBe ( `ref=${ data . base } ` )
107+ expect ( git ( data . repo , 'rev-parse' , 'FETCH_HEAD' ) ) . toBe ( data . base )
108+ } )
109+
99110 it ( 'fails closed when multiple open PRs across pages claim the dispatched branch' , ( ) => {
100111 const data = fixture ( )
101112 const result = resolveBase ( data , { PR_RESPONSE : JSON . stringify ( [ [ data . pr ] , [ data . pr ] ] ) } )
@@ -114,7 +125,9 @@ describe('diff audit base selection', () => {
114125 if ( failure === 'tag' ) overrides . GITHUB_REF_TYPE = 'tag'
115126 if ( failure === 'api' ) overrides . API_EXIT = '73'
116127 if ( failure === 'invalid-base' )
117- overrides . PR_RESPONSE = JSON . stringify ( [ [ { ...data . pr , base : { sha : 'HEAD~1' } } ] ] )
128+ overrides . PR_RESPONSE = JSON . stringify ( [
129+ [ { ...data . pr , base : { ref : 'HEAD~1' , sha : 'HEAD~1' } } ] ,
130+ ] )
118131 if ( failure === 'fetch' )
119132 git ( data . repo , 'remote' , 'set-url' , 'origin' , join ( data . root , 'missing.git' ) )
120133 const result = resolveBase ( data , overrides )
0 commit comments