@@ -4,8 +4,10 @@ import * as Effect from "effect/Effect";
44import * as FileSystem from "effect/FileSystem" ;
55import * as Layer from "effect/Layer" ;
66import * as PlatformError from "effect/PlatformError" ;
7+ import { ProjectId } from "@t3tools/contracts" ;
78
89import * as ServerConfig from "../config.ts" ;
10+ import * as ProjectStore from "../orchestration-v2/ProjectStore.ts" ;
911import * as ServerSettings from "../serverSettings.ts" ;
1012import * as GitVcsDriver from "../vcs/GitVcsDriver.ts" ;
1113import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts" ;
@@ -17,8 +19,30 @@ function layer(input: {
1719 readonly detectCalls ?: Array < { readonly cwd : string } > ;
1820 readonly worktreesDirectory ?: string ;
1921 readonly previousWorktreesDirectories ?: ReadonlyArray < string > ;
22+ readonly projectRoots ?: ReadonlyArray < string > | "unavailable" ;
2023} ) {
24+ const projectRoots = input . projectRoots ?? [ ] ;
2125 return ReviewService . layer . pipe (
26+ Layer . provide (
27+ Layer . mock ( ProjectStore . ProjectStoreV2 ) ( {
28+ listShells : ( ) =>
29+ projectRoots === "unavailable"
30+ ? Effect . fail (
31+ new ProjectStore . ProjectStoreV2Error ( { operation : "list" , cause : "offline" } ) ,
32+ )
33+ : Effect . succeed (
34+ projectRoots . map ( ( workspaceRoot , index ) => ( {
35+ id : ProjectId . make ( `project-${ index } ` ) ,
36+ title : `Project ${ index } ` ,
37+ workspaceRoot,
38+ defaultModelSelection : null ,
39+ scripts : [ ] ,
40+ createdAt : "2026-01-01T00:00:00.000Z" ,
41+ updatedAt : "2026-01-01T00:00:00.000Z" ,
42+ } ) ) ,
43+ ) ,
44+ } ) ,
45+ ) ,
2246 Layer . provide (
2347 Layer . mock ( VcsDriverRegistry . VcsDriverRegistry ) ( {
2448 get : ( ) => Effect . die ( "unexpected VCS registry get" ) ,
@@ -134,6 +158,38 @@ describe("ReviewService", () => {
134158 } ) . pipe ( Effect . provide ( NodeServices . layer ) ) ,
135159 ) ;
136160
161+ it . effect ( "allows registered project roots outside the server cwd" , ( ) =>
162+ Effect . gen ( function * ( ) {
163+ const fs = yield * FileSystem . FileSystem ;
164+ const workspaceRoot = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-review-workspace-" } ) ;
165+ const baseDir = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-review-base-" } ) ;
166+ // Stands in for a project on another drive than the server's home cwd.
167+ const projectRoot = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-review-project-" } ) ;
168+ const projectChild = `${ projectRoot } /packages/app` ;
169+ yield * fs . makeDirectory ( projectChild , { recursive : true } ) ;
170+ const sibling = `${ projectRoot } -sibling` ;
171+ yield * fs . makeDirectory ( sibling ) ;
172+ yield * Effect . addFinalizer ( ( ) => fs . remove ( sibling , { recursive : true } ) . pipe ( Effect . ignore ) ) ;
173+
174+ const review = ( cwd : string , projectRoots : ReadonlyArray < string > | "unavailable" ) =>
175+ Effect . gen ( function * ( ) {
176+ const service = yield * ReviewService . ReviewService ;
177+ return yield * service . getDiffPreview ( { cwd } ) ;
178+ } ) . pipe ( Effect . provide ( layer ( { workspaceRoot, baseDir, projectRoots } ) ) ) ;
179+
180+ assert . strictEqual ( ( yield * review ( projectRoot , [ projectRoot ] ) ) . cwd , projectRoot ) ;
181+ assert . strictEqual ( ( yield * review ( projectChild , [ projectRoot ] ) ) . cwd , projectChild ) ;
182+ for ( const [ cwd , projectRoots ] of [
183+ [ sibling , [ projectRoot ] ] ,
184+ [ projectRoot , [ ] ] ,
185+ [ projectRoot , "unavailable" ] ,
186+ ] as const ) {
187+ const error = yield * review ( cwd , projectRoots ) . pipe ( Effect . flip ) ;
188+ assert . strictEqual ( error . _tag , "VcsRepositoryDetectionError" ) ;
189+ }
190+ } ) . pipe ( Effect . provide ( NodeServices . layer ) ) ,
191+ ) ;
192+
137193 it . effect ( "allows diff preview cwd inside the configured workspace root" , ( ) =>
138194 Effect . gen ( function * ( ) {
139195 const fs = yield * FileSystem . FileSystem ;
0 commit comments