feat: add audio and video support to read_file (#2556)

This commit is contained in:
Santhosh Kumar
2025-07-02 00:52:32 +05:30
committed by GitHub
parent 63ed8d6499
commit 0275ab0108
3 changed files with 87 additions and 9 deletions

View File

@@ -211,6 +211,16 @@ describe('fileUtils', () => {
expect(detectFileType('file.pdf')).toBe('pdf');
});
it('should detect audio type by extension', () => {
mockMimeLookup.mockReturnValueOnce('audio/mpeg');
expect(detectFileType('song.mp3')).toBe('audio');
});
it('should detect video type by extension', () => {
mockMimeLookup.mockReturnValueOnce('video/mp4');
expect(detectFileType('movie.mp4')).toBe('video');
});
it('should detect known binary extensions as binary (e.g. .zip)', () => {
mockMimeLookup.mockReturnValueOnce('application/zip');
expect(detectFileType('archive.zip')).toBe('binary');
@@ -427,5 +437,23 @@ describe('fileUtils', () => {
);
expect(result.isTruncated).toBe(true);
});
it('should return an error if the file size exceeds 20MB', async () => {
// Create a file just over 20MB
const twentyOneMB = 21 * 1024 * 1024;
const buffer = Buffer.alloc(twentyOneMB, 0x61); // Fill with 'a'
actualNodeFs.writeFileSync(testTextFilePath, buffer);
const result = await processSingleFileContent(
testTextFilePath,
tempRootDir,
);
expect(result.error).toContain('File size exceeds the 20MB limit');
expect(result.returnDisplay).toContain(
'File size exceeds the 20MB limit',
);
expect(result.llmContent).toContain('File size exceeds the 20MB limit');
});
});
});