1- import type { FileDiffContentsLoader , FileDiffMetadata } from "@pierre/diffs" ;
1+ import type { FileDiffMetadata } from "@pierre/diffs" ;
22import { EnvironmentId } from "@t3tools/contracts" ;
33import { AsyncResult } from "effect/reactivity" ;
44import { describe , expect , it } from "vite-plus/test" ;
@@ -55,13 +55,6 @@ function loaderReturning(oldContents: string, newContents: string) {
5555 ) ;
5656}
5757
58- function loadOutcome ( loader : FileDiffContentsLoader , fileDiff : FileDiffMetadata ) {
59- return loader ( fileDiff ) . then (
60- ( ) => "hydrated with stale contents" ,
61- ( ) => "rejected" ,
62- ) ;
63- }
64-
6558describe ( "createGitDiffFileContentsLoader" , ( ) => {
6659 it ( "loads contents that still reproduce the patch" , async ( ) => {
6760 const loaded = await loaderReturning (
@@ -72,31 +65,26 @@ describe("createGitDiffFileContentsLoader", () => {
7265 expect ( loaded . newFile . contents ) . toBe ( toContents ( changedLines ) ) ;
7366 } ) ;
7467
75- it ( "rejects contents that end before the patch's hunk" , async ( ) => {
76- const loader = loaderReturning (
77- toContents ( originalLines . slice ( 0 , 30 ) ) ,
78- toContents ( changedLines . slice ( 0 , 30 ) ) ,
79- ) ;
80-
81- await expect ( loadOutcome ( loader , partialFileDiff ( ) ) ) . resolves . toBe ( "rejected" ) ;
82- } ) ;
83-
84- it ( "rejects contents whose unchanged tail no longer matches between sides" , async ( ) => {
85- const loader = loaderReturning (
86- toContents ( originalLines ) ,
87- toContents ( [ ...changedLines , "line 41 appended" ] ) ,
88- ) ;
89-
90- await expect ( loadOutcome ( loader , partialFileDiff ( ) ) ) . resolves . toBe ( "rejected" ) ;
91- } ) ;
92-
93- it ( "rejects contents whose hunk lines changed without moving" , async ( ) => {
94- const loader = loaderReturning (
95- toContents ( originalLines ) ,
96- toContents ( changedLines . map ( ( line , index ) => ( index === 30 ? "edited since" : line ) ) ) ,
97- ) ;
68+ it . each ( [
69+ {
70+ name : "end before the patch's hunk" ,
71+ oldLines : originalLines . slice ( 0 , 30 ) ,
72+ newLines : changedLines . slice ( 0 , 30 ) ,
73+ } ,
74+ {
75+ name : "have unchanged tails that no longer match between sides" ,
76+ oldLines : originalLines ,
77+ newLines : [ ...changedLines , "line 41 appended" ] ,
78+ } ,
79+ {
80+ name : "changed hunk lines without moving them" ,
81+ oldLines : originalLines ,
82+ newLines : changedLines . map ( ( line , index ) => ( index === 30 ? "edited since" : line ) ) ,
83+ } ,
84+ ] ) ( "rejects contents that $name" , async ( { oldLines, newLines } ) => {
85+ const loader = loaderReturning ( toContents ( oldLines ) , toContents ( newLines ) ) ;
9886
99- await expect ( loadOutcome ( loader , partialFileDiff ( ) ) ) . resolves . toBe ( "rejected ") ;
87+ await expect ( loader ( partialFileDiff ( ) ) ) . rejects . toThrow ( "changed since the diff was loaded ") ;
10088 } ) ;
10189
10290 it ( "loads a whitespace-ignored patch whose context shows one side's whitespace" , async ( ) => {
0 commit comments