@@ -15,6 +15,14 @@ vi.mock("fs/promises", () => ({
1515 readFile : vi . fn ( ) . mockResolvedValue ( "file content" ) ,
1616 writeFile : vi . fn ( ) . mockResolvedValue ( undefined ) ,
1717 access : vi . fn ( ) . mockResolvedValue ( undefined ) ,
18+ mkdir : vi . fn ( ) . mockResolvedValue ( undefined ) ,
19+ rename : vi . fn ( ) . mockResolvedValue ( undefined ) ,
20+ unlink : vi . fn ( ) . mockResolvedValue ( undefined ) ,
21+ } ) )
22+
23+ // Mock safeWriteText (used by saveDirectly)
24+ vi . mock ( "../../../services/file-safety/safeWriteText" , ( ) => ( {
25+ safeWriteText : vi . fn ( ) . mockResolvedValue ( undefined ) ,
1826} ) )
1927
2028// Mock utils
@@ -26,6 +34,8 @@ vi.mock("../../../utils/fs", () => ({
2634vi . mock ( "path" , ( ) => ( {
2735 resolve : vi . fn ( ( cwd , relPath ) => `${ cwd } /${ relPath } ` ) ,
2836 basename : vi . fn ( ( path ) => path . split ( "/" ) . pop ( ) ) ,
37+ dirname : vi . fn ( ( path ) => path . split ( "/" ) . slice ( 0 , - 1 ) . join ( "/" ) || "/" ) ,
38+ join : ( ...args : string [ ] ) => args . join ( "/" ) ,
2939} ) )
3040
3141// Mock vscode
@@ -791,9 +801,9 @@ describe("DiffViewProvider", () => {
791801
792802 const result = await diffViewProvider . saveDirectly ( "test.ts" , "new content" , true , true , 2000 )
793803
794- // Verify file was written
795- const fs = await import ( "fs/promises " )
796- expect ( fs . writeFile ) . toHaveBeenCalledWith ( `${ mockCwd } /test.ts` , "new content" , "utf-8 ")
804+ // Verify file was written via safeWriteText
805+ const { safeWriteText } = await import ( "../../../services/file-safety/safeWriteText " )
806+ expect ( safeWriteText ) . toHaveBeenCalledWith ( `${ mockCwd } /test.ts` , "new content" )
797807
798808 // Verify file was opened without focus
799809 expect ( vscode . window . showTextDocument ) . toHaveBeenCalledWith (
@@ -814,9 +824,9 @@ describe("DiffViewProvider", () => {
814824 it ( "should not open file when openWithoutFocus is false" , async ( ) => {
815825 await diffViewProvider . saveDirectly ( "test.ts" , "new content" , false , true , 1000 )
816826
817- // Verify file was written
818- const fs = await import ( "fs/promises " )
819- expect ( fs . writeFile ) . toHaveBeenCalledWith ( `${ mockCwd } /test.ts` , "new content" , "utf-8 ")
827+ // Verify file was written via safeWriteText
828+ const { safeWriteText } = await import ( "../../../services/file-safety/safeWriteText " )
829+ expect ( safeWriteText ) . toHaveBeenCalledWith ( `${ mockCwd } /test.ts` , "new content" )
820830
821831 // Verify file was NOT opened
822832 expect ( vscode . window . showTextDocument ) . not . toHaveBeenCalled ( )
@@ -829,9 +839,9 @@ describe("DiffViewProvider", () => {
829839
830840 await diffViewProvider . saveDirectly ( "test.ts" , "new content" , true , false , 1000 )
831841
832- // Verify file was written
833- const fs = await import ( "fs/promises " )
834- expect ( fs . writeFile ) . toHaveBeenCalledWith ( `${ mockCwd } /test.ts` , "new content" , "utf-8 ")
842+ // Verify file was written via safeWriteText
843+ const { safeWriteText } = await import ( "../../../services/file-safety/safeWriteText " )
844+ expect ( safeWriteText ) . toHaveBeenCalledWith ( `${ mockCwd } /test.ts` , "new content" )
835845
836846 // Verify delay was NOT called
837847 expect ( mockDelay ) . not . toHaveBeenCalled ( )
0 commit comments