@@ -7,10 +7,11 @@ const since = Date.parse("2026-09-10T10:00:00Z");
77const review : Review = { id : 1 , user : { login : "alice" } , state : "APPROVED" , commit_id : "head" , submitted_at : "2026-09-10T11:00:00Z" } ;
88const comment : DatedComment = { id : 2 , user : { login : "alice" } , body : "/merge" , created_at : "2026-09-10T11:00:00Z" , updated_at : "2026-09-10T11:00:00Z" } ;
99const policy = { enabled : true , method : "squash" as const , comments : [ "/merge" , "jest git, możesz mergować" ] } ;
10- test ( "approvals must reference the published head and must not be stale or superseded " , ( ) => {
10+ test ( "reviews must reference the published head and must not be superseded or unsubmitted " , ( ) => {
1111 assert . deepEqual ( approvalAuthors ( [ review ] , [ ] , "head" , since , policy . comments ) , [ "alice" ] ) ;
1212 assert . deepEqual ( approvalAuthors ( [ review ] , [ ] , "new-head" , since , policy . comments ) , [ ] ) ;
13- assert . deepEqual ( approvalAuthors ( [ review ] , [ ] , "head" , since + 9_000_000 , policy . comments ) , [ ] ) ;
13+ assert . deepEqual ( approvalAuthors ( [ review ] , [ ] , "head" , since + 9_000_000 , policy . comments ) , [ "alice" ] ) ;
14+ assert . deepEqual ( approvalAuthors ( [ { ...review , submitted_at : null } ] , [ ] , "head" , since , policy . comments ) , [ ] ) ;
1415 for ( const state of [ "CHANGES_REQUESTED" , "DISMISSED" ] ) {
1516 assert . deepEqual ( approvalAuthors ( [ review , { ...review , id : 3 , state } ] , [ ] , "head" , since , policy . comments ) , [ ] ) ;
1617 }
@@ -42,6 +43,17 @@ test("merge API requires an allowed writer and pins the verified SHA", async ()
4243 }
4344 const stranger = api ( ) ; assert . equal ( await stranger . github . mergeApproved ( "o/r" , 2 , "head" , since , [ "bob" ] , policy ) , false ) ; assert . equal ( stranger . writes . length , 0 ) ;
4445} ) ;
46+ test ( "approval of the same SHA survives delayed publication, but an old merge comment cannot authorize it" , async ( ) => {
47+ const publishedLater = since + 9_000_000 ;
48+ const f = api ( ) ;
49+ assert . equal ( await f . github . mergeApproved ( "o/r" , 2 , "head" , publishedLater , [ "alice" ] , policy ) , true ) ;
50+ assert . equal ( f . writes . length , 1 ) ; assert . equal ( f . writes [ 0 ] ! . body . sha , "head" ) ;
51+ assert . deepEqual ( approvalAuthors ( [ ] , [ comment ] , "head" , publishedLater , policy . comments ) , [ ] ) ;
52+ assert . deepEqual ( approvalAuthors ( [ review ] , [ ] , "different-head" , publishedLater , policy . comments ) , [ ] ) ;
53+ for ( const state of [ "DISMISSED" , "CHANGES_REQUESTED" ] ) {
54+ assert . deepEqual ( approvalAuthors ( [ review , { ...review , id : 3 , state } ] , [ comment ] , "head" , publishedLater , policy . comments ) , [ ] ) ;
55+ }
56+ } ) ;
4557test ( "unready checks defer merging and an already merged PR reconciles without another PUT" , async ( ) => {
4658 const f = api ( { mergeable_state : "unstable" } ) ; await assert . rejects ( f . github . mergeApproved ( "o/r" , 2 , "head" , since , [ "alice" ] , policy ) , / n o t r e a d y / ) ; assert . equal ( f . writes . length , 0 ) ;
4759 const failed = api ( { mergeResult : false } ) ; await assert . rejects ( failed . github . mergeApproved ( "o/r" , 2 , "head" , since , [ "alice" ] , policy ) , / d i d n o t m e r g e / ) ;
0 commit comments