summaryrefslogtreecommitdiff
path: root/packages/core/src/utils/fileUtils.test.ts
diff options
context:
space:
mode:
authorConrad Irwin <[email protected]>2025-08-18 16:29:45 -0600
committerGitHub <[email protected]>2025-08-18 22:29:45 +0000
commitfb3ceb0da4e2cd636013c2c36a9c0016c01aa47f (patch)
tree7aa43846dd88bd5acdb8898b0ccd2e685f2d5ece /packages/core/src/utils/fileUtils.test.ts
parent4394b6ab4fc86637b07fcd26b9a790c627d1e065 (diff)
Read and write files through Zed (#6169)
Co-authored-by: Agus Zubiaga <[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, 22 insertions, 1 deletions
diff --git a/packages/core/src/utils/fileUtils.test.ts b/packages/core/src/utils/fileUtils.test.ts
index cfedfe27..7b3e3ca1 100644
--- a/packages/core/src/utils/fileUtils.test.ts
+++ b/packages/core/src/utils/fileUtils.test.ts
@@ -26,6 +26,7 @@ import {
detectFileType,
processSingleFileContent,
} from './fileUtils.js';
+import { StandardFileSystemService } from '../services/fileSystemService.js';
vi.mock('mime-types', () => ({
default: { lookup: vi.fn() },
@@ -280,6 +281,7 @@ describe('fileUtils', () => {
const result = await processSingleFileContent(
testTextFilePath,
tempRootDir,
+ new StandardFileSystemService(),
);
expect(result.llmContent).toBe(content);
expect(result.returnDisplay).toBe('');
@@ -290,6 +292,7 @@ describe('fileUtils', () => {
const result = await processSingleFileContent(
nonexistentFilePath,
tempRootDir,
+ new StandardFileSystemService(),
);
expect(result.error).toContain('File not found');
expect(result.returnDisplay).toContain('File not found');
@@ -303,6 +306,7 @@ describe('fileUtils', () => {
const result = await processSingleFileContent(
testTextFilePath,
tempRootDir,
+ new StandardFileSystemService(),
);
expect(result.error).toContain('Simulated read error');
expect(result.returnDisplay).toContain('Simulated read error');
@@ -317,6 +321,7 @@ describe('fileUtils', () => {
const result = await processSingleFileContent(
testImageFilePath,
tempRootDir,
+ new StandardFileSystemService(),
);
expect(result.error).toContain('Simulated image read error');
expect(result.returnDisplay).toContain('Simulated image read error');
@@ -329,6 +334,7 @@ describe('fileUtils', () => {
const result = await processSingleFileContent(
testImageFilePath,
tempRootDir,
+ new StandardFileSystemService(),
);
expect(
(result.llmContent as { inlineData: unknown }).inlineData,
@@ -350,6 +356,7 @@ describe('fileUtils', () => {
const result = await processSingleFileContent(
testPdfFilePath,
tempRootDir,
+ new StandardFileSystemService(),
);
expect(
(result.llmContent as { inlineData: unknown }).inlineData,
@@ -378,6 +385,7 @@ describe('fileUtils', () => {
const result = await processSingleFileContent(
testSvgFilePath,
tempRootDir,
+ new StandardFileSystemService(),
);
expect(result.llmContent).toBe(svgContent);
@@ -395,6 +403,7 @@ describe('fileUtils', () => {
const result = await processSingleFileContent(
testBinaryFilePath,
tempRootDir,
+ new StandardFileSystemService(),
);
expect(result.llmContent).toContain(
'Cannot display content of binary file',
@@ -403,7 +412,11 @@ describe('fileUtils', () => {
});
it('should handle path being a directory', async () => {
- const result = await processSingleFileContent(directoryPath, tempRootDir);
+ const result = await processSingleFileContent(
+ directoryPath,
+ tempRootDir,
+ new StandardFileSystemService(),
+ );
expect(result.error).toContain('Path is a directory');
expect(result.returnDisplay).toContain('Path is a directory');
});
@@ -415,6 +428,7 @@ describe('fileUtils', () => {
const result = await processSingleFileContent(
testTextFilePath,
tempRootDir,
+ new StandardFileSystemService(),
5,
5,
); // Read lines 6-10
@@ -435,6 +449,7 @@ describe('fileUtils', () => {
const result = await processSingleFileContent(
testTextFilePath,
tempRootDir,
+ new StandardFileSystemService(),
10,
10,
);
@@ -454,6 +469,7 @@ describe('fileUtils', () => {
const result = await processSingleFileContent(
testTextFilePath,
tempRootDir,
+ new StandardFileSystemService(),
0,
10,
);
@@ -476,6 +492,7 @@ describe('fileUtils', () => {
const result = await processSingleFileContent(
testTextFilePath,
tempRootDir,
+ new StandardFileSystemService(),
);
expect(result.llmContent).toContain('Short line');
@@ -497,6 +514,7 @@ describe('fileUtils', () => {
const result = await processSingleFileContent(
testTextFilePath,
tempRootDir,
+ new StandardFileSystemService(),
0,
5,
);
@@ -515,6 +533,7 @@ describe('fileUtils', () => {
const result = await processSingleFileContent(
testTextFilePath,
tempRootDir,
+ new StandardFileSystemService(),
0,
11,
);
@@ -540,6 +559,7 @@ describe('fileUtils', () => {
const result = await processSingleFileContent(
testTextFilePath,
tempRootDir,
+ new StandardFileSystemService(),
0,
10,
);
@@ -558,6 +578,7 @@ describe('fileUtils', () => {
const result = await processSingleFileContent(
testTextFilePath,
tempRootDir,
+ new StandardFileSystemService(),
);
expect(result.error).toContain('File size exceeds the 20MB limit');