summaryrefslogtreecommitdiff
path: root/packages/core/src/tools/read-file.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/read-file.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/read-file.test.ts')
-rw-r--r--packages/core/src/tools/read-file.test.ts39
1 files changed, 37 insertions, 2 deletions
diff --git a/packages/core/src/tools/read-file.test.ts b/packages/core/src/tools/read-file.test.ts
index e06c353a..f4086a2b 100644
--- a/packages/core/src/tools/read-file.test.ts
+++ b/packages/core/src/tools/read-file.test.ts
@@ -12,6 +12,7 @@ import fs from 'fs';
import fsp from 'fs/promises';
import { Config } from '../config/config.js';
import { FileDiscoveryService } from '../services/fileDiscoveryService.js';
+import { createMockWorkspaceContext } from '../test-utils/mockWorkspaceContext.js';
describe('ReadFileTool', () => {
let tempRootDir: string;
@@ -27,6 +28,7 @@ describe('ReadFileTool', () => {
const mockConfigInstance = {
getFileService: () => new FileDiscoveryService(tempRootDir),
getTargetDir: () => tempRootDir,
+ getWorkspaceContext: () => createMockWorkspaceContext(tempRootDir),
} as unknown as Config;
tool = new ReadFileTool(mockConfigInstance);
});
@@ -65,8 +67,9 @@ describe('ReadFileTool', () => {
it('should return error for path outside root', () => {
const outsidePath = path.resolve(os.tmpdir(), 'outside-root.txt');
const params: ReadFileToolParams = { absolute_path: outsidePath };
- expect(tool.validateToolParams(params)).toMatch(
- /File path must be within the root directory/,
+ const error = tool.validateToolParams(params);
+ expect(error).toContain(
+ 'File path must be within one of the workspace directories',
);
});
@@ -261,4 +264,36 @@ describe('ReadFileTool', () => {
});
});
});
+
+ describe('workspace boundary validation', () => {
+ it('should validate paths are within workspace root', () => {
+ const params: ReadFileToolParams = {
+ absolute_path: path.join(tempRootDir, 'file.txt'),
+ };
+ expect(tool.validateToolParams(params)).toBeNull();
+ });
+
+ it('should reject paths outside workspace root', () => {
+ const params: ReadFileToolParams = {
+ absolute_path: '/etc/passwd',
+ };
+ const error = tool.validateToolParams(params);
+ expect(error).toContain(
+ 'File path must be within one of the workspace directories',
+ );
+ expect(error).toContain(tempRootDir);
+ });
+
+ it('should provide clear error message with workspace directories', () => {
+ const outsidePath = path.join(os.tmpdir(), 'outside-workspace.txt');
+ const params: ReadFileToolParams = {
+ absolute_path: outsidePath,
+ };
+ const error = tool.validateToolParams(params);
+ expect(error).toContain(
+ 'File path must be within one of the workspace directories',
+ );
+ expect(error).toContain(tempRootDir);
+ });
+ });
});