diff --git a/src/integrations/misc/__tests__/extract-text-large-files.spec.ts b/src/integrations/misc/__tests__/extract-text-large-files.spec.ts index c9e2f181f5a..662d3256a94 100644 --- a/src/integrations/misc/__tests__/extract-text-large-files.spec.ts +++ b/src/integrations/misc/__tests__/extract-text-large-files.spec.ts @@ -152,15 +152,19 @@ describe("extractTextFromFile - Large File Handling", () => { expect(result).toContain("[File truncated: showing 500 of 10000 total lines") }) - it("should handle maxReadFileLine of 0 by throwing an error", async () => { + it("should handle maxReadFileLine of 0 by treating as unlimited", async () => { const fileContent = "Line 1\nLine 2\nLine 3" mockedFs.readFile.mockResolvedValue(fileContent as any) - // maxReadFileLine of 0 should throw an error - await expect(extractTextFromFile("/test/file.ts", 0)).rejects.toThrow( - "Invalid maxReadFileLine: 0. Must be a positive integer or -1 for unlimited.", - ) + // maxReadFileLine of 0 should be treated as unlimited (same as -1) + const result = await extractTextFromFile("/test/file.ts", 0) + + // Should include all content with line numbers + expect(result).toContain("1 | Line 1") + expect(result).toContain("2 | Line 2") + expect(result).toContain("3 | Line 3") + expect(result).not.toContain("[File truncated:") }) it("should handle negative maxReadFileLine by treating as undefined", async () => { diff --git a/src/integrations/misc/extract-text.ts b/src/integrations/misc/extract-text.ts index bafa7a5bab1..b120bcaf173 100644 --- a/src/integrations/misc/extract-text.ts +++ b/src/integrations/misc/extract-text.ts @@ -63,10 +63,11 @@ export function getSupportedBinaryFormats(): string[] { */ export async function extractTextFromFile(filePath: string, maxReadFileLine?: number): Promise { // Validate maxReadFileLine parameter - if (maxReadFileLine !== undefined && maxReadFileLine !== -1) { + // 0 is treated as unlimited (same as -1) for backward compatibility + if (maxReadFileLine !== undefined && maxReadFileLine !== -1 && maxReadFileLine !== 0) { if (!Number.isInteger(maxReadFileLine) || maxReadFileLine < 1) { throw new Error( - `Invalid maxReadFileLine: ${maxReadFileLine}. Must be a positive integer or -1 for unlimited.`, + `Invalid maxReadFileLine: ${maxReadFileLine}. Must be a positive integer, 0, or -1 for unlimited.`, ) } } @@ -90,7 +91,8 @@ export async function extractTextFromFile(filePath: string, maxReadFileLine?: nu if (!isBinary) { // Check if we need to apply line limit - if (maxReadFileLine !== undefined && maxReadFileLine !== -1) { + // 0 is treated as unlimited (same as -1) for backward compatibility + if (maxReadFileLine !== undefined && maxReadFileLine !== -1 && maxReadFileLine !== 0) { const totalLines = await countFileLines(filePath) if (totalLines > maxReadFileLine) { // Read only up to maxReadFileLine (endLine is 0-based and inclusive)