-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: Background commands #6587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ describe("executeCommand", () => { | |
| getState: vitest.fn().mockResolvedValue({ | ||
| terminalOutputLineLimit: 500, | ||
| terminalShellIntegrationDisabled: false, | ||
| experiments: {}, | ||
| }), | ||
| } | ||
|
|
||
|
|
@@ -50,7 +51,7 @@ describe("executeCommand", () => { | |
| cwd: "/test/project", | ||
| taskId: "test-task-123", | ||
| providerRef: { | ||
| deref: vitest.fn().mockResolvedValue(mockProvider), | ||
| deref: vitest.fn().mockReturnValue(mockProvider), | ||
liwilliam2021 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| say: vitest.fn().mockResolvedValue(undefined), | ||
| terminalProcess: undefined, | ||
|
|
@@ -451,4 +452,126 @@ describe("executeCommand", () => { | |
| expect(mockTerminalInstance.getCurrentWorkingDirectory).toHaveBeenCalled() | ||
| }) | ||
| }) | ||
|
|
||
| describe("PREVENT_TERMINAL_DISRUPTION experiment", () => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a test that simulates an interactive command when |
||
| it("should not call terminal.show() when PREVENT_TERMINAL_DISRUPTION is enabled", async () => { | ||
| // Setup: Enable PREVENT_TERMINAL_DISRUPTION experiment | ||
| mockProvider.getState.mockResolvedValue({ | ||
| terminalOutputLineLimit: 500, | ||
| terminalShellIntegrationDisabled: false, | ||
| experiments: { preventTerminalDisruption: true }, | ||
| }) | ||
|
|
||
| // Create a mock Terminal instance | ||
| const vscodeTerminal = new Terminal(1, undefined, "/test/project") | ||
| const mockVSCodeTerminal = vscodeTerminal as any | ||
| mockVSCodeTerminal.terminal = { | ||
| show: vitest.fn(), | ||
| } | ||
| mockVSCodeTerminal.getCurrentWorkingDirectory = vitest.fn().mockReturnValue("/test/project") | ||
| mockVSCodeTerminal.runCommand = vitest | ||
| .fn() | ||
| .mockImplementation((command: string, callbacks: RooTerminalCallbacks) => { | ||
| setTimeout(() => { | ||
| callbacks.onCompleted("Command output", mockProcess) | ||
| callbacks.onShellExecutionComplete({ exitCode: 0 }, mockProcess) | ||
| }, 0) | ||
| return mockProcess | ||
| }) | ||
| ;(TerminalRegistry.getOrCreateTerminal as any).mockResolvedValue(mockVSCodeTerminal) | ||
|
|
||
| const options: ExecuteCommandOptions = { | ||
| executionId: "test-123", | ||
| command: "echo test", | ||
| terminalShellIntegrationDisabled: false, | ||
| terminalOutputLineLimit: 500, | ||
| } | ||
|
|
||
| // Execute | ||
| await executeCommand(mockTask, options) | ||
|
|
||
| // Verify terminal.show() was NOT called | ||
| expect(mockVSCodeTerminal.terminal.show).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("should call terminal.show() when PREVENT_TERMINAL_DISRUPTION is disabled", async () => { | ||
| // Setup: Disable PREVENT_TERMINAL_DISRUPTION experiment | ||
| mockProvider.getState.mockResolvedValue({ | ||
| terminalOutputLineLimit: 500, | ||
| terminalShellIntegrationDisabled: false, | ||
| experiments: { preventTerminalDisruption: false }, | ||
| }) | ||
|
|
||
| // Create a mock Terminal instance | ||
| const vscodeTerminal = new Terminal(1, undefined, "/test/project") | ||
| const mockVSCodeTerminal = vscodeTerminal as any | ||
| mockVSCodeTerminal.terminal = { | ||
| show: vitest.fn(), | ||
| } | ||
| mockVSCodeTerminal.getCurrentWorkingDirectory = vitest.fn().mockReturnValue("/test/project") | ||
| mockVSCodeTerminal.runCommand = vitest | ||
| .fn() | ||
| .mockImplementation((command: string, callbacks: RooTerminalCallbacks) => { | ||
| setTimeout(() => { | ||
| callbacks.onCompleted("Command output", mockProcess) | ||
| callbacks.onShellExecutionComplete({ exitCode: 0 }, mockProcess) | ||
| }, 0) | ||
| return mockProcess | ||
| }) | ||
| ;(TerminalRegistry.getOrCreateTerminal as any).mockResolvedValue(mockVSCodeTerminal) | ||
|
|
||
| const options: ExecuteCommandOptions = { | ||
| executionId: "test-123", | ||
| command: "echo test", | ||
| terminalShellIntegrationDisabled: false, | ||
| terminalOutputLineLimit: 500, | ||
| } | ||
|
|
||
| // Execute | ||
| await executeCommand(mockTask, options) | ||
|
|
||
| // Verify terminal.show() was called | ||
| expect(mockVSCodeTerminal.terminal.show).toHaveBeenCalledWith(true) | ||
| }) | ||
|
|
||
| it("should call terminal.show() when PREVENT_TERMINAL_DISRUPTION is not present in experiments", async () => { | ||
| // Setup: No PREVENT_TERMINAL_DISRUPTION in experiments | ||
| mockProvider.getState.mockResolvedValue({ | ||
| terminalOutputLineLimit: 500, | ||
| terminalShellIntegrationDisabled: false, | ||
| experiments: {}, | ||
| }) | ||
|
|
||
| // Create a mock Terminal instance | ||
| const vscodeTerminal = new Terminal(1, undefined, "/test/project") | ||
| const mockVSCodeTerminal = vscodeTerminal as any | ||
| mockVSCodeTerminal.terminal = { | ||
| show: vitest.fn(), | ||
| } | ||
| mockVSCodeTerminal.getCurrentWorkingDirectory = vitest.fn().mockReturnValue("/test/project") | ||
| mockVSCodeTerminal.runCommand = vitest | ||
| .fn() | ||
| .mockImplementation((command: string, callbacks: RooTerminalCallbacks) => { | ||
| setTimeout(() => { | ||
| callbacks.onCompleted("Command output", mockProcess) | ||
| callbacks.onShellExecutionComplete({ exitCode: 0 }, mockProcess) | ||
| }, 0) | ||
| return mockProcess | ||
| }) | ||
| ;(TerminalRegistry.getOrCreateTerminal as any).mockResolvedValue(mockVSCodeTerminal) | ||
|
|
||
| const options: ExecuteCommandOptions = { | ||
| executionId: "test-123", | ||
| command: "echo test", | ||
| terminalShellIntegrationDisabled: false, | ||
| terminalOutputLineLimit: 500, | ||
| } | ||
|
|
||
| // Execute | ||
| await executeCommand(mockTask, options) | ||
|
|
||
| // Verify terminal.show() was called | ||
| expect(mockVSCodeTerminal.terminal.show).toHaveBeenCalledWith(true) | ||
| }) | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Integration test for PREVENT_TERMINAL_DISRUPTION functionality | ||
| // npx vitest run src/core/tools/__tests__/executeCommandTool.preventTerminalDisruption.integration.spec.ts | ||
|
|
||
| import { EXPERIMENT_IDS, experiments } from "../../../shared/experiments" | ||
|
|
||
| describe("PREVENT_TERMINAL_DISRUPTION integration", () => { | ||
| it("should have PREVENT_TERMINAL_DISRUPTION experiment defined", () => { | ||
| expect(EXPERIMENT_IDS.PREVENT_TERMINAL_DISRUPTION).toBe("preventTerminalDisruption") | ||
| }) | ||
|
|
||
| it("should correctly check if PREVENT_TERMINAL_DISRUPTION is enabled", () => { | ||
| // Test when experiment is disabled (default) | ||
| const disabledConfig = { preventTerminalDisruption: false } | ||
| expect(experiments.isEnabled(disabledConfig, EXPERIMENT_IDS.PREVENT_TERMINAL_DISRUPTION)).toBe(false) | ||
|
|
||
| // Test when experiment is enabled | ||
| const enabledConfig = { preventTerminalDisruption: true } | ||
| expect(experiments.isEnabled(enabledConfig, EXPERIMENT_IDS.PREVENT_TERMINAL_DISRUPTION)).toBe(true) | ||
|
|
||
| // Test when experiment is not in config (should use default) | ||
| const emptyConfig = {} | ||
| expect(experiments.isEnabled(emptyConfig, EXPERIMENT_IDS.PREVENT_TERMINAL_DISRUPTION)).toBe(false) | ||
| }) | ||
|
|
||
| it("should verify the executeCommandTool imports experiments correctly", async () => { | ||
| // This test verifies that the executeCommandTool module can import and use experiments | ||
| const executeCommandModule = await import("../executeCommandTool") | ||
| expect(executeCommandModule).toBeDefined() | ||
| expect(executeCommandModule.executeCommand).toBeDefined() | ||
| expect(executeCommandModule.executeCommandTool).toBeDefined() | ||
| }) | ||
|
|
||
| it("should verify Terminal class structure for show method", async () => { | ||
| // This test verifies the Terminal class has the expected structure | ||
| const terminalModule = await import("../../../integrations/terminal/Terminal") | ||
| expect(terminalModule.Terminal).toBeDefined() | ||
|
|
||
| // The Terminal class should have a constructor that accepts a terminal | ||
| const Terminal = terminalModule.Terminal | ||
| expect(typeof Terminal).toBe("function") | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ import { TerminalRegistry } from "../../integrations/terminal/TerminalRegistry" | |
| import { Terminal } from "../../integrations/terminal/Terminal" | ||
| import { Package } from "../../shared/package" | ||
| import { t } from "../../i18n" | ||
| import { EXPERIMENT_IDS, experiments } from "../../shared/experiments" | ||
|
|
||
| class ShellIntegrationError extends Error {} | ||
|
|
||
|
|
@@ -241,7 +242,20 @@ export async function executeCommand( | |
| const terminal = await TerminalRegistry.getOrCreateTerminal(workingDir, task.taskId, terminalProvider) | ||
|
|
||
| if (terminal instanceof Terminal) { | ||
| terminal.terminal.show(true) | ||
| // Check if PREVENT_TERMINAL_DISRUPTION is enabled | ||
liwilliam2021 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // This experimental feature allows commands to run in the background without | ||
| // automatically switching focus to the terminal output, improving workflow continuity | ||
| const provider = task.providerRef.deref() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: you already read provider state in executeCommandTool earlier. You can pass a precomputed flag (e.g., |
||
| const state = provider ? await provider.getState() : null | ||
| const preventTerminalDisruption = experiments.isEnabled( | ||
liwilliam2021 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| state?.experiments ?? {}, | ||
| EXPERIMENT_IDS.PREVENT_TERMINAL_DISRUPTION, | ||
| ) | ||
|
|
||
| // Only show terminal if PREVENT_TERMINAL_DISRUPTION is not enabled | ||
| if (!preventTerminalDisruption) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding an escape hatch to the options to explicitly force terminal focus when needed, e.g. |
||
| terminal.terminal.show(true) | ||
| } | ||
|
|
||
| // Update the working directory in case the terminal we asked for has | ||
| // a different working directory so that the model will know where the | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { EXPERIMENT_IDS, experimentConfigsMap, experimentDefault, experiments } from "../experiments" | ||
|
|
||
| describe("PREVENT_TERMINAL_DISRUPTION experiment", () => { | ||
| it("should include PREVENT_TERMINAL_DISRUPTION in EXPERIMENT_IDS", () => { | ||
| expect(EXPERIMENT_IDS.PREVENT_TERMINAL_DISRUPTION).toBe("preventTerminalDisruption") | ||
| }) | ||
|
|
||
| it("should have PREVENT_TERMINAL_DISRUPTION in experimentConfigsMap", () => { | ||
| expect(experimentConfigsMap.PREVENT_TERMINAL_DISRUPTION).toBeDefined() | ||
| expect(experimentConfigsMap.PREVENT_TERMINAL_DISRUPTION.enabled).toBe(false) | ||
| }) | ||
|
|
||
| it("should have PREVENT_TERMINAL_DISRUPTION in experimentDefault", () => { | ||
| expect(experimentDefault.preventTerminalDisruption).toBe(false) | ||
| }) | ||
|
|
||
| it("should correctly check if PREVENT_TERMINAL_DISRUPTION is enabled", () => { | ||
| // Test when experiment is disabled (default) | ||
| const disabledConfig = { preventTerminalDisruption: false } | ||
| expect(experiments.isEnabled(disabledConfig, EXPERIMENT_IDS.PREVENT_TERMINAL_DISRUPTION)).toBe(false) | ||
|
|
||
| // Test when experiment is enabled | ||
| const enabledConfig = { preventTerminalDisruption: true } | ||
| expect(experiments.isEnabled(enabledConfig, EXPERIMENT_IDS.PREVENT_TERMINAL_DISRUPTION)).toBe(true) | ||
|
|
||
| // Test when experiment is not in config (should use default) | ||
| const emptyConfig = {} | ||
| expect(experiments.isEnabled(emptyConfig, EXPERIMENT_IDS.PREVENT_TERMINAL_DISRUPTION)).toBe(false) | ||
| }) | ||
| }) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.