@@ -11,7 +11,70 @@ function diff(path: string): PullRequestDiffResult {
1111 } ;
1212}
1313
14+ function withheldDiff ( ) : PullRequestDiffResult {
15+ return {
16+ patch : "diff --git a/large.ts b/large.ts\n--- a/large.ts\n+++ b/large.ts\n" ,
17+ truncated : true ,
18+ nextCursor : null ,
19+ omittedFileStats : [ { path : "large.ts" , additions : 3000 , deletions : 1800 } ] ,
20+ } ;
21+ }
22+
1423describe ( "paged mobile pull request diffs" , ( ) => {
24+ it ( "withheld PR hunks must retain provider line counts" , ( ) => {
25+ const result = withheldDiff ( ) ;
26+ const cache = new WeakMap < PullRequestDiffResult , ReviewParsedDiff > ( ) ;
27+ const pages = [ { cursor : null , result } ] ;
28+ const parsed = combinePullRequestDiffPages ( pages , cache , "pr" ) ;
29+ if ( parsed . kind !== "files" ) throw new Error ( "Expected structured diff" ) ;
30+ expect ( parsed . files [ 0 ] ) . toMatchObject ( {
31+ path : "large.ts" ,
32+ additions : 3000 ,
33+ deletions : 1800 ,
34+ rows : [ ] ,
35+ } ) ;
36+ expect ( parsed . additions ) . toBe ( 3000 ) ;
37+ expect ( parsed . deletions ) . toBe ( 1800 ) ;
38+ expect ( parsed . notice ) . toBe (
39+ "Some file contents are unavailable. Open the pull request on its provider to see the full changes." ,
40+ ) ;
41+ const cached = combinePullRequestDiffPages ( pages , cache , "pr" ) ;
42+ if ( cached . kind !== "files" ) throw new Error ( "Expected structured diff" ) ;
43+ expect ( cached . files [ 0 ] ) . toBe ( parsed . files [ 0 ] ) ;
44+ } ) ;
45+
46+ it ( "combines normal and withheld pages and refreshes counts with unchanged patch text" , ( ) => {
47+ const first = { ...diff ( "first.ts" ) , nextCursor : "second" } ;
48+ const withheld = withheldDiff ( ) ;
49+ const cache = new WeakMap < PullRequestDiffResult , ReviewParsedDiff > ( ) ;
50+ const pages = retainPullRequestDiffPage (
51+ retainPullRequestDiffPage ( [ ] , null , first ) ,
52+ "second" ,
53+ withheld ,
54+ ) ;
55+ const before = combinePullRequestDiffPages ( pages , cache , "pr" ) ;
56+ if ( before . kind !== "files" ) throw new Error ( "Expected structured diff" ) ;
57+ expect ( before . files . map ( ( file ) => [ file . path , file . additions , file . deletions ] ) ) . toEqual ( [
58+ [ "first.ts" , 1 , 1 ] ,
59+ [ "large.ts" , 3000 , 1800 ] ,
60+ ] ) ;
61+ expect ( before . additions ) . toBe ( 3001 ) ;
62+ expect ( before . deletions ) . toBe ( 1801 ) ;
63+
64+ const refreshed = retainPullRequestDiffPage ( pages , "second" , {
65+ ...withheld ,
66+ omittedFileStats : [ { path : "large.ts" , additions : 4000 , deletions : 2000 } ] ,
67+ } ) ;
68+ const after = combinePullRequestDiffPages ( refreshed , cache , "pr" ) ;
69+ if ( after . kind !== "files" ) throw new Error ( "Expected structured diff" ) ;
70+ expect ( after . files [ 0 ] ) . toBe ( before . files [ 0 ] ) ;
71+ expect ( after . files [ 1 ] ?. id ) . toBe ( before . files [ 1 ] ?. id ) ;
72+ expect ( after . files [ 1 ] ) . toMatchObject ( { additions : 4000 , deletions : 2000 , rows : [ ] } ) ;
73+ expect ( after . additions ) . toBe ( 4001 ) ;
74+ expect ( after . deletions ) . toBe ( 2001 ) ;
75+ expect ( after . notice ) . toBe ( before . notice ) ;
76+ expect ( before . additions ) . toBe ( 3001 ) ;
77+ } ) ;
1578 it ( "retains file order and IDs when another page arrives" , ( ) => {
1679 const first = { ...diff ( "first.ts" ) , nextCursor : "second" } ;
1780 const pages = retainPullRequestDiffPage ( [ ] , null , first ) ;
0 commit comments