@@ -179,6 +179,71 @@ describe("createAssetEnvironmentAtoms", () => {
179179 } ) . pipe ( Effect . scoped ) ,
180180 ) ;
181181
182+ it . effect ( "signs a scoped query on its own and keeps the scope off the wire" , ( ) =>
183+ Effect . gen ( function * ( ) {
184+ const environmentId = EnvironmentId . make ( "remote" ) ;
185+ const payloads : unknown [ ] = [ ] ;
186+ const client = {
187+ [ WS_METHODS . assetsCreateUrl ] : ( payload : unknown ) => {
188+ payloads . push ( payload ) ;
189+ return Effect . succeed ( {
190+ relativeUrl : `/api/assets/token-${ payloads . length } /shot.png` ,
191+ expiresAt : 999999 ,
192+ } ) ;
193+ } ,
194+ } as unknown as WsRpcProtocolClient ;
195+ const supervisor = EnvironmentSupervisor . EnvironmentSupervisor . of ( {
196+ target : new PrimaryConnectionTarget ( {
197+ environmentId,
198+ label : "remote" ,
199+ httpBaseUrl : "https://remote.test" ,
200+ wsBaseUrl : "wss://remote.test" ,
201+ } ) ,
202+ state : yield * SubscriptionRef . make < SupervisorConnectionState > ( {
203+ ...AVAILABLE_CONNECTION_STATE ,
204+ phase : "connected" as const ,
205+ } ) ,
206+ session : yield * SubscriptionRef . make ( Option . some ( { client } as RpcSession ) ) ,
207+ prepared : yield * SubscriptionRef . make ( Option . none < PreparedConnection > ( ) ) ,
208+ connect : Effect . void ,
209+ disconnect : Effect . void ,
210+ retryNow : Effect . void ,
211+ } ) ;
212+ const environments = EnvironmentRegistry . EnvironmentRegistry . of ( {
213+ run : ( _id , effect ) =>
214+ Effect . provideService ( effect , EnvironmentSupervisor . EnvironmentSupervisor , supervisor ) ,
215+ followStream : ( _id , stream ) =>
216+ Stream . provideService ( stream , EnvironmentSupervisor . EnvironmentSupervisor , supervisor ) ,
217+ } as EnvironmentRegistry . EnvironmentRegistry [ "Service" ] ) ;
218+ const registry = AtomRegistry . make ( ) ;
219+ yield * Effect . addFinalizer ( ( ) => Effect . sync ( ( ) => registry . dispose ( ) ) ) ;
220+ const assets = createAssetEnvironmentAtoms (
221+ Atom . runtime ( Layer . succeed ( EnvironmentRegistry . EnvironmentRegistry , environments ) ) ,
222+ ) ;
223+ const resource = {
224+ _tag : "media-file" as const ,
225+ threadId : ThreadId . make ( "thread-1" ) ,
226+ path : "shot.png" ,
227+ } ;
228+ const signedUrl = ( scope ?: string ) =>
229+ AtomRegistry . getResult (
230+ registry ,
231+ assets . createUrl ( { environmentId, input : { resource, scope } } ) ,
232+ { suspendOnWaiting : true } ,
233+ ) . pipe ( Effect . map ( ( result ) => result . relativeUrl ) ) ;
234+
235+ // Two messages that show one path each sign their own URL.
236+ expect ( yield * signedUrl ( "message-1" ) ) . toBe ( "/api/assets/token-1/shot.png" ) ;
237+ expect ( yield * signedUrl ( "message-2" ) ) . toBe ( "/api/assets/token-2/shot.png" ) ;
238+ expect ( yield * signedUrl ( "message-1" ) ) . toBe ( "/api/assets/token-1/shot.png" ) ;
239+ expect ( payloads ) . toEqual ( [ { resource } , { resource } ] ) ;
240+ // An absent scope shares the unscoped query.
241+ expect ( assets . createUrl ( { environmentId, input : { resource, scope : undefined } } ) ) . toBe (
242+ assets . createUrl ( { environmentId, input : { resource } } ) ,
243+ ) ;
244+ } ) . pipe ( Effect . scoped ) ,
245+ ) ;
246+
182247 it ( "keys asset URL queries by environment and resource" , ( ) => {
183248 const runtime = Atom . runtime ( Layer . empty ) as unknown as Atom . AtomRuntime <
184249 EnvironmentRegistry . EnvironmentRegistry ,
0 commit comments