@@ -399,78 +399,101 @@ suite.define(() => {
399399 }
400400 } ) ;
401401
402- it ( "renders a canonical inbound image through the ticketed media route" , async ( ) => {
403- const artifactDir = process . env . OPENCLAW_UI_E2E_ARTIFACT_DIR ?. trim ( ) ;
404- const context = await suite . newBrowserContext ( {
405- locale : "en-US" ,
406- serviceWorkers : "block" ,
407- viewport : { height : 900 , width : 1280 } ,
408- } ) ;
409- const page = await context . newPage ( ) ;
410- const requestedMediaUrls : URL [ ] = [ ] ;
411- await page . route ( "**/__openclaw__/assistant-media?**" , async ( route ) => {
412- const request = route . request ( ) ;
413- const url = new URL ( request . url ( ) ) ;
414- requestedMediaUrls . push ( url ) ;
415- expect ( url . searchParams . get ( "source" ) ) . toBe ( "media://inbound/telegram-photo.png" ) ;
416- if ( url . searchParams . get ( "meta" ) === "1" ) {
417- expect ( request . headers ( ) . authorization ) . toBe ( "Bearer e2e-device-token" ) ;
402+ it . each ( [
403+ {
404+ name : "canonical inbound" ,
405+ source : "media://inbound/telegram-photo.png" ,
406+ workspaceDir : undefined ,
407+ screenshotName : "canonical-inbound-image" ,
408+ } ,
409+ {
410+ name : "sandbox-staged inbound" ,
411+ source : "/workspace/media/inbound/fabricated-sandbox.png" ,
412+ workspaceDir : "/workspace" ,
413+ screenshotName : "sandbox-inbound-image" ,
414+ } ,
415+ ] as const ) (
416+ "renders a $name image through the ticketed media route" ,
417+ async ( { source, workspaceDir, screenshotName } ) => {
418+ const artifactDir = process . env . OPENCLAW_UI_E2E_ARTIFACT_DIR ?. trim ( ) ;
419+ const context = await suite . newBrowserContext ( {
420+ locale : "en-US" ,
421+ serviceWorkers : "block" ,
422+ viewport : { height : 900 , width : 1280 } ,
423+ } ) ;
424+ const page = await context . newPage ( ) ;
425+ const requestedMediaUrls : URL [ ] = [ ] ;
426+ await page . route ( "**/__openclaw__/assistant-media?**" , async ( route ) => {
427+ const request = route . request ( ) ;
428+ const url = new URL ( request . url ( ) ) ;
429+ requestedMediaUrls . push ( url ) ;
430+ expect ( url . searchParams . get ( "source" ) ) . toBe ( source ) ;
431+ if ( url . searchParams . get ( "meta" ) === "1" ) {
432+ expect ( request . headers ( ) . authorization ) . toBe ( "Bearer e2e-device-token" ) ;
433+ await route . fulfill ( {
434+ contentType : "application/json" ,
435+ body : JSON . stringify ( {
436+ available : true ,
437+ mediaTicket : "ticket-inbound" ,
438+ mediaTicketExpiresAt : new Date ( Date . now ( ) + 5 * 60_000 ) . toISOString ( ) ,
439+ } ) ,
440+ } ) ;
441+ return ;
442+ }
443+ expect ( url . searchParams . get ( "mediaTicket" ) ) . toBe ( "ticket-inbound" ) ;
444+ expect ( request . headers ( ) . authorization ) . toBeUndefined ( ) ;
418445 await route . fulfill ( {
419- contentType : "application/json" ,
420- body : JSON . stringify ( {
421- available : true ,
422- mediaTicket : "ticket-inbound" ,
423- mediaTicketExpiresAt : new Date ( Date . now ( ) + 5 * 60_000 ) . toISOString ( ) ,
424- } ) ,
446+ contentType : "image/png" ,
447+ body : Buffer . from (
448+ "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9Y9Zl1sAAAAASUVORK5CYII=" ,
449+ "base64" ,
450+ ) ,
425451 } ) ;
426- return ;
427- }
428- expect ( url . searchParams . get ( "mediaTicket" ) ) . toBe ( "ticket-inbound" ) ;
429- await route . fulfill ( {
430- contentType : "image/png" ,
431- body : Buffer . from (
432- "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9Y9Zl1sAAAAASUVORK5CYII=" ,
433- "base64" ,
434- ) ,
435452 } ) ;
436- } ) ;
437- await installMockGateway ( page , {
438- historyMessages : [
439- {
440- id : "user-inbound-media-ref" ,
441- role : "user" ,
442- content : [ { type : "text" , text : "🖼️ Attached image" } ] ,
443- __openclaw : {
444- media : [ { path : "media://inbound/telegram-photo.png" , contentType : "image/png" } ] ,
453+ await installMockGateway ( page , {
454+ historyMessages : [
455+ {
456+ id : "user-inbound-media-ref" ,
457+ role : "user" ,
458+ content : [ { type : "text" , text : "🖼️ Attached image" } ] ,
459+ __openclaw : {
460+ media : [
461+ {
462+ path : source ,
463+ contentType : "image/png" ,
464+ ...( workspaceDir ? { workspaceDir } : { } ) ,
465+ } ,
466+ ] ,
467+ } ,
468+ timestamp : Date . now ( ) ,
445469 } ,
446- timestamp : Date . now ( ) ,
447- } ,
448- ] ,
449- } ) ;
470+ ] ,
471+ } ) ;
450472
451- try {
452- await page . goto ( `${ suite . server . baseUrl } chat` ) ;
453- await expect . poll ( ( ) => requestedMediaUrls . length , { timeout : 10_000 } ) . toBe ( 2 ) ;
454- const image = page . locator ( "img.chat-message-image" ) ;
455- await image . waitFor ( { state : "visible" , timeout : 10_000 } ) ;
456- await expect
457- . poll ( ( ) =>
458- image . evaluate ( ( element ) =>
459- element instanceof HTMLImageElement && element . complete ? element . naturalWidth : 0 ,
460- ) ,
461- )
462- . toBe ( 1 ) ;
463- if ( artifactDir ) {
464- await mkdir ( artifactDir , { recursive : true } ) ;
465- await page . screenshot ( {
466- fullPage : true ,
467- path : `${ artifactDir } /canonical-inbound-image.png` ,
468- } ) ;
473+ try {
474+ await page . goto ( `${ suite . server . baseUrl } chat` ) ;
475+ await expect . poll ( ( ) => requestedMediaUrls . length , { timeout : 10_000 } ) . toBe ( 2 ) ;
476+ const image = page . locator ( "img.chat-message-image" ) ;
477+ await image . waitFor ( { state : "visible" , timeout : 10_000 } ) ;
478+ await expect
479+ . poll ( ( ) =>
480+ image . evaluate ( ( element ) =>
481+ element instanceof HTMLImageElement && element . complete ? element . naturalWidth : 0 ,
482+ ) ,
483+ )
484+ . toBe ( 1 ) ;
485+ if ( artifactDir ) {
486+ await mkdir ( artifactDir , { recursive : true } ) ;
487+ await page . screenshot ( {
488+ fullPage : true ,
489+ path : `${ artifactDir } /${ screenshotName } .png` ,
490+ } ) ;
491+ }
492+ } finally {
493+ await suite . closeBrowserContext ( context ) ;
469494 }
470- } finally {
471- await suite . closeBrowserContext ( context ) ;
472- }
473- } ) ;
495+ } ,
496+ ) ;
474497
475498 it ( "evicts and refetches managed image Blob URLs after the cache reaches capacity" , async ( ) => {
476499 const context = await suite . newBrowserContext ( {
0 commit comments