@@ -574,6 +574,7 @@ const checkContextsPage = (
574574 } ) ;
575575
576576const pullRequestRefs = encodeJson ( { base : { sha : "a1b2c3d" } , head : { sha : "b1c2d3e" } } ) ;
577+ const pullRequestMergeBase = encodeJson ( { merge_base_commit : { sha : "c1d2e3f" } } ) ;
577578
578579const crossRepositoryDetail = ( headRefOid = "abc123" ) =>
579580 coreResponse ( {
@@ -2856,6 +2857,34 @@ layer("GitHubPullRequestApi.layer", (it) => {
28562857 } ) ,
28572858 ) ;
28582859
2860+ it . effect ( "expands a pull request file from its merge base, not the moved base tip" , ( ) =>
2861+ Effect . gen ( function * ( ) {
2862+ const answers : Record < string , string > = {
2863+ "repos/acme/web/pulls/7" : pullRequestRefs ,
2864+ "repos/acme/web/compare/a1b2c3d...b1c2d3e?per_page=1&page=2" : pullRequestMergeBase ,
2865+ "repos/acme/web/contents/src/a.ts?ref=a1b2c3d" : "base tip\n" ,
2866+ "repos/acme/web/contents/src/a.ts?ref=c1d2e3f" : "merge base\n" ,
2867+ "repos/acme/web/contents/src/a.ts?ref=b1c2d3e" : "head\n" ,
2868+ } ;
2869+ mockedExecute . mockImplementation ( ( call ) =>
2870+ Effect . succeed ( output ( call . kind === "rest" ? ( answers [ call . path ] ?? "" ) : "" ) ) ,
2871+ ) ;
2872+ const cli = yield * GitHubPullRequestApi . GitHubPullRequestApi ;
2873+
2874+ const contents = yield * cli . getPullRequestDiffFileContents ( {
2875+ cwd : "/w" ,
2876+ repository : "acme/web" ,
2877+ host : "github.com" ,
2878+ number : 7 ,
2879+ changeType : "change" ,
2880+ oldPath : "src/a.ts" ,
2881+ newPath : "src/a.ts" ,
2882+ } ) ;
2883+
2884+ expect ( contents ) . toEqual ( { oldContents : "merge base\n" , newContents : "head\n" } ) ;
2885+ } ) ,
2886+ ) ;
2887+
28592888 it . effect ( "reports unusable diff revisions as a structured error" , ( ) =>
28602889 Effect . gen ( function * ( ) {
28612890 mockedExecute . mockReturnValueOnce ( Effect . succeed ( output ( "not-a-sha\tstill-not-a-sha\n" ) ) ) ;
@@ -2885,6 +2914,7 @@ layer("GitHubPullRequestApi.layer", (it) => {
28852914 it . effect ( "reports undecodable diff file contents as binary" , ( ) =>
28862915 Effect . gen ( function * ( ) {
28872916 mockedExecute . mockReturnValueOnce ( Effect . succeed ( output ( pullRequestRefs ) ) ) ;
2917+ mockedExecute . mockReturnValueOnce ( Effect . succeed ( output ( pullRequestMergeBase ) ) ) ;
28882918 mockedExecute . mockReturnValueOnce ( Effect . succeed ( output ( "binary�contents" , false , true ) ) ) ;
28892919 const cli = yield * GitHubPullRequestApi . GitHubPullRequestApi ;
28902920
@@ -2911,6 +2941,7 @@ layer("GitHubPullRequestApi.layer", (it) => {
29112941 it . effect ( "returns valid text containing a literal replacement character" , ( ) =>
29122942 Effect . gen ( function * ( ) {
29132943 mockedExecute . mockReturnValueOnce ( Effect . succeed ( output ( pullRequestRefs ) ) ) ;
2944+ mockedExecute . mockReturnValueOnce ( Effect . succeed ( output ( pullRequestMergeBase ) ) ) ;
29142945 mockedExecute . mockReturnValueOnce ( Effect . succeed ( output ( "before�after" ) ) ) ;
29152946 const cli = yield * GitHubPullRequestApi . GitHubPullRequestApi ;
29162947
0 commit comments