@@ -1961,6 +1961,47 @@ it.effect("a stalled desktop viewer still gets its size, control and reconnect",
19611961 ) . pipe ( Effect . provide ( layer ) ) ,
19621962) ;
19631963
1964+ it . live ( "the tab the desktop shows is visible and picked for agents without a tab" , ( ) =>
1965+ Effect . scoped (
1966+ Effect . gen ( function * ( ) {
1967+ const broker = yield * Broker . PreviewAutomationBroker ;
1968+ const manager = yield * Manager . PreviewManager ;
1969+ yield * ServerBrowser . ServerBrowser ;
1970+ yield * Effect . yieldNow ;
1971+ const openDesktopTab = Effect . fn ( "openDesktopTab" ) ( function * ( url : string ) {
1972+ desktopRendersNext = true ;
1973+ const opened = yield * manager . open ( {
1974+ threadId : scope . thread . threadId ,
1975+ url,
1976+ runtime : "server" ,
1977+ } ) ;
1978+ const tabId = PreviewTabId . make ( opened . tabId ) ;
1979+ yield * broker . invoke ( { scope, tabId, operation : "status" , input : { } } ) ;
1980+ return tabId ;
1981+ } ) ;
1982+ const recentTab = yield * openDesktopTab ( "http://localhost:5173/recent" ) ;
1983+ const shownTab = yield * openDesktopTab ( "http://localhost:5173/shown" ) ;
1984+ // Opened first and used last, so recency or insertion order alone picks it.
1985+ yield * broker . invoke ( { scope, tabId : recentTab , operation : "status" , input : { } } ) ;
1986+
1987+ shownDesktopTabs . add ( shownTab ) ;
1988+ const status = yield * broker . invoke < PreviewAutomationStatus > ( {
1989+ scope : asSession ( "agent-b" ) ,
1990+ operation : "status" ,
1991+ input : { } ,
1992+ } ) ;
1993+ expect ( status ) . toMatchObject ( {
1994+ tabId : shownTab ,
1995+ visible : true ,
1996+ tabs : [
1997+ expect . objectContaining ( { tabId : recentTab , visible : false } ) ,
1998+ expect . objectContaining ( { tabId : shownTab , visible : true } ) ,
1999+ ] ,
2000+ } ) ;
2001+ } ) ,
2002+ ) . pipe ( Effect . provide ( layer ) ) ,
2003+ ) ;
2004+
19642005it . live ( "agents read a human's tab with no arguments and act on it only while nobody drives" , ( ) =>
19652006 Effect . scoped (
19662007 Effect . gen ( function * ( ) {
0 commit comments