@@ -59,6 +59,7 @@ describe("getEnvironmentDetails", () => {
5959 getLastCommand : Mock
6060 getProcessesWithOutput : Mock
6161 cleanCompletedProcessQueue ?: Mock
62+ getCurrentWorkingDirectory : Mock
6263 }
6364
6465 let mockCline : Partial < Task >
@@ -208,6 +209,7 @@ describe("getEnvironmentDetails", () => {
208209 id : "terminal-1" ,
209210 getLastCommand : vi . fn ( ) . mockReturnValue ( "npm test" ) ,
210211 getProcessesWithOutput : vi . fn ( ) . mockReturnValue ( [ ] ) ,
212+ getCurrentWorkingDirectory : vi . fn ( ) . mockReturnValue ( "/test/path/src" ) ,
211213 } as MockTerminal
212214
213215 ; ( TerminalRegistry . getTerminals as Mock ) . mockReturnValue ( [ mockActiveTerminal ] )
@@ -216,7 +218,9 @@ describe("getEnvironmentDetails", () => {
216218 const result = await getEnvironmentDetails ( mockCline as Task )
217219
218220 expect ( result ) . toContain ( "# Actively Running Terminals" )
219- expect ( result ) . toContain ( "Original command: `npm test`" )
221+ expect ( result ) . toContain ( "## Terminal terminal-1 (Active)" )
222+ expect ( result ) . toContain ( "### Working Directory: `/test/path/src`" )
223+ expect ( result ) . toContain ( "### Original command: `npm test`" )
220224 expect ( result ) . toContain ( "Test output" )
221225
222226 mockCline . didEditFile = true
@@ -234,8 +238,10 @@ describe("getEnvironmentDetails", () => {
234238
235239 const mockInactiveTerminal = {
236240 id : "terminal-2" ,
241+ getLastCommand : vi . fn ( ) . mockReturnValue ( "npm build" ) ,
237242 getProcessesWithOutput : vi . fn ( ) . mockReturnValue ( [ mockProcess ] ) ,
238243 cleanCompletedProcessQueue : vi . fn ( ) ,
244+ getCurrentWorkingDirectory : vi . fn ( ) . mockReturnValue ( "/test/path/build" ) ,
239245 } as MockTerminal
240246
241247 ; ( TerminalRegistry . getTerminals as Mock ) . mockImplementation ( ( active : boolean ) =>
@@ -245,13 +251,56 @@ describe("getEnvironmentDetails", () => {
245251 const result = await getEnvironmentDetails ( mockCline as Task )
246252
247253 expect ( result ) . toContain ( "# Inactive Terminals with Completed Process Output" )
248- expect ( result ) . toContain ( "Terminal terminal-2" )
254+ expect ( result ) . toContain ( "## Terminal terminal-2 (Inactive)" )
255+ expect ( result ) . toContain ( "### Working Directory: `/test/path/build`" )
249256 expect ( result ) . toContain ( "Command: `npm build`" )
250257 expect ( result ) . toContain ( "Build output" )
251258
252259 expect ( mockInactiveTerminal . cleanCompletedProcessQueue ) . toHaveBeenCalled ( )
253260 } )
254261
262+ it ( "should include working directory for terminals" , async ( ) => {
263+ const mockActiveTerminal = {
264+ id : "terminal-1" ,
265+ getLastCommand : vi . fn ( ) . mockReturnValue ( "cd /some/path && npm start" ) ,
266+ getProcessesWithOutput : vi . fn ( ) . mockReturnValue ( [ ] ) ,
267+ getCurrentWorkingDirectory : vi . fn ( ) . mockReturnValue ( "/some/path" ) ,
268+ } as MockTerminal
269+
270+ const mockProcess = {
271+ command : "npm test" ,
272+ getUnretrievedOutput : vi . fn ( ) . mockReturnValue ( "Test completed" ) ,
273+ }
274+
275+ const mockInactiveTerminal = {
276+ id : "terminal-2" ,
277+ getLastCommand : vi . fn ( ) . mockReturnValue ( "npm test" ) ,
278+ getProcessesWithOutput : vi . fn ( ) . mockReturnValue ( [ mockProcess ] ) ,
279+ cleanCompletedProcessQueue : vi . fn ( ) ,
280+ getCurrentWorkingDirectory : vi . fn ( ) . mockReturnValue ( "/another/path" ) ,
281+ } as MockTerminal
282+
283+ ; ( TerminalRegistry . getTerminals as Mock ) . mockImplementation ( ( active : boolean ) =>
284+ active ? [ mockActiveTerminal ] : [ mockInactiveTerminal ] ,
285+ )
286+ ; ( TerminalRegistry . getUnretrievedOutput as Mock ) . mockReturnValue ( "Server started" )
287+
288+ const result = await getEnvironmentDetails ( mockCline as Task )
289+
290+ // Check active terminal working directory
291+ expect ( result ) . toContain ( "## Terminal terminal-1 (Active)" )
292+ expect ( result ) . toContain ( "### Working Directory: `/some/path`" )
293+ expect ( result ) . toContain ( "### Original command: `cd /some/path && npm start`" )
294+
295+ // Check inactive terminal working directory
296+ expect ( result ) . toContain ( "## Terminal terminal-2 (Inactive)" )
297+ expect ( result ) . toContain ( "### Working Directory: `/another/path`" )
298+
299+ // Verify the methods were called
300+ expect ( mockActiveTerminal . getCurrentWorkingDirectory ) . toHaveBeenCalled ( )
301+ expect ( mockInactiveTerminal . getCurrentWorkingDirectory ) . toHaveBeenCalled ( )
302+ } )
303+
255304 it ( "should include warning when file writing is not allowed" , async ( ) => {
256305 ; ( isToolAllowedForMode as Mock ) . mockReturnValue ( false )
257306 ; ( getModeBySlug as Mock ) . mockImplementation ( ( slug : string ) => {
@@ -310,6 +359,7 @@ describe("getEnvironmentDetails", () => {
310359 id : "terminal-1" ,
311360 getLastCommand : vi . fn ( ) . mockReturnValue ( "npm test" ) ,
312361 getProcessesWithOutput : vi . fn ( ) . mockReturnValue ( [ ] ) ,
362+ getCurrentWorkingDirectory : vi . fn ( ) . mockReturnValue ( "/test/path" ) ,
313363 } as MockTerminal
314364
315365 ; ( TerminalRegistry . getTerminals as Mock ) . mockReturnValue ( [ mockErrorTerminal ] )
0 commit comments