@@ -27,6 +27,12 @@ vi.mock("../../../utils/fs", () => ({
2727 createDirectoriesForFile : vi . fn ( ) . mockResolvedValue ( [ ] ) ,
2828} ) )
2929
30+ // Mock encoding utilities
31+ vi . mock ( "../../../utils/encoding" , ( ) => ( {
32+ readFileWithEncodingDetection : vi . fn ( ) . mockResolvedValue ( "file content" ) ,
33+ writeFileWithEncodingPreservation : vi . fn ( ) . mockResolvedValue ( undefined ) ,
34+ } ) )
35+
3036// Mock path
3137vi . mock ( "path" , async ( ) => {
3238 const actual = await vi . importActual ( "path" ) ;
@@ -382,8 +388,8 @@ describe("DiffViewProvider", () => {
382388 const result = await diffViewProvider . saveDirectly ( "test.ts" , "new content" , true , true , 2000 )
383389
384390 // Verify file was written
385- const fs = await import ( "fs/promises " )
386- expect ( fs . writeFile ) . toHaveBeenCalledWith ( `${ mockCwd } /test.ts` , "new content" , "utf-8 ")
391+ const { writeFileWithEncodingPreservation } = await import ( "../../../utils/encoding " )
392+ expect ( writeFileWithEncodingPreservation ) . toHaveBeenCalledWith ( `${ mockCwd } /test.ts` , "new content" )
387393
388394 // Verify file was opened without focus
389395 expect ( vscode . window . showTextDocument ) . toHaveBeenCalledWith (
@@ -405,8 +411,8 @@ describe("DiffViewProvider", () => {
405411 await diffViewProvider . saveDirectly ( "test.ts" , "new content" , false , true , 1000 )
406412
407413 // Verify file was written
408- const fs = await import ( "fs/promises " )
409- expect ( fs . writeFile ) . toHaveBeenCalledWith ( `${ mockCwd } /test.ts` , "new content" , "utf-8 ")
414+ const { writeFileWithEncodingPreservation } = await import ( "../../../utils/encoding " )
415+ expect ( writeFileWithEncodingPreservation ) . toHaveBeenCalledWith ( `${ mockCwd } /test.ts` , "new content" )
410416
411417 // Verify file was NOT opened
412418 expect ( vscode . window . showTextDocument ) . not . toHaveBeenCalled ( )
@@ -420,8 +426,8 @@ describe("DiffViewProvider", () => {
420426 await diffViewProvider . saveDirectly ( "test.ts" , "new content" , true , false , 1000 )
421427
422428 // Verify file was written
423- const fs = await import ( "fs/promises " )
424- expect ( fs . writeFile ) . toHaveBeenCalledWith ( `${ mockCwd } /test.ts` , "new content" , "utf-8 ")
429+ const { writeFileWithEncodingPreservation } = await import ( "../../../utils/encoding " )
430+ expect ( writeFileWithEncodingPreservation ) . toHaveBeenCalledWith ( `${ mockCwd } /test.ts` , "new content" )
425431
426432 // Verify delay was NOT called
427433 expect ( mockDelay ) . not . toHaveBeenCalled ( )
0 commit comments