@@ -2890,6 +2890,16 @@ async function prepareReviewContext(
28902890 throw new Error ( `captured_pr_base_changed: expected ${ String ( target . base_sha ) } , current ${ liveBase || "missing" } ` ) ;
28912891 }
28922892 const files = await githubRequestAllPages ( `https://api.github.com/repos/${ repo } /pulls/${ prNumber } /files` , token ) ;
2893+ const comparison = ( await githubRequest (
2894+ "GET" ,
2895+ `https://api.github.com/repos/${ repo } /compare/${ liveBase } ...${ liveHead } ` ,
2896+ token ,
2897+ ) ) as JsonObject ;
2898+ const mergeBase = String ( ( ( ( comparison . merge_base_commit as JsonObject | undefined ) || { } ) . sha ) || "" ) ;
2899+ if ( ! / ^ [ a - f 0 - 9 ] { 40 } $ / i. test ( mergeBase ) ) {
2900+ throw new Error ( "captured_pr_merge_base_missing" ) ;
2901+ }
2902+ const metadata = { ...summarizePr ( pr ) , merge_base_sha : mergeBase } ;
28932903
28942904 const fetchBase = runCommand ( [ config . hostGitBin , "fetch" , "--depth" , "1" , "origin" , liveBase ] , workspace , env , 180 ) ;
28952905 writeJsonAtomic ( join ( attemptDir , "fetch-pr-base.json" ) , redactedCommandResult ( fetchBase ) ) ;
@@ -2898,7 +2908,21 @@ async function prepareReviewContext(
28982908 kind : "pull_request" ,
28992909 pr_number : prNumber ,
29002910 fetch_error : fetchBase . stderr ,
2901- metadata : summarizePr ( pr ) ,
2911+ metadata,
2912+ files : summarizePrFiles ( files , new Map ( ) ) ,
2913+ } ;
2914+ }
2915+
2916+ const fetchMergeBase = mergeBase === liveBase
2917+ ? fetchBase
2918+ : runCommand ( [ config . hostGitBin , "fetch" , "--depth" , "1" , "origin" , mergeBase ] , workspace , env , 180 ) ;
2919+ writeJsonAtomic ( join ( attemptDir , "fetch-pr-merge-base.json" ) , redactedCommandResult ( fetchMergeBase ) ) ;
2920+ if ( fetchMergeBase . returncode !== 0 ) {
2921+ return {
2922+ kind : "pull_request" ,
2923+ pr_number : prNumber ,
2924+ fetch_error : fetchMergeBase . stderr ,
2925+ metadata,
29022926 files : summarizePrFiles ( files , new Map ( ) ) ,
29032927 } ;
29042928 }
@@ -2910,7 +2934,7 @@ async function prepareReviewContext(
29102934 kind : "pull_request" ,
29112935 pr_number : prNumber ,
29122936 fetch_error : fetch . stderr ,
2913- metadata : summarizePr ( pr ) ,
2937+ metadata,
29142938 files : summarizePrFiles ( files , new Map ( ) ) ,
29152939 } ;
29162940 }
@@ -2939,7 +2963,7 @@ async function prepareReviewContext(
29392963 if ( ! filename ) continue ;
29402964 const diffPaths = [ ...new Set ( [ String ( file . previous_filename || "" ) , filename ] . filter ( Boolean ) ) ] ;
29412965 const diff = runCommand (
2942- [ config . hostGitBin , "diff" , "--no-ext-diff" , "--unified=3" , liveBase , liveHead , "--" , ...diffPaths ] ,
2966+ [ config . hostGitBin , "diff" , "--no-ext-diff" , "--unified=3" , mergeBase , liveHead , "--" , ...diffPaths ] ,
29432967 workspace ,
29442968 env ,
29452969 180 ,
@@ -2962,7 +2986,7 @@ async function prepareReviewContext(
29622986 return {
29632987 kind : "pull_request" ,
29642988 pr_number : prNumber ,
2965- metadata : summarizePr ( pr ) ,
2989+ metadata,
29662990 files : summarizePrFiles ( files , localPatches ) ,
29672991 checkout : {
29682992 fetch_returncode : fetch . returncode ,
@@ -3042,6 +3066,7 @@ function reviewEvidence(reviewContext: JsonObject, reviewContextPath: string, ta
30423066 pr_number : reviewContext . pr_number ,
30433067 base_ref : metadata . base_ref ,
30443068 base_sha : metadata . base_sha ,
3069+ merge_base_sha : metadata . merge_base_sha ,
30453070 head_ref : metadata . head_ref ,
30463071 head_sha : metadata . head_sha ,
30473072 workspace_head_sha : checkout . workspace_head_sha ,
@@ -4003,6 +4028,7 @@ export function normalizeReviewPublication(
40034028 if ( result . status !== "success" ) validationIssues . push ( "runtime result was not successful" ) ;
40044029 if ( ! String ( evidence . head_sha || "" ) . trim ( ) ) validationIssues . push ( "PR head revision is missing" ) ;
40054030 if ( ! String ( evidence . base_sha || "" ) . trim ( ) ) validationIssues . push ( "PR base revision is missing" ) ;
4031+ if ( ! String ( evidence . merge_base_sha || "" ) . trim ( ) ) validationIssues . push ( "PR merge-base revision is missing" ) ;
40064032 if ( ! String ( evidence . workspace_head_sha || "" ) . trim ( ) ) validationIssues . push ( "checked-out revision is missing" ) ;
40074033 if ( evidence . workspace_head_sha !== evidence . head_sha ) validationIssues . push ( "checked-out revision does not match the captured PR head" ) ;
40084034 if ( ! String ( evidence . publication_workspace_head_sha || "" ) . trim ( ) ) validationIssues . push ( "post-run workspace revision is missing" ) ;
@@ -4427,6 +4453,7 @@ function publicationCommentBody(task: JsonObject, result: JsonObject, heading =
44274453 parts . push (
44284454 `- PR: #${ evidence . pr_number } ` ,
44294455 `- Base: \`${ evidence . base_ref } \` @ \`${ evidence . base_sha } \`` ,
4456+ `- Merge base: \`${ evidence . merge_base_sha } \`` ,
44304457 `- Head: \`${ evidence . head_ref } \` @ \`${ evidence . head_sha } \`` ,
44314458 `- Checked-out workspace HEAD: \`${ evidence . workspace_head_sha } \`` ,
44324459 `- Changed files supplied to agent: ${ evidence . changed_file_count } ` ,
0 commit comments