@@ -174,40 +174,55 @@ describe("DesktopLocalEnvironmentAuth", () => {
174174 } ,
175175 ] ) ,
176176 } as unknown as DesktopBackendPool . DesktopBackendPool [ "Service" ] ) ;
177- it . effect ( "waits for backend readiness before spending the bootstrap retry window" , ( ) =>
178- Effect . gen ( function * ( ) {
179- const ready = yield * Deferred . make < boolean > ( ) ;
180- const requests = yield * Ref . make ( 0 ) ;
181- const pool = Layer . succeed ( DesktopBackendPool . DesktopBackendPool , {
182- list : Effect . succeed ( [
183- {
184- id : PRIMARY_LOCAL_ENVIRONMENT_ID ,
185- label : Effect . succeed ( "Local" ) ,
186- currentConfig : Effect . succeedSome ( config ) ,
187- waitForReady : ( ) => Deferred . await ( ready ) ,
188- } ,
189- ] ) ,
190- } as unknown as DesktopBackendPool . DesktopBackendPool [ "Service" ] ) ;
191- const client = Layer . succeed (
192- HttpClient . HttpClient ,
193- HttpClient . make ( ( request ) =>
194- Ref . update ( requests , ( count ) => count + 1 ) . pipe ( Effect . as ( tokenResponse ( request ) ) ) ,
195- ) ,
196- ) ;
197- const auth = yield * DesktopLocalEnvironmentAuth . DesktopLocalEnvironmentAuth . pipe (
198- Effect . provide (
199- DesktopLocalEnvironmentAuth . layer . pipe ( Layer . provide ( Layer . merge ( pool , client ) ) ) ,
200- ) ,
201- ) ;
202- const token = yield * auth . getBearerToken . pipe ( Effect . forkChild ) ;
203- yield * TestClock . adjust ( "40 seconds" ) ;
204- assert . strictEqual ( yield * Ref . get ( requests ) , 0 ) ;
205- assert . isUndefined ( token . pollUnsafe ( ) ) ;
177+ it . effect . each ( [ true , false ] ) (
178+ "waits for backend readiness (%s) before spending the bootstrap retry window" ,
179+ ( isReady ) =>
180+ Effect . gen ( function * ( ) {
181+ const ready = yield * Deferred . make < boolean > ( ) ;
182+ const requests = yield * Ref . make ( 0 ) ;
183+ const pool = Layer . succeed ( DesktopBackendPool . DesktopBackendPool , {
184+ list : Effect . succeed ( [
185+ {
186+ id : PRIMARY_LOCAL_ENVIRONMENT_ID ,
187+ label : Effect . succeed ( "Local" ) ,
188+ currentConfig : Effect . succeedSome ( config ) ,
189+ waitForReady : ( ) => Deferred . await ( ready ) ,
190+ } ,
191+ ] ) ,
192+ } as unknown as DesktopBackendPool . DesktopBackendPool [ "Service" ] ) ;
193+ const client = Layer . succeed (
194+ HttpClient . HttpClient ,
195+ HttpClient . make ( ( request ) =>
196+ Ref . update ( requests , ( count ) => count + 1 ) . pipe ( Effect . as ( tokenResponse ( request ) ) ) ,
197+ ) ,
198+ ) ;
199+ const auth = yield * DesktopLocalEnvironmentAuth . DesktopLocalEnvironmentAuth . pipe (
200+ Effect . provide (
201+ DesktopLocalEnvironmentAuth . layer . pipe ( Layer . provide ( Layer . merge ( pool , client ) ) ) ,
202+ ) ,
203+ ) ;
204+ const token = yield * auth . getBearerToken . pipe ( Effect . result , Effect . forkChild ) ;
205+ yield * TestClock . adjust ( "40 seconds" ) ;
206+ assert . strictEqual ( yield * Ref . get ( requests ) , 0 ) ;
207+ assert . isUndefined ( token . pollUnsafe ( ) ) ;
206208
207- yield * Deferred . succeed ( ready , true ) ;
208- assert . strictEqual ( yield * Fiber . join ( token ) , "desktop-bearer-token" ) ;
209- assert . strictEqual ( yield * Ref . get ( requests ) , 1 ) ;
210- } ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
209+ yield * Deferred . succeed ( ready , isReady ) ;
210+ const result = yield * Fiber . join ( token ) ;
211+ if ( isReady ) {
212+ assert . strictEqual ( result . _tag , "Success" ) ;
213+ if ( result . _tag !== "Success" ) return assert . fail ( "expected a bearer token" ) ;
214+ assert . strictEqual ( result . success , "desktop-bearer-token" ) ;
215+ } else {
216+ assert . strictEqual ( result . _tag , "Failure" ) ;
217+ if ( result . _tag !== "Failure" ) return assert . fail ( "expected an unreadiness error" ) ;
218+ assert . strictEqual (
219+ result . failure . _tag ,
220+ "DesktopLocalEnvironmentAuthBackendNotReadyError" ,
221+ ) ;
222+ assert . notProperty ( result . failure , "cause" ) ;
223+ }
224+ assert . strictEqual ( yield * Ref . get ( requests ) , isReady ? 1 : 0 ) ;
225+ } ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
211226 ) ;
212227
213228 const makeExchange = ( failures : number , failure : ( ) => Response ) =>
@@ -269,6 +284,7 @@ describe("DesktopLocalEnvironmentAuth", () => {
269284 const error = yield * Fiber . join ( fiber ) ;
270285
271286 assert . strictEqual ( error . _tag , "DesktopLocalEnvironmentAuthSessionBootstrapError" ) ;
287+ assert . property ( error , "cause" ) ;
272288 assert . strictEqual ( yield * Ref . get ( requestCount ) , 1 ) ;
273289 } ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
274290 ) ;
0 commit comments