@@ -92,11 +92,15 @@ const findCodeBlocks = (
9292
9393describe ( 'memoryImportProcessor' , ( ) => {
9494 beforeEach ( ( ) => {
95- vi . clearAllMocks ( ) ;
95+ vi . resetAllMocks ( ) ; // Use resetAllMocks to clear mock implementations
9696 // Mock console methods
9797 console . warn = vi . fn ( ) ;
9898 console . error = vi . fn ( ) ;
9999 console . debug = vi . fn ( ) ;
100+ // Default mock for lstat (used by findProjectRoot)
101+ mockedFs . lstat . mockRejectedValue (
102+ Object . assign ( new Error ( 'ENOENT' ) , { code : 'ENOENT' } ) ,
103+ ) ;
100104 } ) ;
101105
102106 afterEach ( ( ) => {
@@ -204,20 +208,43 @@ describe('memoryImportProcessor', () => {
204208 ) ;
205209 } ) ;
206210
207- it ( 'should handle file not found errors ' , async ( ) => {
211+ it ( 'should silently preserve content when file not found (ENOENT) ' , async ( ) => {
208212 const content = 'Content @./nonexistent.md more content' ;
209213 const basePath = testPath ( 'test' , 'path' ) ;
210214
211- mockedFs . access . mockRejectedValue ( new Error ( 'File not found' ) ) ;
215+ // Mock ENOENT error (file not found)
216+ mockedFs . access . mockRejectedValue (
217+ Object . assign ( new Error ( 'ENOENT: no such file or directory' ) , {
218+ code : 'ENOENT' ,
219+ } ) ,
220+ ) ;
221+
222+ const result = await processImports ( content , basePath , true ) ;
223+
224+ // Content should be preserved as-is when file doesn't exist
225+ expect ( result . content ) . toBe ( content ) ;
226+ // No error should be logged for ENOENT
227+ expect ( console . error ) . not . toHaveBeenCalled ( ) ;
228+ } ) ;
229+
230+ it ( 'should log error for non-ENOENT file access errors' , async ( ) => {
231+ const content = 'Content @./permission-denied.md more content' ;
232+ const basePath = testPath ( 'test' , 'path' ) ;
233+
234+ // Mock a permission denied error (not ENOENT)
235+ mockedFs . access . mockRejectedValue (
236+ Object . assign ( new Error ( 'Permission denied' ) , { code : 'EACCES' } ) ,
237+ ) ;
212238
213239 const result = await processImports ( content , basePath , true ) ;
214240
241+ // Should show error comment for non-ENOENT errors
215242 expect ( result . content ) . toContain (
216- '<!-- Import failed: ./nonexistent .md - File not found -->' ,
243+ '<!-- Import failed: ./permission-denied .md - Permission denied -->' ,
217244 ) ;
218245 expect ( console . error ) . toHaveBeenCalledWith (
219246 '[ERROR] [ImportProcessor]' ,
220- 'Failed to import ./nonexistent .md: File not found ' ,
247+ 'Failed to import ./permission-denied .md: Permission denied ' ,
221248 ) ;
222249 } ) ;
223250
@@ -448,6 +475,50 @@ describe('memoryImportProcessor', () => {
448475 expect ( result . importTree . imports ) . toBeUndefined ( ) ;
449476 } ) ;
450477
478+ it ( 'should still import valid paths while ignoring non-existent paths' , async ( ) => {
479+ const content = '使用 @./valid.md 文件和 @中文路径 注解' ;
480+ const basePath = testPath ( 'test' , 'path' ) ;
481+ const importedContent = 'Valid imported content' ;
482+
483+ // Mock: valid.md exists, 中文路径 doesn't exist
484+ mockedFs . access
485+ . mockResolvedValueOnce ( undefined ) // ./valid.md exists
486+ . mockRejectedValueOnce (
487+ Object . assign ( new Error ( 'ENOENT' ) , { code : 'ENOENT' } ) ,
488+ ) ; // 中文路径 doesn't exist
489+ mockedFs . readFile . mockResolvedValue ( importedContent ) ;
490+
491+ const result = await processImports ( content , basePath , true ) ;
492+
493+ // Should import valid.md
494+ expect ( result . content ) . toContain ( importedContent ) ;
495+ expect ( result . content ) . toContain ( '<!-- Imported from: ./valid.md -->' ) ;
496+ // The non-existent path should remain as-is
497+ expect ( result . content ) . toContain ( '@中文路径' ) ;
498+ } ) ;
499+
500+ it ( 'should import Chinese file names if they exist' , async ( ) => {
501+ const content = '导入 @./中文文档.md 文件' ;
502+ const projectRoot = testPath ( 'test' , 'project' ) ;
503+ const basePath = testPath ( projectRoot , 'src' ) ;
504+ const importedContent = '这是中文文档的内容' ;
505+
506+ mockedFs . access . mockResolvedValue ( undefined ) ;
507+ mockedFs . readFile . mockResolvedValue ( importedContent ) ;
508+
509+ const result = await processImports (
510+ content ,
511+ basePath ,
512+ true ,
513+ undefined ,
514+ projectRoot ,
515+ ) ;
516+
517+ // Should successfully import the Chinese-named file
518+ expect ( result . content ) . toContain ( importedContent ) ;
519+ expect ( result . content ) . toContain ( '<!-- Imported from: ./中文文档.md -->' ) ;
520+ } ) ;
521+
451522 it ( 'should allow imports from parent and subdirectories within project root' , async ( ) => {
452523 const content =
453524 'Parent import: @../parent.md Subdir import: @./components/sub.md' ;
0 commit comments