@@ -178,6 +178,41 @@ it.effect.each([{}, { includeImage: false }])(
178178 ) . pipe ( Effect . provide ( TestLayer ) ) ,
179179) ;
180180
181+ it . effect . each ( [
182+ { args : { } , advice : "No active preview tab was found for snapshot. Call preview_open first." } ,
183+ {
184+ args : { tabId : alternateTabId } ,
185+ advice : `Preview tab ${ alternateTabId } was not found for snapshot. Omit tabId to use the current tab, or call preview_open.` ,
186+ } ,
187+ ] ) ( "tells the agent to open a tab when the snapshot has none $args" , ( { args, advice } ) =>
188+ Effect . scoped (
189+ Effect . gen ( function * ( ) {
190+ const broker = yield * PreviewAutomationBroker . PreviewAutomationBroker ;
191+ const connected = yield * Deferred . make < void > ( ) ;
192+ const events = yield * broker . connect ( { clientId : "mcp-no-tab-client" , environmentId } ) ;
193+ yield * Stream . runForEach ( events , ( event ) =>
194+ event . type === "connected"
195+ ? Deferred . succeed ( connected , undefined )
196+ : broker . respond ( {
197+ clientId : "mcp-no-tab-client" ,
198+ connectionId : event . connectionId ,
199+ requestId : event . request . requestId ,
200+ ok : false ,
201+ error : { _tag : "PreviewAutomationTabNotFoundError" , message : "no tab" } ,
202+ } ) ,
203+ ) . pipe ( Effect . forkScoped ) ;
204+ yield * Deferred . await ( connected ) ;
205+
206+ const snapshot = yield * callSnapshot ( args ) ;
207+
208+ expect ( snapshot . isError ) . toBe ( true ) ;
209+ expect ( snapshot . content ) . toEqual ( [
210+ { type : "text" , text : `Preview snapshot failed: ${ advice } ` } ,
211+ ] ) ;
212+ } ) ,
213+ ) . pipe ( Effect . provide ( TestLayer ) ) ,
214+ ) ;
215+
181216it . effect ( "tells the agent how to fall back when no desktop app can run the snapshot" , ( ) =>
182217 Effect . gen ( function * ( ) {
183218 const snapshot = yield * callSnapshot ( { } ) ;
0 commit comments