summaryrefslogtreecommitdiff
path: root/packages/core/src/utils/fileUtils.test.ts
diff options
context:
space:
mode:
authorjoshualitt <[email protected]>2025-08-05 11:52:39 -0700
committerGitHub <[email protected]>2025-08-05 18:52:39 +0000
commit08f14319467cb88ba897a630e1a4c3182e5ae434 (patch)
treec3b87d21e2e621c57cdc91aae7e22c54b0e8a8a0 /packages/core/src/utils/fileUtils.test.ts
parent43d5aaa7980aaa51714175bc9c11d13f39c5d1be (diff)
bug(core): fix `contentRangeTruncated` calculation. (#5329)
Co-authored-by: Jacob Richman <[email protected]>
Diffstat (limited to 'packages/core/src/utils/fileUtils.test.ts')
-rw-r--r--packages/core/src/utils/fileUtils.test.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/core/src/utils/fileUtils.test.ts b/packages/core/src/utils/fileUtils.test.ts
index ca121bca..bcdf3fe7 100644
--- a/packages/core/src/utils/fileUtils.test.ts
+++ b/packages/core/src/utils/fileUtils.test.ts
@@ -426,6 +426,29 @@ describe('fileUtils', () => {
expect(result.linesShown).toEqual([6, 10]);
});
+ it('should identify truncation when reading the end of a file', async () => {
+ 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.
+ const result = await processSingleFileContent(
+ testTextFilePath,
+ tempRootDir,
+ 10,
+ 10,
+ );
+ const expectedContent = lines.slice(10, 20).join('\n');
+
+ expect(result.llmContent).toContain(expectedContent);
+ expect(result.llmContent).toContain(
+ '[File content truncated: showing lines 11-20 of 20 total lines. Use offset/limit parameters to view more.]',
+ );
+ expect(result.returnDisplay).toBe('Read lines 11-20 of 20 from test.txt');
+ expect(result.isTruncated).toBe(true); // This is the key check for the bug
+ expect(result.originalLineCount).toBe(20);
+ expect(result.linesShown).toEqual([11, 20]);
+ });
+
it('should handle limit exceeding file length', async () => {
const lines = ['Line 1', 'Line 2'];
actualNodeFs.writeFileSync(testTextFilePath, lines.join('\n'));