@@ -1581,6 +1581,44 @@ describe("EnvironmentSupervisor", () => {
15811581 } ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
15821582 ) ;
15831583
1584+ it . effect ( "learns routes from the replacement session after a token handoff" , ( ) =>
1585+ Effect . gen ( function * ( ) {
1586+ const learnCalls = yield * Ref . make ( 0 ) ;
1587+ const harness = yield * makeHarness ( {
1588+ prepare : ( attempt ) =>
1589+ Effect . succeed ( {
1590+ ...PREPARED_CONNECTION ,
1591+ target : RELAY_TARGET ,
1592+ httpAuthorization : {
1593+ _tag : "Dpop" ,
1594+ accessToken : `access-token-${ attempt } ` ,
1595+ expiresAtEpochMs : 3_600_000 * attempt ,
1596+ } ,
1597+ } ) ,
1598+ initialConfig : ( ) =>
1599+ Effect . succeed ( { directEndpoints : [ ] } as Pick <
1600+ ServerConfig ,
1601+ "directEndpoints"
1602+ > as ServerConfig ) ,
1603+ } ) ;
1604+ const supervisor = yield * EnvironmentSupervisor . make ( RELAY_ENTRY , {
1605+ initiallyDesired : true ,
1606+ learnRoutes : ( ) =>
1607+ Ref . update ( learnCalls , ( count ) => count + 1 ) . pipe ( Effect . as ( Option . none ( ) ) ) ,
1608+ } ) . pipe ( Effect . provide ( harness . dependencies ) ) ;
1609+
1610+ yield * awaitState ( supervisor . state , ( state ) => state . phase === "connected" ) ;
1611+ const first = Option . getOrThrow ( yield * SubscriptionRef . get ( supervisor . session ) ) ;
1612+ yield * TestClock . adjust ( "1 minute" ) ;
1613+ expect ( yield * Ref . get ( learnCalls ) ) . toBe ( 1 ) ;
1614+
1615+ yield * TestClock . adjust ( "58 minutes" ) ;
1616+ yield * awaitNewSession ( supervisor . session , first ) ;
1617+ yield * TestClock . adjust ( "1 second" ) ;
1618+ expect ( yield * Ref . get ( learnCalls ) ) . toBe ( 2 ) ;
1619+ } ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
1620+ ) ;
1621+
15841622 it . effect ( "keeps the session while a failed replacement retries before expiry" , ( ) =>
15851623 Effect . gen ( function * ( ) {
15861624 const harness = yield * makeHarness ( {
0 commit comments