1- import fs from "node:fs" ;
2- import os from "node:os" ;
3- import path from "node:path" ;
41import { execFileSync } from "node:child_process" ;
52
63import * as NodeServices from "@effect/platform-node/NodeServices" ;
@@ -13,9 +10,11 @@ import {
1310import {
1411 Effect ,
1512 Exit ,
13+ FileSystem ,
1614 Layer ,
1715 ManagedRuntime ,
1816 Option ,
17+ Path ,
1918 Ref ,
2019 Schedule ,
2120 Schema ,
@@ -66,7 +65,7 @@ import {
6665 makeTestProviderAdapterHarness ,
6766 type TestProviderAdapterHarness ,
6867} from "./TestProviderAdapter.integration.ts" ;
69- import { ServerConfig } from "../src/config.ts" ;
68+ import { deriveServerPaths , ServerConfig } from "../src/config.ts" ;
7069
7170function runGit ( cwd : string , args : ReadonlyArray < string > ) {
7271 return execFileSync ( "git" , args , {
@@ -76,14 +75,16 @@ function runGit(cwd: string, args: ReadonlyArray<string>) {
7675 } ) ;
7776}
7877
79- function initializeGitWorkspace ( cwd : string ) {
78+ const initializeGitWorkspace = Effect . fn ( function * ( cwd : string ) {
8079 runGit ( cwd , [ "init" , "--initial-branch=main" ] ) ;
8180 runGit ( cwd , [ "config" , "user.email" , "[email protected] " ] ) ; 8281 runGit ( cwd , [ "config" , "user.name" , "Test User" ] ) ;
83- fs . writeFileSync ( path . join ( cwd , "README.md" ) , "v1\n" , "utf8" ) ;
82+ const fileSystem = yield * FileSystem . FileSystem ;
83+ const { join } = yield * Path . Path ;
84+ yield * fileSystem . writeFileString ( join ( cwd , "README.md" ) , "v1\n" ) ;
8485 runGit ( cwd , [ "add" , "." ] ) ;
8586 runGit ( cwd , [ "commit" , "-m" , "Initial" ] ) ;
86- }
87+ } ) ;
8788
8889export function gitRefExists ( cwd : string , ref : string ) : boolean {
8990 try {
@@ -214,7 +215,9 @@ export const makeOrchestrationIntegrationHarness = (
214215 options ?: MakeOrchestrationIntegrationHarnessOptions ,
215216) =>
216217 Effect . gen ( function * ( ) {
217- const sleep = ( ms : number ) => Effect . sleep ( ms ) ;
218+ const path = yield * Path . Path ;
219+ const fileSystem = yield * FileSystem . FileSystem ;
220+
218221 const provider = options ?. provider ?? "codex" ;
219222 const useRealCodex = options ?. realCodex === true ;
220223 const adapterHarness = useRealCodex
@@ -231,13 +234,16 @@ export const makeOrchestrationIntegrationHarness = (
231234 listProviders : ( ) => Effect . succeed ( [ adapterHarness . provider ] ) ,
232235 } as typeof ProviderAdapterRegistry . Service )
233236 : null ;
234- const rootDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "t3-orchestration-integration-" ) ) ;
237+ const rootDir = yield * fileSystem . makeTempDirectoryScoped ( {
238+ prefix : "t3-orchestration-integration-" ,
239+ } ) ;
235240 const workspaceDir = path . join ( rootDir , "workspace" ) ;
236- const stateDir = path . join ( rootDir , "state" ) ;
237- const dbPath = path . join ( stateDir , "state.sqlite" ) ;
238- fs . mkdirSync ( workspaceDir , { recursive : true } ) ;
239- fs . mkdirSync ( stateDir , { recursive : true } ) ;
240- initializeGitWorkspace ( workspaceDir ) ;
241+ const { stateDir, dbPath } = yield * deriveServerPaths ( rootDir , undefined ) . pipe (
242+ Effect . provideService ( Path . Path , path ) ,
243+ ) ;
244+ yield * fileSystem . makeDirectory ( workspaceDir , { recursive : true } ) ;
245+ yield * fileSystem . makeDirectory ( stateDir , { recursive : true } ) ;
246+ yield * initializeGitWorkspace ( workspaceDir ) ;
241247
242248 const persistenceLayer = makeSqlitePersistenceLive ( dbPath ) ;
243249 const orchestrationLayer = OrchestrationEngineLive . pipe (
@@ -262,7 +268,7 @@ export const makeOrchestrationIntegrationHarness = (
262268 } ) ,
263269 ) . pipe (
264270 Layer . provide ( makeCodexAdapterLive ( ) ) ,
265- Layer . provideMerge ( ServerConfig . layerTest ( workspaceDir , stateDir ) ) ,
271+ Layer . provideMerge ( ServerConfig . layerTest ( workspaceDir , rootDir ) ) ,
266272 Layer . provideMerge ( NodeServices . layer ) ,
267273 Layer . provideMerge ( providerSessionDirectoryLayer ) ,
268274 ) ;
@@ -312,7 +318,7 @@ export const makeOrchestrationIntegrationHarness = (
312318 ) ;
313319 const layer = orchestrationReactorLayer . pipe (
314320 Layer . provide ( persistenceLayer ) ,
315- Layer . provideMerge ( ServerConfig . layerTest ( workspaceDir , stateDir ) ) ,
321+ Layer . provideMerge ( ServerConfig . layerTest ( workspaceDir , rootDir ) ) ,
316322 Layer . provideMerge ( NodeServices . layer ) ,
317323 ) ;
318324
@@ -352,7 +358,7 @@ export const makeOrchestrationIntegrationHarness = (
352358 yield * Stream . runForEach ( runtimeReceiptBus . stream , ( receipt ) =>
353359 Ref . update ( receiptHistory , ( history ) => [ ...history , receipt ] ) . pipe ( Effect . asVoid ) ,
354360 ) . pipe ( Effect . forkIn ( scope ) ) ;
355- yield * sleep ( 10 ) ;
361+ yield * Effect . sleep ( 10 ) ;
356362
357363 const waitForThread : OrchestrationIntegrationHarness [ "waitForThread" ] = (
358364 threadId ,
@@ -469,13 +475,7 @@ export const makeOrchestrationIntegrationHarness = (
469475 }
470476 } ) ;
471477
472- yield * shutdown . pipe (
473- Effect . ensuring (
474- Effect . sync ( ( ) => {
475- fs . rmSync ( rootDir , { recursive : true , force : true } ) ;
476- } ) ,
477- ) ,
478- ) ;
478+ yield * shutdown ;
479479 } ) ;
480480
481481 return {
0 commit comments