summaryrefslogtreecommitdiff
path: root/packages/core/src/tools/shell.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/core/src/tools/shell.test.ts')
-rw-r--r--packages/core/src/tools/shell.test.ts38
1 files changed, 37 insertions, 1 deletions
diff --git a/packages/core/src/tools/shell.test.ts b/packages/core/src/tools/shell.test.ts
index 55364197..7f237e3d 100644
--- a/packages/core/src/tools/shell.test.ts
+++ b/packages/core/src/tools/shell.test.ts
@@ -37,6 +37,7 @@ import * as crypto from 'crypto';
import * as summarizer from '../utils/summarizer.js';
import { ToolConfirmationOutcome } from './tools.js';
import { OUTPUT_UPDATE_INTERVAL_MS } from './shell.js';
+import { createMockWorkspaceContext } from '../test-utils/mockWorkspaceContext.js';
describe('ShellTool', () => {
let shellTool: ShellTool;
@@ -53,6 +54,7 @@ describe('ShellTool', () => {
getDebugMode: vi.fn().mockReturnValue(false),
getTargetDir: vi.fn().mockReturnValue('/test/dir'),
getSummarizeToolOutputConfig: vi.fn().mockReturnValue(undefined),
+ getWorkspaceContext: () => createMockWorkspaceContext('.'),
getGeminiClient: vi.fn(),
} as unknown as Config;
@@ -105,7 +107,7 @@ describe('ShellTool', () => {
vi.mocked(fs.existsSync).mockReturnValue(false);
expect(
shellTool.validateToolParams({ command: 'ls', directory: 'rel/path' }),
- ).toBe('Directory must exist.');
+ ).toBe("Directory 'rel/path' is not a registered workspace directory.");
});
});
@@ -385,3 +387,37 @@ describe('ShellTool', () => {
});
});
});
+
+describe('validateToolParams', () => {
+ it('should return null for valid directory', () => {
+ const config = {
+ getCoreTools: () => undefined,
+ getExcludeTools: () => undefined,
+ getTargetDir: () => '/root',
+ getWorkspaceContext: () =>
+ createMockWorkspaceContext('/root', ['/users/test']),
+ } as unknown as Config;
+ const shellTool = new ShellTool(config);
+ const result = shellTool.validateToolParams({
+ command: 'ls',
+ directory: 'test',
+ });
+ expect(result).toBeNull();
+ });
+
+ it('should return error for directory outside workspace', () => {
+ const config = {
+ getCoreTools: () => undefined,
+ getExcludeTools: () => undefined,
+ getTargetDir: () => '/root',
+ getWorkspaceContext: () =>
+ createMockWorkspaceContext('/root', ['/users/test']),
+ } as unknown as Config;
+ const shellTool = new ShellTool(config);
+ const result = shellTool.validateToolParams({
+ command: 'ls',
+ directory: 'test2',
+ });
+ expect(result).toContain('is not a registered workspace directory');
+ });
+});