feat(core): migrate read_file to 1-based start_line/end_line parameters (#19526)

This commit is contained in:
Adam Weidman
2026-02-20 17:59:18 -05:00
committed by GitHub
parent 58d637f919
commit 547f5d45f5
10 changed files with 140 additions and 106 deletions
+23 -12
View File
@@ -130,29 +130,36 @@ describe('ReadFileTool', () => {
);
});
it('should throw error if offset is negative', () => {
it('should throw error if start_line is less than 1', () => {
const params: ReadFileToolParams = {
file_path: path.join(tempRootDir, 'test.txt'),
offset: -1,
start_line: 0,
};
expect(() => tool.build(params)).toThrow(
'Offset must be a non-negative number',
);
expect(() => tool.build(params)).toThrow('start_line must be at least 1');
});
it('should throw error if limit is zero or negative', () => {
it('should throw error if end_line is less than 1', () => {
const params: ReadFileToolParams = {
file_path: path.join(tempRootDir, 'test.txt'),
limit: 0,
end_line: 0,
};
expect(() => tool.build(params)).toThrow('end_line must be at least 1');
});
it('should throw error if start_line is greater than end_line', () => {
const params: ReadFileToolParams = {
file_path: path.join(tempRootDir, 'test.txt'),
start_line: 10,
end_line: 5,
};
expect(() => tool.build(params)).toThrow(
'Limit must be a positive number',
'start_line cannot be greater than end_line',
);
});
});
describe('getDescription', () => {
it('should return relative path without limit/offset', () => {
it('should return relative path without ranges', () => {
const subDir = path.join(tempRootDir, 'sub', 'dir');
const params: ReadFileToolParams = {
file_path: path.join(subDir, 'file.txt'),
@@ -393,7 +400,7 @@ describe('ReadFileTool', () => {
expect(result.returnDisplay).toBe('');
});
it('should support offset and limit for text files', async () => {
it('should support start_line and end_line for text files', async () => {
const filePath = path.join(tempRootDir, 'paginated.txt');
const lines = Array.from({ length: 20 }, (_, i) => `Line ${i + 1}`);
const fileContent = lines.join('\n');
@@ -401,8 +408,8 @@ describe('ReadFileTool', () => {
const params: ReadFileToolParams = {
file_path: filePath,
offset: 5, // Start from line 6
limit: 3,
start_line: 6,
end_line: 8,
};
const invocation = tool.build(params);
@@ -569,6 +576,10 @@ describe('ReadFileTool', () => {
const schema = tool.getSchema();
expect(schema.name).toBe(ReadFileTool.Name);
expect(schema.description).toMatchSnapshot();
expect(
(schema.parametersJsonSchema as { properties: Record<string, unknown> })
.properties,
).not.toHaveProperty('offset');
});
it('should return the schema from the resolver when modelId is provided', () => {