@@ -67,6 +67,7 @@ describe("createAssetEnvironmentAtoms", () => {
6767 { name : "remote success" , path : "/tmp/clip.mp4" , success : true } ,
6868 { name : "relative path" , path : "clip.mp4" } ,
6969 { name : "no primary" , path : "/tmp/clip.mp4" , primary : "none" } ,
70+ { name : "primary reconnect" , path : "/tmp/frame.png" , primary : "reconnecting" } ,
7071 { name : "same environment" , path : "/tmp/clip.mp4" , primary : "same" } ,
7172 { name : "non-media" , path : "/tmp/report.html" } ,
7273 { name : "authorization failure" , path : "/tmp/clip.mp4" , error : "auth" } ,
@@ -133,20 +134,22 @@ describe("createAssetEnvironmentAtoms", () => {
133134 followStream : ( id , stream ) =>
134135 Stream . provideService ( stream , EnvironmentSupervisor , supervisors . get ( id ) ! ) ,
135136 } as EnvironmentRegistry [ "Service" ] ) ;
137+ const registry = AtomRegistry . make ( ) ;
138+ yield * Effect . addFinalizer ( ( ) => Effect . sync ( ( ) => registry . dispose ( ) ) ) ;
139+ const localTarget = {
140+ environmentId : scenario . primary === "same" ? remoteId : localId ,
141+ httpBaseUrl : "https://local.test" ,
142+ } ;
143+ const localEnvironment = Atom . make < typeof localTarget | null > (
144+ scenario . primary === "none" || scenario . primary === "reconnecting" ? null : localTarget ,
145+ ) ;
136146 const assets = createAssetEnvironmentAtoms (
137147 Atom . runtime ( Layer . succeed ( EnvironmentRegistry , environments ) ) ,
138148 {
139- localMediaEnvironment : ( ) =>
140- scenario . primary === "none"
141- ? null
142- : {
143- environmentId : scenario . primary === "same" ? remoteId : localId ,
144- httpBaseUrl : "https://local.test" ,
145- } ,
149+ localMediaEnvironment : ( ) => registry . get ( localEnvironment ) ,
150+ localMediaRefreshTrigger : localEnvironment ,
146151 } ,
147152 ) ;
148- const registry = AtomRegistry . make ( ) ;
149- yield * Effect . addFinalizer ( ( ) => Effect . sync ( ( ) => registry . dispose ( ) ) ) ;
150153 const query = assets . createUrl ( { environmentId : remoteId , input : { resource } } ) ;
151154 const result = AtomRegistry . getResult ( registry , query , { suspendOnWaiting : true } ) ;
152155 if ( scenario . fallback || scenario . success ) {
@@ -159,6 +162,11 @@ describe("createAssetEnvironmentAtoms", () => {
159162 expect ( yield * Effect . flip ( result ) ) . toEqual ( error ) ;
160163 }
161164 expect ( calls ) . toEqual ( scenario . fallback ? [ remoteId , localId ] : [ remoteId ] ) ;
165+ if ( scenario . primary === "reconnecting" ) {
166+ registry . set ( localEnvironment , localTarget ) ;
167+ expect ( ( yield * result ) . relativeUrl ) . toBe ( "https://local.test/api/assets/local/media" ) ;
168+ expect ( calls ) . toEqual ( [ remoteId , remoteId , localId ] ) ;
169+ }
162170 } ) . pipe ( Effect . scoped ) ,
163171 ) ;
164172 }
0 commit comments