@@ -40,6 +40,9 @@ function fixture(options: {
4040 leaseError ?: unknown ;
4141 aheadBy ?: number ;
4242 compareError ?: unknown ;
43+ rebasedAheadBy ?: number ;
44+ rebasedBehindBy ?: number ;
45+ temporaryMergeable ?: boolean | null ;
4346} = { } ) {
4447 const calls : Call [ ] = [ ] ;
4548 let tempRef = "" ;
@@ -57,7 +60,15 @@ function fixture(options: {
5760 compareCommits : ( args : Record < string , unknown > ) => {
5861 record ( "repos.compareCommits" , args ) ;
5962 if ( options . compareError ) throw options . compareError ;
60- return { data : { ahead_by : options . aheadBy ?? 1 } } ;
63+ const isRebased = args . head === "rebased" ;
64+ return {
65+ data : {
66+ ahead_by : isRebased
67+ ? options . rebasedAheadBy ?? options . aheadBy ?? 1
68+ : options . aheadBy ?? 1 ,
69+ behind_by : isRebased ? options . rebasedBehindBy ?? 0 : 0 ,
70+ } ,
71+ } ;
6172 } ,
6273 } ,
6374 git : {
@@ -110,6 +121,9 @@ function fixture(options: {
110121 data : {
111122 number : 99 ,
112123 state : "open" ,
124+ mergeable : options . temporaryMergeable === undefined
125+ ? false
126+ : options . temporaryMergeable ,
113127 head : { ref : "fork" } ,
114128 base : { ref : tempRef } ,
115129 } ,
@@ -165,6 +179,7 @@ Deno.test("reverse-rebase verifies SHAs, updates base to merge result, and clean
165179 "repos.compareCommits" ,
166180 "pulls.create" ,
167181 "pulls.merge" ,
182+ "repos.compareCommits" ,
168183 "git.getRef" ,
169184 "git.getRef" ,
170185 "graphql" ,
@@ -186,9 +201,9 @@ Deno.test("reverse-rebase verifies SHAs, updates base to merge result, and clean
186201 ) ;
187202 assertEquals ( calls [ 3 ] . args . merge_method , "rebase" ) ;
188203 assertEquals ( calls [ 3 ] . args . sha , "fork-old" ) ;
189- assertMatch ( String ( calls [ 6 ] . args . query ) , / u p d a t e R e f s / ) ;
204+ assertMatch ( String ( calls [ 7 ] . args . query ) , / u p d a t e R e f s / ) ;
190205 assertEquals (
191- { ...calls [ 6 ] . args , query : undefined } ,
206+ { ...calls [ 7 ] . args , query : undefined } ,
192207 {
193208 query : undefined ,
194209 repositoryId : "repo-node" ,
@@ -198,7 +213,7 @@ Deno.test("reverse-rebase verifies SHAs, updates base to merge result, and clean
198213 force : true ,
199214 } ,
200215 ) ;
201- assertEquals ( calls [ 10 ] . args . ref , String ( create . ref ) . replace ( "refs/" , "" ) ) ;
216+ assertEquals ( calls [ 11 ] . args . ref , String ( create . ref ) . replace ( "refs/" , "" ) ) ;
202217} ) ;
203218
204219Deno . test ( "reverse-rebase never cleans up a ref it failed to create" , async ( ) => {
@@ -309,3 +324,21 @@ Deno.test("reverse-rebase cleans its temporary ref when comparison fails", async
309324 "git.deleteRef" ,
310325 ] ) ;
311326} ) ;
327+
328+ Deno . test ( "reverse-rebase rejects a result with injected temporary-base ancestry" , async ( ) => {
329+ const { calls, run } = fixture ( { rebasedAheadBy : 2 } ) ;
330+ assertEquals ( await run ( ) , false ) ;
331+ assert ( ! calls . some ( ( call ) => call . name === "graphql" ) ) ;
332+ assertEquals ( calls . at ( - 1 ) ?. name , "git.deleteRef" ) ;
333+ } ) ;
334+
335+ Deno . test ( "reverse-rebase does not label a policy 405 as a content conflict" , async ( ) => {
336+ const { calls, run } = fixture ( {
337+ mergeError : { status : 405 } ,
338+ temporaryMergeable : null ,
339+ } ) ;
340+ assertEquals ( await run ( ) , false ) ;
341+ assert ( ! calls . some ( ( call ) => call . name === "issues.update" ) ) ;
342+ assert ( calls . some ( ( call ) => call . name === "pulls.get" ) ) ;
343+ assertEquals ( calls . at ( - 1 ) ?. name , "git.deleteRef" ) ;
344+ } ) ;
0 commit comments