1- import { describe , expect , it } from "vite-plus/test" ;
1+ import { describe , expect , it , vi } from "vite-plus/test" ;
22import type { PullRequestDiffResult } from "@t3tools/contracts" ;
33import type { ReviewParsedDiff } from "../review/reviewModel" ;
44import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients" ;
5- import { combinePullRequestDiffPages , retainPullRequestDiffPage } from "./pullRequestDiffPages" ;
5+ import * as reviewModel from "../review/reviewModel" ;
6+ import {
7+ combinePullRequestDiffPages ,
8+ getCachedPullRequestDiffPages ,
9+ retainPullRequestDiffPage ,
10+ } from "./pullRequestDiffPages" ;
611
712const GITHUB = sourceControlClients . get ( "github" ) . changeRequest ;
813
@@ -24,6 +29,65 @@ function withheldDiff(): PullRequestDiffResult {
2429}
2530
2631describe ( "paged mobile pull request diffs" , ( ) => {
32+ it ( "isolates scopes, cursors, and provider terminology for the same result" , ( ) => {
33+ const result = withheldDiff ( ) ;
34+ const pages = [ { cursor : null , result } ] ;
35+ const first = getCachedPullRequestDiffPages ( pages , "first" , GITHUB ) ;
36+ const otherScope = getCachedPullRequestDiffPages ( pages , "second" , GITHUB ) ;
37+ const otherCursor = getCachedPullRequestDiffPages (
38+ [ { cursor : "next" , result } ] ,
39+ "first" ,
40+ GITHUB ,
41+ ) ;
42+ const otherProvider = getCachedPullRequestDiffPages (
43+ pages ,
44+ "first" ,
45+ sourceControlClients . get ( "gitlab" ) . changeRequest ,
46+ ) ;
47+ expect ( otherScope ) . not . toBe ( first ) ;
48+ expect ( otherCursor ) . not . toBe ( first ) ;
49+ expect ( otherProvider ) . not . toBe ( first ) ;
50+ if ( first . kind !== "files" || otherScope . kind !== "files" || otherProvider . kind !== "files" )
51+ throw new Error ( "Expected structured files" ) ;
52+ expect ( otherScope . files [ 0 ] ?. id ) . not . toBe ( first . files [ 0 ] ?. id ) ;
53+ expect ( first . notice ) . toContain ( "pull request" ) ;
54+ expect ( otherProvider . notice ) . toContain ( "merge request" ) ;
55+ expect ( getCachedPullRequestDiffPages ( pages , "first" , GITHUB ) ) . toBe ( first ) ;
56+ } ) ;
57+
58+ it ( "reuses earlier pages on append and invalidates changed continuation results" , ( ) => {
59+ using parse = vi . spyOn ( reviewModel , "buildReviewParsedDiff" ) ;
60+ const firstPage = { cursor : null , result : diff ( "first.ts" ) } ;
61+ const first = getCachedPullRequestDiffPages ( [ firstPage ] , "append" , GITHUB ) ;
62+ const nextPage = { cursor : "next" , result : withheldDiff ( ) } ;
63+ const combined = getCachedPullRequestDiffPages ( [ firstPage , nextPage ] , "append" , GITHUB ) ;
64+ expect ( parse ) . toHaveBeenCalledTimes ( 2 ) ;
65+ if ( first . kind !== "files" || combined . kind !== "files" ) throw new Error ( "Expected files" ) ;
66+ expect ( combined . files [ 0 ] ) . toBe ( first . files [ 0 ] ) ;
67+ expect ( combined . files . map ( ( file ) => file . path ) ) . toEqual ( [ "first.ts" , "large.ts" ] ) ;
68+ expect ( getCachedPullRequestDiffPages ( [ firstPage , nextPage ] , "append" , GITHUB ) ) . toBe ( combined ) ;
69+ const refreshed = getCachedPullRequestDiffPages (
70+ [
71+ firstPage ,
72+ {
73+ ...nextPage ,
74+ result : {
75+ ...nextPage . result ,
76+ omittedFileStats : [ { path : "large.ts" , additions : 4000 , deletions : 2000 } ] ,
77+ } ,
78+ } ,
79+ ] ,
80+ "append" ,
81+ GITHUB ,
82+ ) ;
83+ expect ( parse ) . toHaveBeenCalledTimes ( 3 ) ;
84+ expect ( refreshed ) . not . toBe ( combined ) ;
85+ if ( refreshed . kind !== "files" ) throw new Error ( "Expected refreshed files" ) ;
86+ expect ( refreshed . files [ 0 ] ) . toBe ( first . files [ 0 ] ) ;
87+ expect ( refreshed . files [ 1 ] ) . toMatchObject ( { additions : 4000 , deletions : 2000 } ) ;
88+ expect ( combined . files [ 1 ] ?. additions ) . toBe ( 3000 ) ;
89+ } ) ;
90+
2791 it ( "withheld PR hunks must retain provider line counts" , ( ) => {
2892 const result = withheldDiff ( ) ;
2993 const cache = new WeakMap < PullRequestDiffResult , ReviewParsedDiff > ( ) ;
0 commit comments