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

View File

@@ -930,7 +930,7 @@ describe('fileUtils', () => {
expect(result.returnDisplay).toContain('Path is a directory');
});
it('should paginate text files correctly (offset and limit)', async () => {
it('should paginate text files correctly (startLine and endLine)', async () => {
const lines = Array.from({ length: 20 }, (_, i) => `Line ${i + 1}`);
actualNodeFs.writeFileSync(testTextFilePath, lines.join('\n'));
@@ -938,9 +938,9 @@ describe('fileUtils', () => {
testTextFilePath,
tempRootDir,
new StandardFileSystemService(),
5,
5,
); // Read lines 6-10
6,
10,
); // Read lines 6-10 (1-based)
const expectedContent = lines.slice(5, 10).join('\n');
expect(result.llmContent).toBe(expectedContent);
@@ -954,13 +954,13 @@ describe('fileUtils', () => {
const lines = Array.from({ length: 20 }, (_, i) => `Line ${i + 1}`);
actualNodeFs.writeFileSync(testTextFilePath, lines.join('\n'));
// Read from line 11 to 20. The start is not 0, so it's truncated.
// Read from line 11 to 20. The start is not 1, so it's truncated.
const result = await processSingleFileContent(
testTextFilePath,
tempRootDir,
new StandardFileSystemService(),
10,
10,
11,
20,
);
const expectedContent = lines.slice(10, 20).join('\n');
@@ -971,7 +971,7 @@ describe('fileUtils', () => {
expect(result.linesShown).toEqual([11, 20]);
});
it('should handle limit exceeding file length', async () => {
it('should handle endLine exceeding file length', async () => {
const lines = ['Line 1', 'Line 2'];
actualNodeFs.writeFileSync(testTextFilePath, lines.join('\n'));
@@ -979,7 +979,7 @@ describe('fileUtils', () => {
testTextFilePath,
tempRootDir,
new StandardFileSystemService(),
0,
1,
10,
);
const expectedContent = lines.join('\n');
@@ -1015,21 +1015,22 @@ describe('fileUtils', () => {
expect(result.isTruncated).toBe(true);
});
it('should truncate when line count exceeds the limit', async () => {
const lines = Array.from({ length: 11 }, (_, i) => `Line ${i + 1}`);
it('should truncate when line count exceeds the default limit', async () => {
const lines = Array.from({ length: 2500 }, (_, i) => `Line ${i + 1}`);
actualNodeFs.writeFileSync(testTextFilePath, lines.join('\n'));
// Read 5 lines, but there are 11 total
// No ranges provided, should use default limit (2000)
const result = await processSingleFileContent(
testTextFilePath,
tempRootDir,
new StandardFileSystemService(),
0,
5,
);
expect(result.isTruncated).toBe(true);
expect(result.returnDisplay).toBe('Read lines 1-5 of 11 from test.txt');
expect(result.returnDisplay).toBe(
'Read lines 1-2000 of 2500 from test.txt',
);
expect(result.linesShown).toEqual([1, 2000]);
});
it('should truncate when a line length exceeds the character limit', async () => {
@@ -1043,7 +1044,7 @@ describe('fileUtils', () => {
testTextFilePath,
tempRootDir,
new StandardFileSystemService(),
0,
1,
11,
);
@@ -1069,7 +1070,7 @@ describe('fileUtils', () => {
testTextFilePath,
tempRootDir,
new StandardFileSystemService(),
0,
1,
10,
);
expect(result.isTruncated).toBe(true);