@@ -19,6 +19,7 @@ function deferred<T>() {
1919
2020const state = vi . hoisted ( ( ) => ( {
2121 sessions : new Map < string , Pick < AuthSessionState , "authenticated" | "scopes" > > ( ) ,
22+ connection : vi . fn ( ) ,
2223 mint : vi . fn ( ) ,
2324 download : vi . fn ( ) ,
2425 png : vi . fn ( ) ,
@@ -43,7 +44,7 @@ vi.mock("../../state/assets", () => ({ assetEnvironment: { createUrl: {} } }));
4344vi . mock ( "../../state/use-atom-query-runner" , ( ) => ( { useAtomQueryRunner : ( ) => state . mint } ) ) ;
4445vi . mock ( "../../state/session" , ( ) => ( {
4546 environmentSession : { sessionStateAtom : ( environmentId : string ) => environmentId } ,
46- readPreparedConnection : ( ) => ( { httpBaseUrl : "https://host.test" } ) ,
47+ readPreparedConnection : ( environmentId : string ) => state . connection ( environmentId ) ,
4748} ) ) ;
4849vi . mock ( "../../state/query" , ( ) => ( {
4950 useEnvironmentQuery : ( environmentId : string ) => ( {
@@ -122,6 +123,7 @@ function openMenu(source: MediaActionSource) {
122123beforeEach ( ( ) => {
123124 state . sessions . clear ( ) ;
124125 state . sessions . set ( environmentId , denied ) ;
126+ state . connection . mockReset ( ) . mockReturnValue ( { httpBaseUrl : "https://host.test" } ) ;
125127 state . mint
126128 . mockReset ( )
127129 . mockResolvedValue ( AsyncResult . success ( { relativeUrl : "/api/assets/image.png" , expiresAt : 1 } ) ) ;
@@ -242,6 +244,40 @@ it("remints GitHub media before using its public display URL", async () => {
242244 expect ( await item . items [ "image/png" ] ) . toEqual ( png ) ;
243245} ) ;
244246
247+ it ( "copies a readable public GitHub image while its environment is disconnected" , async ( ) => {
248+ const { readMediaPng } = await vi . importActual < typeof import ( "./mediaContent" ) > ( "./mediaContent" ) ;
249+ state . png . mockImplementation ( readMediaPng ) ;
250+ state . connection . mockReturnValue ( null ) ;
251+ const png = new Blob ( [ "public GitHub image" ] , { type : "image/png" } ) ;
252+ using fetch = vi . spyOn ( globalThis , "fetch" ) . mockResolvedValue ( new Response ( png ) ) ;
253+ const url = "https://raw.githubusercontent.com/example/repo/main/image.png" ;
254+
255+ await useMediaActions ( {
256+ kind : "image" ,
257+ name : "image.png" ,
258+ src : url ,
259+ environmentId,
260+ asset : { environmentId, resource : { _tag : "github-media" , cwd : "/repo" , url } } ,
261+ } ) . copyImage ( ) ;
262+
263+ expect ( state . mint ) . not . toHaveBeenCalled ( ) ;
264+ expect ( fetch ) . toHaveBeenCalledExactlyOnceWith ( url ) ;
265+ const [ item ] = state . clipboard . mock . calls [ 0 ] ! [ 0 ] ;
266+ expect ( await item . items [ "image/png" ] ) . toEqual ( png ) ;
267+ } ) ;
268+
269+ it ( "does not bypass host-file assets through their display URL when disconnected" , async ( ) => {
270+ state . connection . mockReturnValue ( null ) ;
271+ state . sessions . set ( environmentId , granted ) ;
272+ const source = { ...hostSource ( ) , src : "https://images.example.com/image.png" } ;
273+
274+ await expect ( useMediaActions ( source ) . copyImage ( ) ) . rejects . toThrow ( "Reconnect" ) ;
275+ await expect ( useMediaActions ( source ) . save ( ) ) . rejects . toThrow ( "Reconnect" ) ;
276+ expect ( state . mint ) . not . toHaveBeenCalled ( ) ;
277+ expect ( state . png ) . not . toHaveBeenCalled ( ) ;
278+ expect ( state . download ) . not . toHaveBeenCalled ( ) ;
279+ } ) ;
280+
245281it . each ( [ "workspace-file" , "media-file" ] as const ) (
246282 "disables denied %s byte actions and prevents imperative requests" ,
247283 async ( _tag ) => {
0 commit comments