@@ -2796,6 +2796,24 @@ describe("browser tool url alias support", () => {
27962796 } ) ;
27972797 } ) ;
27982798
2799+ it ( "untracks the selected tab when close omits targetId" , async ( ) => {
2800+ browserActionsMocks . browserAct . mockResolvedValueOnce ( {
2801+ ok : true ,
2802+ targetId : "selected-tab" ,
2803+ url : "https://example.com" ,
2804+ } ) ;
2805+ const tool = createBrowserTool ( { agentSessionKey : "agent:main:main" } ) ;
2806+
2807+ await tool . execute ?.( "call-1" , { action : "close" } ) ;
2808+
2809+ expect ( sessionTabRegistryMocks . untrackSessionBrowserTab ) . toHaveBeenCalledWith ( {
2810+ sessionKey : "agent:main:main" ,
2811+ targetId : "selected-tab" ,
2812+ baseUrl : undefined ,
2813+ profile : "openclaw" ,
2814+ } ) ;
2815+ } ) ;
2816+
27992817 it ( "never creates tracking records from tab listing or focus" , async ( ) => {
28002818 browserClientMocks . browserTabs . mockResolvedValueOnce ( [
28012819 {
@@ -2817,6 +2835,41 @@ describe("browser tool url alias support", () => {
28172835describe ( "browser tool act compatibility" , ( ) => {
28182836 registerBrowserToolAfterEachReset ( ) ;
28192837
2838+ it . each ( [
2839+ {
2840+ name : "close" ,
2841+ request : { kind : "close" , targetId : "closed-tab" } ,
2842+ result : { ok : true , targetId : "closed-tab" , url : "https://example.com" } ,
2843+ } ,
2844+ {
2845+ name : "batch close" ,
2846+ request : {
2847+ kind : "batch" ,
2848+ targetId : "closed-tab" ,
2849+ actions : [ { kind : "close" } ] ,
2850+ } ,
2851+ result : {
2852+ ok : true ,
2853+ targetId : "closed-tab" ,
2854+ results : [ { ok : true } ] ,
2855+ aborted : { reason : "closed" , afterAction : 1 , url : "https://example.com" , skipped : 0 } ,
2856+ } ,
2857+ } ,
2858+ ] ) ( "retires session ownership after act:$name" , async ( { request, result } ) => {
2859+ browserActionsMocks . browserAct . mockResolvedValueOnce ( result ) ;
2860+ const tool = createBrowserTool ( { agentSessionKey : "agent:main:main" } ) ;
2861+
2862+ await tool . execute ?.( "call-1" , { action : "act" , request } ) ;
2863+
2864+ expect ( sessionTabRegistryMocks . untrackSessionBrowserTab ) . toHaveBeenCalledWith ( {
2865+ sessionKey : "agent:main:main" ,
2866+ targetId : "closed-tab" ,
2867+ baseUrl : undefined ,
2868+ profile : "openclaw" ,
2869+ } ) ;
2870+ expect ( sessionTabRegistryMocks . touchSessionBrowserTab ) . not . toHaveBeenCalled ( ) ;
2871+ } ) ;
2872+
28202873 it ( "adds a clear note when a batch aborts after navigation" , async ( ) => {
28212874 browserActionsMocks . browserAct . mockResolvedValueOnce ( {
28222875 ok : true ,
0 commit comments