@@ -1900,6 +1900,30 @@ suite('RunInTerminalTool', () => {
19001900 chatServiceDisposeEmitter . fire ( { sessionResources : [ LocalChatSessionUri . forSession ( 'non-existent-session' ) ] , reason : 'cleared' } ) ;
19011901 strictEqual ( runInTerminalTool . sessionTerminalAssociations . size , 0 , 'No associations should exist after handling non-existent session' ) ;
19021902 } ) ;
1903+
1904+ test ( 'should not reuse a disposed cached terminal' , ( ) => {
1905+ const sessionResource = LocalChatSessionUri . forSession ( 'disposed-terminal-session' ) ;
1906+ const disposedTerminal = {
1907+ isDisposed : true ,
1908+ dispose : ( ) => { } ,
1909+ processId : 99999 ,
1910+ } as unknown as ITerminalInstance ;
1911+ runInTerminalTool . sessionTerminalAssociations . set ( sessionResource , {
1912+ instance : disposedTerminal ,
1913+ shellIntegrationQuality : ShellIntegrationQuality . None ,
1914+ isBackground : false ,
1915+ } ) ;
1916+
1917+ // A disposed cached terminal should not be returned by the association lookup
1918+ const cachedTerminal = runInTerminalTool . sessionTerminalAssociations . get ( sessionResource ) ;
1919+ ok ( cachedTerminal , 'Cached terminal should exist in the map' ) ;
1920+ strictEqual ( cachedTerminal ! . instance . isDisposed , true , 'Cached terminal should be disposed' ) ;
1921+
1922+ // Verify the guard condition that _initTerminal uses:
1923+ // cachedTerminal && !cachedTerminal.isBackground && !cachedTerminal.instance.isDisposed
1924+ const wouldReuse = cachedTerminal !== undefined && ! cachedTerminal . isBackground && ! cachedTerminal . instance . isDisposed ;
1925+ strictEqual ( wouldReuse , false , 'Should not reuse a disposed cached terminal' ) ;
1926+ } ) ;
19031927 } ) ;
19041928
19051929 test ( 'should dedupe rapid repeated background input-needed notifications' , ( ) => {
0 commit comments