summaryrefslogtreecommitdiff
path: root/packages/core/src/tools/glob.test.ts
diff options
context:
space:
mode:
authorYuki Okita <[email protected]>2025-07-31 05:38:20 +0900
committerGitHub <[email protected]>2025-07-30 20:38:20 +0000
commitc1fe6889569610878c45216556fb99424b5bcba4 (patch)
treeb96f5f66bc00426fcd3e4b87402067342abbce12 /packages/core/src/tools/glob.test.ts
parent21965f986c8aa99da5a0f8e52ae823bb2f040d7a (diff)
feat: Multi-Directory Workspace Support (part1: add `--include-directories` option) (#4605)
Co-authored-by: Allen Hutchison <[email protected]>
Diffstat (limited to 'packages/core/src/tools/glob.test.ts')
-rw-r--r--packages/core/src/tools/glob.test.ts37
1 files changed, 35 insertions, 2 deletions
diff --git a/packages/core/src/tools/glob.test.ts b/packages/core/src/tools/glob.test.ts
index 51effe4e..0ee6c0ee 100644
--- a/packages/core/src/tools/glob.test.ts
+++ b/packages/core/src/tools/glob.test.ts
@@ -9,9 +9,10 @@ import { partListUnionToString } from '../core/geminiRequest.js';
import path from 'path';
import fs from 'fs/promises';
import os from 'os';
-import { describe, it, expect, beforeEach, afterEach } from 'vitest'; // Removed vi
+import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { FileDiscoveryService } from '../services/fileDiscoveryService.js';
import { Config } from '../config/config.js';
+import { createMockWorkspaceContext } from '../test-utils/mockWorkspaceContext.js';
describe('GlobTool', () => {
let tempRootDir: string; // This will be the rootDirectory for the GlobTool instance
@@ -23,6 +24,7 @@ describe('GlobTool', () => {
getFileService: () => new FileDiscoveryService(tempRootDir),
getFileFilteringRespectGitIgnore: () => true,
getTargetDir: () => tempRootDir,
+ getWorkspaceContext: () => createMockWorkspaceContext(tempRootDir),
} as unknown as Config;
beforeEach(async () => {
@@ -243,7 +245,7 @@ describe('GlobTool', () => {
path: '../../../../../../../../../../tmp',
}; // Definitely outside
expect(specificGlobTool.validateToolParams(paramsOutside)).toContain(
- "resolves outside the tool's root directory",
+ 'resolves outside the allowed workspace directories',
);
});
@@ -264,6 +266,37 @@ describe('GlobTool', () => {
);
});
});
+
+ describe('workspace boundary validation', () => {
+ it('should validate search paths are within workspace boundaries', () => {
+ const validPath = { pattern: '*.ts', path: 'sub' };
+ const invalidPath = { pattern: '*.ts', path: '../..' };
+
+ expect(globTool.validateToolParams(validPath)).toBeNull();
+ expect(globTool.validateToolParams(invalidPath)).toContain(
+ 'resolves outside the allowed workspace directories',
+ );
+ });
+
+ it('should provide clear error messages when path is outside workspace', () => {
+ const invalidPath = { pattern: '*.ts', path: '/etc' };
+ const error = globTool.validateToolParams(invalidPath);
+
+ expect(error).toContain(
+ 'resolves outside the allowed workspace directories',
+ );
+ expect(error).toContain(tempRootDir);
+ });
+
+ it('should work with paths in workspace subdirectories', async () => {
+ const params: GlobToolParams = { pattern: '*.md', path: 'sub' };
+ const result = await globTool.execute(params, abortSignal);
+
+ expect(result.llmContent).toContain('Found 2 file(s)');
+ expect(result.llmContent).toContain('fileC.md');
+ expect(result.llmContent).toContain('FileD.MD');
+ });
+ });
});
describe('sortFileEntries', () => {