File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -341,6 +341,21 @@ export class HarnessExtensionHost {
341341 this . teardownBridge ?.( ) ;
342342 this . teardownBridge = undefined ;
343343 await this . runner ?. emit ( { type : "session_shutdown" , reason : "quit" } ) ;
344+ const managedNames = new Set ( [
345+ ...this . hostTools . map ( ( tool ) => tool . name ) ,
346+ ...this . extensionTools . map ( ( tool ) => tool . name ) ,
347+ ] ) ;
348+ if ( managedNames . size > 0 ) {
349+ const baseTools = this . harness . getTools ( ) . filter ( ( tool ) => ! managedNames . has ( tool . name ) ) ;
350+ const baseNames = new Set ( baseTools . map ( ( tool ) => tool . name ) ) ;
351+ const activeBaseNames = this . harness
352+ . getActiveTools ( )
353+ . map ( ( tool ) => tool . name )
354+ . filter ( ( name ) => baseNames . has ( name ) ) ;
355+ await this . harness . setTools ( baseTools , activeBaseNames ) ;
356+ }
357+ this . extensionTools = [ ] ;
358+ this . inactiveExtensionTools . clear ( ) ;
344359 this . runner = undefined ;
345360 }
346361
Original file line number Diff line number Diff line change @@ -139,6 +139,16 @@ describe("HarnessExtensionHost", () => {
139139 await expect ( created . load ( ) ) . rejects . toThrow ( / d i s p o s e d / ) ;
140140 } ) ;
141141
142+ it ( "removes extension tools from the harness on dispose" , async ( ) => {
143+ const created = await loadHost ( ) ;
144+ expect ( fx ! . harness . getTools ( ) . map ( ( tool ) => tool . name ) ) . toContain ( "click_visual" ) ;
145+ await created . dispose ( ) ;
146+ const tools = fx ! . harness . getTools ( ) . map ( ( tool ) => tool . name ) ;
147+ const active = fx ! . harness . getActiveTools ( ) . map ( ( tool ) => tool . name ) ;
148+ expect ( tools ) . not . toContain ( "click_visual" ) ;
149+ expect ( active ) . not . toContain ( "click_visual" ) ;
150+ } ) ;
151+
142152 it ( "ignores a second load() rather than stacking a duplicate registration" , async ( ) => {
143153 const created = await loadHost ( ) ;
144154 const count = ( ) =>
You can’t perform that action at this time.
0 commit comments