@@ -51,6 +51,7 @@ const layerEnrichment = ProjectEnrichmentService.layer.pipe(
5151const layerRealGit = GitVcsDriver . layer . pipe ( Layer . provide ( VcsProcess . layer ) ) ;
5252
5353interface HarnessOptions {
54+ readonly scratchDir ?: string ;
5455 readonly vcsProcess ?: Layer . Layer < VcsProcess . VcsProcess > ;
5556 readonly git ?: Layer . Layer < GitVcsDriver . GitVcsDriver > ;
5657 readonly projects ?: (
@@ -75,7 +76,14 @@ const layer = (baseDir: string, options?: HarnessOptions) =>
7576 Layer . provideMerge ( options ?. git ?? layerRealGit ) ,
7677 Layer . provideMerge ( SqlitePersistence . layerMemory ) ,
7778 Layer . provideMerge ( ServerSettings . layerTest ( ) ) ,
78- Layer . provideMerge ( ServerConfig . layerTest ( baseDir , baseDir ) ) ,
79+ Layer . provideMerge (
80+ Layer . effect (
81+ ServerConfig . ServerConfig ,
82+ ServerConfig . ServerConfig . pipe (
83+ Effect . map ( ( config ) => ( { ...config , scratchDir : options ?. scratchDir } ) ) ,
84+ ) ,
85+ ) . pipe ( Layer . provide ( ServerConfig . layerTest ( baseDir , baseDir ) ) ) ,
86+ ) ,
7987 Layer . provideMerge ( NodeServices . layer ) ,
8088 ) ;
8189
@@ -259,6 +267,57 @@ it.effect("gives each Scratch thread its own folder, named from its message", ()
259267 ) ,
260268) ;
261269
270+ it . effect ( "uses a configured directory without changing the Scratch project" , ( ) =>
271+ Effect . gen ( function * ( ) {
272+ const fs = yield * FileSystem . FileSystem ;
273+ const path = yield * Path . Path ;
274+ const root = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-scratch-custom-" } ) ;
275+ const baseDir = path . join ( root , "data" ) ;
276+ const scratchDir = path . join ( root , "custom" , "chats" ) ;
277+ yield * Effect . gen ( function * ( ) {
278+ const scratch = yield * ManagedProjectFolders . ManagedProjectFolders ;
279+ const projects = yield * ProjectService . ProjectService ;
280+ const { projectId } = yield * scratch . ensureScratchProject ;
281+ const project = Option . getOrThrow ( yield * projects . getById ( projectId ) ) ;
282+ assert . equal ( project . workspaceRoot , path . join ( baseDir , "scratch" ) ) ;
283+ assert . isTrue ( yield * scratch . isScratchProject ( projectId ) ) ;
284+ const folders = yield * Effect . forEach (
285+ [ "thread:a:12345678" , "thread:b:12345678" ] ,
286+ ( threadId ) =>
287+ scratch . folderForThread ( { projectId, threadId : ThreadId . make ( threadId ) , text : "Hello" } ) ,
288+ ) ;
289+ const paths = folders . map ( Option . getOrThrow ) ;
290+ assert . equal ( new Set ( paths ) . size , 2 ) ;
291+ for ( const folder of paths ) {
292+ assert . equal ( path . dirname ( folder ) , scratchDir ) ;
293+ assert . isTrue ( yield * fs . exists ( folder ) ) ;
294+ }
295+ assert . deepEqual ( yield * fs . readDirectory ( project . workspaceRoot ) , [ ] ) ;
296+ } ) . pipe ( Effect . provide ( layer ( baseDir , { scratchDir } ) ) ) ;
297+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
298+ ) ;
299+
300+ it . effect ( "rejects a configured Scratch directory inside a Git checkout" , ( ) =>
301+ Effect . gen ( function * ( ) {
302+ const fs = yield * FileSystem . FileSystem ;
303+ const path = yield * Path . Path ;
304+ const root = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-scratch-custom-repo-" } ) ;
305+ const checkout = path . join ( root , "repo" ) ;
306+ yield * fs . makeDirectory ( checkout ) ;
307+ yield * git ( checkout , [ "init" , "--quiet" ] ) ;
308+ const scratchDir = path . join ( checkout , "missing" , "chats" ) ;
309+ yield * Effect . gen ( function * ( ) {
310+ const scratch = yield * ManagedProjectFolders . ManagedProjectFolders ;
311+ assert . isTrue ( Option . isNone ( yield * scratch . scratchRoot ) ) ;
312+ assert . equal (
313+ ( yield * Effect . flip ( scratch . ensureScratchProject ) ) . _tag ,
314+ "ScratchUnavailableError" ,
315+ ) ;
316+ assert . isFalse ( yield * fs . exists ( scratchDir ) ) ;
317+ } ) . pipe ( Effect . provide ( layer ( path . join ( root , "data" ) , { scratchDir } ) ) ) ;
318+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
319+ ) ;
320+
262321it . effect ( "leaves threads in other projects alone" , ( ) =>
263322 withScratch ( ( { baseDir } ) =>
264323 Effect . gen ( function * ( ) {
0 commit comments