Fix terminal reuse logic (#7157)

This commit is contained in:
Matt Rubens 2025-08-17 02:10:59 -04:00 committed by GitHub
parent 0d90facc53
commit 185365af5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 5 additions and 33 deletions

View file

@ -213,12 +213,7 @@ describe("executeCommand", () => {
// Verify
expect(rejected).toBe(false)
expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith(
customCwd,
true, // customCwd provided
mockTask.taskId,
"vscode",
)
expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith(customCwd, mockTask.taskId, "vscode")
expect(result).toContain(`within working directory '${customCwd}'`)
})
@ -248,12 +243,7 @@ describe("executeCommand", () => {
// Verify
expect(rejected).toBe(false)
expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith(
resolvedCwd,
true, // customCwd provided
mockTask.taskId,
"vscode",
)
expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith(resolvedCwd, mockTask.taskId, "vscode")
expect(result).toContain(`within working directory '${resolvedCwd.toPosix()}'`)
})
@ -302,12 +292,7 @@ describe("executeCommand", () => {
await executeCommand(mockTask, options)
// Verify
expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith(
mockTask.cwd,
false, // no customCwd
mockTask.taskId,
"vscode",
)
expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith(mockTask.cwd, mockTask.taskId, "vscode")
})
it("should use execa provider when shell integration is disabled", async () => {
@ -330,12 +315,7 @@ describe("executeCommand", () => {
await executeCommand(mockTask, options)
// Verify
expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith(
mockTask.cwd,
false, // no customCwd
mockTask.taskId,
"execa",
)
expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith(mockTask.cwd, mockTask.taskId, "execa")
})
})

View file

@ -238,7 +238,7 @@ export async function executeCommand(
}
}
const terminal = await TerminalRegistry.getOrCreateTerminal(workingDir, !!customCwd, task.taskId, terminalProvider)
const terminal = await TerminalRegistry.getOrCreateTerminal(workingDir, task.taskId, terminalProvider)
if (terminal instanceof Terminal) {
terminal.terminal.show(true)

View file

@ -146,13 +146,11 @@ export class TerminalRegistry {
* directory.
*
* @param cwd The working directory path
* @param requiredCwd Whether the working directory is required (if false, may reuse any non-busy terminal)
* @param taskId Optional task ID to associate with the terminal
* @returns A Terminal instance
*/
public static async getOrCreateTerminal(
cwd: string,
requiredCwd: boolean = false,
taskId?: string,
provider: RooTerminalProvider = "vscode",
): Promise<RooTerminal> {
@ -194,12 +192,6 @@ export class TerminalRegistry {
})
}
// Third priority: Find any non-busy terminal (only if directory is not
// required).
if (!terminal && !requiredCwd) {
terminal = terminals.find((t) => !t.busy && t.provider === provider)
}
// If no suitable terminal found, create a new one.
if (!terminal) {
terminal = this.createTerminal(cwd, provider)