@@ -20,6 +20,7 @@ import {
2020import * as Context from "effect/Context" ;
2121import * as Deferred from "effect/Deferred" ;
2222import * as Effect from "effect/Effect" ;
23+ import * as FileSystem from "effect/FileSystem" ;
2324import * as Layer from "effect/Layer" ;
2425import * as Logger from "effect/Logger" ;
2526import * as Schema from "effect/Schema" ;
@@ -467,6 +468,57 @@ it.effect.each([
467468 ) . pipe ( Effect . provide ( layerTest ) ) ,
468469) ;
469470
471+ it . effect ( "saves the uncapped screenshot while the agent sees the capped one" , ( ) =>
472+ Effect . scoped (
473+ Effect . gen ( function * ( ) {
474+ const server = yield * McpServer . McpServer ;
475+ const broker = yield * PreviewAutomationBroker . PreviewAutomationBroker ;
476+ const connected = yield * Deferred . make < void > ( ) ;
477+ const capped =
478+ "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jRZkAAAAASUVORK5CYII=" ;
479+ const full =
480+ "iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAAAAABX3VL4AAAADklEQVR4nGNgYGBgYAAAAAYAAXKCmeoAAAAASUVORK5CYII=" ;
481+ const events = yield * broker . connect ( { clientId : "mcp-save-client" , environmentId } ) ;
482+ yield * Stream . runForEach ( events , ( event ) => {
483+ if ( event . type === "connected" ) return Deferred . succeed ( connected , undefined ) ;
484+ expect ( event . request . input ) . toEqual ( { fullScreenshot : true } ) ;
485+ return broker . respond ( {
486+ clientId : "mcp-save-client" ,
487+ connectionId : event . connectionId ,
488+ requestId : event . request . requestId ,
489+ ok : true ,
490+ result : {
491+ ...snapshotResult ,
492+ screenshot : { mimeType : "image/png" , data : capped , width : 1 , height : 1 } ,
493+ fullScreenshot : { data : full , width : 2 , height : 2 } ,
494+ } ,
495+ } ) ;
496+ } ) . pipe ( Effect . forkScoped ) ;
497+ yield * Deferred . await ( connected ) ;
498+
499+ const snapshot = yield * server
500+ . callTool ( {
501+ name : "preview_snapshot" ,
502+ arguments : { tabId : alternateTabId , save : true , includeImage : true } ,
503+ } )
504+ . pipe (
505+ Effect . provideService ( McpInvocationContext . McpInvocationContext , invocation ) ,
506+ Effect . provideService ( McpSchema . McpServerClient , client ) ,
507+ ) ;
508+ const { screenshotPath } = snapshot . structuredContent as { readonly screenshotPath : string } ;
509+ const saved = yield * ( yield * FileSystem . FileSystem ) . readFile ( screenshotPath ) ;
510+
511+ expect ( Buffer . from ( saved ) . toString ( "base64" ) ) . toBe ( full ) ;
512+ expect ( snapshot . structuredContent ) . not . toHaveProperty ( "fullScreenshot" ) ;
513+ expect ( snapshot . content . at ( - 1 ) ) . toEqual ( {
514+ type : "image" ,
515+ mimeType : "image/png" ,
516+ data : new Uint8Array ( Buffer . from ( capped , "base64" ) ) ,
517+ } ) ;
518+ } ) ,
519+ ) . pipe ( Effect . provide ( layerTest ) ) ,
520+ ) ;
521+
470522it . effect ( "refuses preview tools to a client outside a thread before they run" , ( ) =>
471523 Effect . gen ( function * ( ) {
472524 const server = yield * McpServer . McpServer ;
0 commit comments