From 562c7baa7950260f565bccd4d107367e7658fbae Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sun, 28 Sep 2025 11:06:35 +0900 Subject: [PATCH] Add 2 basic test cases --- .../browser/tools/runInTerminalTool.ts | 2 +- .../test/browser/runInTerminalTool.test.ts | 79 ++++++------------- 2 files changed, 23 insertions(+), 58 deletions(-) diff --git a/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/runInTerminalTool.ts b/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/runInTerminalTool.ts index 2d65758a47e..e96d7fe442c 100644 --- a/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/runInTerminalTool.ts +++ b/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/runInTerminalTool.ts @@ -612,7 +612,7 @@ export class RunInTerminalTool extends Disposable implements IToolImpl { // #region Terminal init - private async _getCopilotShellOrProfile(): Promise { + protected async _getCopilotShellOrProfile(): Promise { const os = await this._osBackend; // Check for chat agent terminal profile first diff --git a/src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/runInTerminalTool.test.ts b/src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/runInTerminalTool.test.ts index 4c9a428b2b6..2f76a3ab2c1 100644 --- a/src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/runInTerminalTool.test.ts +++ b/src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/runInTerminalTool.test.ts @@ -30,6 +30,9 @@ class TestRunInTerminalTool extends RunInTerminalTool { get commandLineAutoApprover() { return this._commandLineAutoApprover; } get sessionTerminalAssociations() { return this._sessionTerminalAssociations; } + getCopilotShellOrProfile() { + return this._getCopilotShellOrProfile(); + } setBackendOs(os: OperatingSystem) { this._osBackend = Promise.resolve(os); } @@ -911,63 +914,6 @@ suite('RunInTerminalTool', () => { }); }); - suite('Terminal Profile Configuration', () => { - test('should use chat agent terminal profile when configured', async () => { - // Set a custom terminal profile for Windows - setConfig(TerminalChatAgentToolsSettingId.TerminalProfileWindows, { - path: 'C:\\Windows\\System32\\cmd.exe', - args: ['/K', 'echo "Custom Terminal"'] - }); - - runInTerminalTool.setBackendOs(OperatingSystem.Windows); - - const result = await executeToolTest({ - command: 'echo hello', - explanation: 'test custom profile', - isBackground: false - }); - - // The test should have a mock that intercepts the profile resolution - // For now, we verify that the setting is properly accessed - ok(result, 'Expected tool to execute successfully with custom profile'); - }); - - test('should fallback to default when no chat agent profile configured', async () => { - // Ensure no terminal profile is set - setConfig(TerminalChatAgentToolsSettingId.TerminalProfileWindows, null); - setConfig(TerminalChatAgentToolsSettingId.TerminalProfileLinux, null); - setConfig(TerminalChatAgentToolsSettingId.TerminalProfileMacOs, null); - - runInTerminalTool.setBackendOs(OperatingSystem.Linux); - - const result = await executeToolTest({ - command: 'echo hello', - explanation: 'test default fallback', - isBackground: false - }); - - ok(result, 'Expected tool to execute successfully with default profile'); - }); - - test('should validate terminal profile configuration', async () => { - // Set invalid terminal profile (missing path) - setConfig(TerminalChatAgentToolsSettingId.TerminalProfileLinux, { - args: ['-l'] - }); - - runInTerminalTool.setBackendOs(OperatingSystem.Linux); - - const result = await executeToolTest({ - command: 'echo hello', - explanation: 'test invalid profile', - isBackground: false - }); - - // Should fallback to default when profile is invalid - ok(result, 'Expected tool to execute successfully with fallback to default profile'); - }); - }); - suite('unique rules deduplication', () => { test('should properly deduplicate rules with same sourceText in auto-approve info', async () => { setAutoApprove({ @@ -983,4 +929,23 @@ suite('RunInTerminalTool', () => { strictEqual(count(autoApproveInfo.value, 'echo'), 1); }); }); + + suite('getCopilotShellOrProfile', () => { + test('should return custom profile when configured', async () => { + runInTerminalTool.setBackendOs(OperatingSystem.Windows); + const customProfile = { path: 'C:\\Windows\\System32\\powershell.exe', args: ['-NoProfile'] }; + setConfig(TerminalChatAgentToolsSettingId.TerminalProfileWindows, customProfile); + + const result = await runInTerminalTool.getCopilotShellOrProfile(); + strictEqual(result, customProfile); + }); + + test('should fall back to default shell when no custom profile is configured', async () => { + runInTerminalTool.setBackendOs(OperatingSystem.Linux); + setConfig(TerminalChatAgentToolsSettingId.TerminalProfileLinux, null); + + const result = await runInTerminalTool.getCopilotShellOrProfile(); + strictEqual(result, 'pwsh'); // From the mock ITerminalProfileResolverService + }); + }); });