@@ -5,6 +5,8 @@ import * as Effect from "effect/Effect";
55import * as FileSystem from "effect/FileSystem" ;
66import * as Layer from "effect/Layer" ;
77import * as Path from "effect/Path" ;
8+ import * as PlatformError from "effect/PlatformError" ;
9+ import * as Result from "effect/Result" ;
810import * as Schema from "effect/Schema" ;
911import * as Stream from "effect/Stream" ;
1012import * as ServerConfig from "../config.ts" ;
@@ -114,6 +116,49 @@ it.effect(
114116 yield * fs . readFileString ( path . join ( userHome , "sessions" , "normal.jsonl" ) ) ,
115117 "normal history" ,
116118 ) ;
119+ const installationFailure = new CodexInstallation . CodexInstallationError ( {
120+ operation : "resolve" ,
121+ detail : "Install the separate runtime first." ,
122+ } ) ;
123+ const homeFailure = new PlatformError . PlatformError (
124+ new PlatformError . SystemError ( {
125+ _tag : "PermissionDenied" ,
126+ module : "FileSystem" ,
127+ method : "makeDirectory" ,
128+ } ) ,
129+ ) ;
130+ for ( const acquireFails of [ true , false ] ) {
131+ const result = yield * makeCodexIsolatedRuntime ( {
132+ instanceId : ProviderInstanceId . make ( "codex-failure" ) ,
133+ config,
134+ environment : { } ,
135+ } ) . pipe (
136+ Effect . flatMap ( ( runtime ) => runtime . resolve ) ,
137+ Effect . provide (
138+ Layer . mock ( CodexInstallation . CodexInstallation ) ( {
139+ managedDirectory : managed . managedDirectory ,
140+ managed : Effect . succeed ( {
141+ ...managed ,
142+ acquire : acquireFails ? ( ) => Effect . fail ( installationFailure ) : managed . acquire ,
143+ } ) ,
144+ } ) ,
145+ ) ,
146+ Effect . provideService ( FileSystem . FileSystem , {
147+ ...fs ,
148+ makeDirectory : ( ) => Effect . fail ( homeFailure ) ,
149+ } ) ,
150+ Effect . result ,
151+ Effect . scoped ,
152+ ) ;
153+ assert . isTrue ( Result . isFailure ( result ) ) ;
154+ if ( Result . isFailure ( result ) ) {
155+ assert . strictEqual (
156+ result . failure . cause ,
157+ acquireFails ? installationFailure : homeFailure ,
158+ ) ;
159+ }
160+ assert . equal ( leases , 0 ) ;
161+ }
117162 } ) . pipe (
118163 Effect . provide (
119164 Layer . mock ( CodexInstallation . CodexInstallation ) ( {
0 commit comments