add absolute file path description for windows (#12007)

This commit is contained in:
Gaurav Sehgal
2025-10-27 09:47:13 +05:30
committed by GitHub
parent ee66732ad2
commit 2fa13420ae
4 changed files with 88 additions and 2 deletions
+40
View File
@@ -22,6 +22,14 @@ vi.mock('../telemetry/loggers.js', () => ({
logFileOperation: vi.fn(),
}));
interface ReadFileParameterSchema {
properties: {
absolute_path: {
description: string;
};
};
}
describe('ReadFileTool', () => {
let tempRootDir: string;
let tool: ReadFileTool;
@@ -196,6 +204,38 @@ describe('ReadFileTool', () => {
});
});
describe('constructor', () => {
afterEach(() => {
vi.restoreAllMocks();
});
it('should use windows-style path examples on windows', () => {
vi.spyOn(process, 'platform', 'get').mockReturnValue('win32');
const tool = new ReadFileTool({} as unknown as Config);
const schema = tool.schema;
expect(
(schema.parametersJsonSchema as ReadFileParameterSchema).properties
.absolute_path.description,
).toBe(
"The absolute path to the file to read (e.g., 'C:\\Users\\project\\file.txt'). Relative paths are not supported. You must provide an absolute path.",
);
});
it('should use unix-style path examples on non-windows platforms', () => {
vi.spyOn(process, 'platform', 'get').mockReturnValue('linux');
const tool = new ReadFileTool({} as unknown as Config);
const schema = tool.schema;
expect(
(schema.parametersJsonSchema as ReadFileParameterSchema).properties
.absolute_path.description,
).toBe(
"The absolute path to the file to read (e.g., '/home/user/project/file.txt'). Relative paths are not supported. You must provide an absolute path.",
);
});
});
describe('execute', () => {
it('should return error if file does not exist', async () => {
const filePath = path.join(tempRootDir, 'nonexistent.txt');