@@ -8,6 +8,7 @@ import * as PlatformError from "effect/PlatformError";
88import * as ServerConfig from "../config.ts" ;
99import * as GitVcsDriver from "../vcs/GitVcsDriver.ts" ;
1010import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts" ;
11+ import * as VcsProcess from "../vcs/VcsProcess.ts" ;
1112import * as ReviewService from "./ReviewService.ts" ;
1213
1314function makeLayer ( input : {
@@ -34,6 +35,64 @@ function makeLayer(input: {
3435}
3536
3637describe ( "ReviewService" , ( ) => {
38+ it . effect . each ( [ false , true ] ) (
39+ "reads working-tree changes with an unrelated base (committed: %s)" ,
40+ ( committed ) =>
41+ Effect . gen ( function * ( ) {
42+ const fs = yield * FileSystem . FileSystem ;
43+ const cwd = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-review-orphan-" } ) ;
44+ const baseDir = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-review-base-" } ) ;
45+ const layer = ReviewService . layer . pipe (
46+ Layer . provide ( VcsDriverRegistry . layer . pipe ( Layer . provide ( VcsProcess . layer ) ) ) ,
47+ Layer . provideMerge ( GitVcsDriver . layer ) ,
48+ Layer . provide ( ServerConfig . layerTest ( cwd , baseDir ) ) ,
49+ Layer . provideMerge ( NodeServices . layer ) ,
50+ ) ;
51+
52+ yield * Effect . gen ( function * ( ) {
53+ const driver = yield * GitVcsDriver . GitVcsDriver ;
54+ const review = yield * ReviewService . ReviewService ;
55+ const git = ( args : ReadonlyArray < string > ) =>
56+ driver . execute ( { operation : "ReviewService.test.git" , cwd, args } ) ;
57+ yield * git ( [ "init" , "-b" , "main" ] ) ;
58+ yield * git ( [ "config" , "user.email" , "[email protected] " ] ) ; 59+ yield * git ( [ "config" , "user.name" , "Test" ] ) ;
60+ yield * fs . writeFileString ( `${ cwd } /README.md` , "base\n" ) ;
61+ yield * git ( [ "add" , "." ] ) ;
62+ yield * git ( [ "commit" , "-m" , "main root" ] ) ;
63+ yield * git ( [ "checkout" , "--orphan" , "orphan" ] ) ;
64+ if ( committed ) yield * git ( [ "commit" , "-m" , "orphan root" ] ) ;
65+ yield * fs . writeFileString ( `${ cwd } /README.md` , "base\ndirty\n" ) ;
66+ yield * fs . writeFileString ( `${ cwd } /untracked.txt` , "new\n" ) ;
67+
68+ const preview = yield * review . getScopedDiffPreview ( {
69+ cwd,
70+ source : "working-tree" ,
71+ baseRef : "missing-base" ,
72+ } ) ;
73+ assert . strictEqual ( preview . sources . length , 1 ) ;
74+ const source = preview . sources [ 0 ] ! ;
75+ assert . strictEqual ( source . kind , "working-tree" ) ;
76+ assert . deepStrictEqual ( source . files , [
77+ { path : "README.md" , previousPath : null , additions : committed ? 1 : 2 , deletions : 0 } ,
78+ { path : "untracked.txt" , previousPath : null , additions : 1 , deletions : 0 } ,
79+ ] ) ;
80+ assert . include ( source . diff , "+dirty" ) ;
81+ assert . include ( source . diff , "+new" ) ;
82+
83+ if ( committed ) {
84+ const error = yield * review
85+ . getScopedDiffPreview ( { cwd, source : "branch-range" , baseRef : "main" } )
86+ . pipe ( Effect . flip ) ;
87+ assert . strictEqual ( error . _tag , "GitCommandError" ) ;
88+ if ( error . _tag === "GitCommandError" ) {
89+ assert . strictEqual ( error . operation , "GitVcsDriver.resolveReviewMergeBase" ) ;
90+ }
91+ }
92+ } ) . pipe ( Effect . provide ( layer ) ) ;
93+ } ) . pipe ( Effect . provide ( NodeServices . layer ) ) ,
94+ ) ;
95+
3796 it . effect ( "rejects diff preview cwd outside the configured workspace roots" , ( ) =>
3897 Effect . gen ( function * ( ) {
3998 const fs = yield * FileSystem . FileSystem ;
0 commit comments