@@ -64,6 +64,64 @@ afterEach(() => {
6464} ) ;
6565
6666describe ( 'workbench root switching' , ( ) => {
67+ it ( 'settles unfinished tool cards when their runtime exits' , async ( ) => {
68+ const fixture = apiFixture ( ) ;
69+ const openSession = vi
70+ . fn < PidexApi [ 'openSession' ] > ( )
71+ . mockResolvedValue ( { sessionId : 'runtime' } ) ;
72+ const sessionCommands = vi
73+ . fn < PidexApi [ 'sessionCommands' ] > ( )
74+ . mockResolvedValue ( { commands : [ ] } ) ;
75+ Object . assign ( fixture , { openSession, sessionCommands } ) ;
76+ const { result } = renderHook ( useWorkbench ) ;
77+ await waitFor ( ( ) => expect ( result . current . ws ?. name ) . toBe ( 'api' ) ) ;
78+ act ( ( ) =>
79+ result . current . showSession ( {
80+ cwd : '/code/api' ,
81+ id : 'archive' ,
82+ file : '/sessions/archive.jsonl' ,
83+ title : 'Build' ,
84+ model : '' ,
85+ timestamp : '' ,
86+ messageCount : 0 ,
87+ } ) ,
88+ ) ;
89+ await waitFor ( ( ) => expect ( result . current . tabs ) . toHaveLength ( 1 ) ) ;
90+ const onEvent = fixture . onSessionEvent . mock . calls [ 0 ] [ 0 ] ;
91+ const onExit = fixture . onSessionExit . mock . calls [ 0 ] [ 0 ] ;
92+ act ( ( ) => {
93+ onEvent ( {
94+ sessionId : 'runtime' ,
95+ event : {
96+ type : 'tool_execution_start' ,
97+ toolCallId : 'build' ,
98+ toolName : 'bash' ,
99+ args : { command : 'build' } ,
100+ } ,
101+ } ) ;
102+ onEvent ( {
103+ sessionId : 'runtime' ,
104+ event : {
105+ type : 'tool_execution_update' ,
106+ toolCallId : 'build' ,
107+ partialResult : { content : [ { type : 'text' , text : 'Partial build' } ] } ,
108+ } ,
109+ } ) ;
110+ onExit ( { sessionId : 'other-runtime' } ) ;
111+ } ) ;
112+ expect ( result . current . tabs [ 0 ] . entries [ 0 ] ) . toMatchObject ( { running : true } ) ;
113+ act ( ( ) => onExit ( { sessionId : 'runtime' } ) ) ;
114+ expect ( result . current . tabs [ 0 ] ) . toMatchObject ( {
115+ running : false ,
116+ exited : true ,
117+ } ) ;
118+ expect ( result . current . tabs [ 0 ] . entries [ 0 ] ) . toMatchObject ( {
119+ running : false ,
120+ interrupted : true ,
121+ output : 'Partial build' ,
122+ } ) ;
123+ } ) ;
124+
67125 it ( 'rejects late catalog, file, model and defaults results from a previous root' , async ( ) => {
68126 const fixture = apiFixture ( ) ;
69127 const oldCatalog = deferred < WorkspaceCatalog > ( ) ;
0 commit comments