Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions src/core/environment/__tests__/getEnvironmentDetails.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe("getEnvironmentDetails", () => {
getLastCommand: Mock
getProcessesWithOutput: Mock
cleanCompletedProcessQueue?: Mock
getCurrentWorkingDirectory: Mock
}

let mockCline: Partial<Task>
Expand Down Expand Up @@ -208,6 +209,7 @@ describe("getEnvironmentDetails", () => {
id: "terminal-1",
getLastCommand: vi.fn().mockReturnValue("npm test"),
getProcessesWithOutput: vi.fn().mockReturnValue([]),
getCurrentWorkingDirectory: vi.fn().mockReturnValue("/test/path/src"),
} as MockTerminal

;(TerminalRegistry.getTerminals as Mock).mockReturnValue([mockActiveTerminal])
Expand All @@ -216,7 +218,9 @@ describe("getEnvironmentDetails", () => {
const result = await getEnvironmentDetails(mockCline as Task)

expect(result).toContain("# Actively Running Terminals")
expect(result).toContain("Original command: `npm test`")
expect(result).toContain("## Terminal terminal-1 (Active)")
expect(result).toContain("### Working Directory: `/test/path/src`")
expect(result).toContain("### Original command: `npm test`")
expect(result).toContain("Test output")

mockCline.didEditFile = true
Expand All @@ -234,8 +238,10 @@ describe("getEnvironmentDetails", () => {

const mockInactiveTerminal = {
id: "terminal-2",
getLastCommand: vi.fn().mockReturnValue("npm build"),
getProcessesWithOutput: vi.fn().mockReturnValue([mockProcess]),
cleanCompletedProcessQueue: vi.fn(),
getCurrentWorkingDirectory: vi.fn().mockReturnValue("/test/path/build"),
} as MockTerminal

;(TerminalRegistry.getTerminals as Mock).mockImplementation((active: boolean) =>
Expand All @@ -245,13 +251,56 @@ describe("getEnvironmentDetails", () => {
const result = await getEnvironmentDetails(mockCline as Task)

expect(result).toContain("# Inactive Terminals with Completed Process Output")
expect(result).toContain("Terminal terminal-2")
expect(result).toContain("## Terminal terminal-2 (Inactive)")
expect(result).toContain("### Working Directory: `/test/path/build`")
expect(result).toContain("Command: `npm build`")
expect(result).toContain("Build output")

expect(mockInactiveTerminal.cleanCompletedProcessQueue).toHaveBeenCalled()
})

it("should include working directory for terminals", async () => {
const mockActiveTerminal = {
id: "terminal-1",
getLastCommand: vi.fn().mockReturnValue("cd /some/path && npm start"),
getProcessesWithOutput: vi.fn().mockReturnValue([]),
getCurrentWorkingDirectory: vi.fn().mockReturnValue("/some/path"),
} as MockTerminal

const mockProcess = {
command: "npm test",
getUnretrievedOutput: vi.fn().mockReturnValue("Test completed"),
}

const mockInactiveTerminal = {
id: "terminal-2",
getLastCommand: vi.fn().mockReturnValue("npm test"),
getProcessesWithOutput: vi.fn().mockReturnValue([mockProcess]),
cleanCompletedProcessQueue: vi.fn(),
getCurrentWorkingDirectory: vi.fn().mockReturnValue("/another/path"),
} as MockTerminal

;(TerminalRegistry.getTerminals as Mock).mockImplementation((active: boolean) =>
active ? [mockActiveTerminal] : [mockInactiveTerminal],
)
;(TerminalRegistry.getUnretrievedOutput as Mock).mockReturnValue("Server started")

const result = await getEnvironmentDetails(mockCline as Task)

// Check active terminal working directory
expect(result).toContain("## Terminal terminal-1 (Active)")
expect(result).toContain("### Working Directory: `/some/path`")
expect(result).toContain("### Original command: `cd /some/path && npm start`")

// Check inactive terminal working directory
expect(result).toContain("## Terminal terminal-2 (Inactive)")
expect(result).toContain("### Working Directory: `/another/path`")

// Verify the methods were called
expect(mockActiveTerminal.getCurrentWorkingDirectory).toHaveBeenCalled()
expect(mockInactiveTerminal.getCurrentWorkingDirectory).toHaveBeenCalled()
})

it("should include warning when file writing is not allowed", async () => {
;(isToolAllowedForMode as Mock).mockReturnValue(false)
;(getModeBySlug as Mock).mockImplementation((slug: string) => {
Expand Down Expand Up @@ -310,6 +359,7 @@ describe("getEnvironmentDetails", () => {
id: "terminal-1",
getLastCommand: vi.fn().mockReturnValue("npm test"),
getProcessesWithOutput: vi.fn().mockReturnValue([]),
getCurrentWorkingDirectory: vi.fn().mockReturnValue("/test/path"),
} as MockTerminal

;(TerminalRegistry.getTerminals as Mock).mockReturnValue([mockErrorTerminal])
Expand Down
9 changes: 7 additions & 2 deletions src/core/environment/getEnvironmentDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ export async function getEnvironmentDetails(cline: Task, includeFileDetails: boo
terminalDetails += "\n\n# Actively Running Terminals"

for (const busyTerminal of busyTerminals) {
terminalDetails += `\n## Original command: \`${busyTerminal.getLastCommand()}\``
const cwd = busyTerminal.getCurrentWorkingDirectory()
terminalDetails += `\n## Terminal ${busyTerminal.id} (Active)`
terminalDetails += `\n### Working Directory: \`${cwd}\``
terminalDetails += `\n### Original command: \`${busyTerminal.getLastCommand()}\``
let newOutput = TerminalRegistry.getUnretrievedOutput(busyTerminal.id)

if (newOutput) {
Expand Down Expand Up @@ -145,7 +148,9 @@ export async function getEnvironmentDetails(cline: Task, includeFileDetails: boo

// Add this terminal's outputs to the details.
if (terminalOutputs.length > 0) {
terminalDetails += `\n## Terminal ${inactiveTerminal.id}`
const cwd = inactiveTerminal.getCurrentWorkingDirectory()
terminalDetails += `\n## Terminal ${inactiveTerminal.id} (Inactive)`
terminalDetails += `\n### Working Directory: \`${cwd}\``
terminalOutputs.forEach((output) => {
terminalDetails += `\n### New Output\n${output}`
})
Expand Down
Loading