@@ -422,21 +422,22 @@ describe('Lib Functions', () => {
422422 const edits = [
423423 { oldText : 'line2' , newText : 'modified line2' }
424424 ] ;
425-
426- mockFs . rename . mockResolvedValueOnce ( undefined ) ;
427-
425+
426+ mockFs . cp . mockResolvedValueOnce ( undefined ) ;
427+
428428 const result = await applyFileEdits ( '/test/file.txt' , edits , false ) ;
429-
429+
430430 expect ( result ) . toContain ( 'modified line2' ) ;
431- // Should write to temporary file then rename
431+ // Should write to temporary file then copy with force
432432 expect ( mockFs . writeFile ) . toHaveBeenCalledWith (
433433 expect . stringMatching ( / \/ t e s t \/ f i l e \. t x t \. [ a - f 0 - 9 ] + \. t m p $ / ) ,
434434 'line1\nmodified line2\nline3\n' ,
435435 'utf-8'
436436 ) ;
437- expect ( mockFs . rename ) . toHaveBeenCalledWith (
437+ expect ( mockFs . cp ) . toHaveBeenCalledWith (
438438 expect . stringMatching ( / \/ t e s t \/ f i l e \. t x t \. [ a - f 0 - 9 ] + \. t m p $ / ) ,
439- '/test/file.txt'
439+ '/test/file.txt' ,
440+ { force : true }
440441 ) ;
441442 } ) ;
442443
@@ -456,41 +457,43 @@ describe('Lib Functions', () => {
456457 { oldText : 'line1' , newText : 'first line' } ,
457458 { oldText : 'line3' , newText : 'third line' }
458459 ] ;
459-
460- mockFs . rename . mockResolvedValueOnce ( undefined ) ;
461-
460+
461+ mockFs . cp . mockResolvedValueOnce ( undefined ) ;
462+
462463 await applyFileEdits ( '/test/file.txt' , edits , false ) ;
463-
464+
464465 expect ( mockFs . writeFile ) . toHaveBeenCalledWith (
465466 expect . stringMatching ( / \/ t e s t \/ f i l e \. t x t \. [ a - f 0 - 9 ] + \. t m p $ / ) ,
466467 'first line\nline2\nthird line\n' ,
467468 'utf-8'
468469 ) ;
469- expect ( mockFs . rename ) . toHaveBeenCalledWith (
470+ expect ( mockFs . cp ) . toHaveBeenCalledWith (
470471 expect . stringMatching ( / \/ t e s t \/ f i l e \. t x t \. [ a - f 0 - 9 ] + \. t m p $ / ) ,
471- '/test/file.txt'
472+ '/test/file.txt' ,
473+ { force : true }
472474 ) ;
473475 } ) ;
474476
475477 it ( 'handles whitespace-flexible matching' , async ( ) => {
476478 mockFs . readFile . mockResolvedValue ( ' line1\n line2\n line3\n' ) ;
477-
479+
478480 const edits = [
479481 { oldText : 'line2' , newText : 'modified line2' }
480482 ] ;
481-
482- mockFs . rename . mockResolvedValueOnce ( undefined ) ;
483-
483+
484+ mockFs . cp . mockResolvedValueOnce ( undefined ) ;
485+
484486 await applyFileEdits ( '/test/file.txt' , edits , false ) ;
485-
487+
486488 expect ( mockFs . writeFile ) . toHaveBeenCalledWith (
487489 expect . stringMatching ( / \/ t e s t \/ f i l e \. t x t \. [ a - f 0 - 9 ] + \. t m p $ / ) ,
488490 ' line1\n modified line2\n line3\n' ,
489491 'utf-8'
490492 ) ;
491- expect ( mockFs . rename ) . toHaveBeenCalledWith (
493+ expect ( mockFs . cp ) . toHaveBeenCalledWith (
492494 expect . stringMatching ( / \/ t e s t \/ f i l e \. t x t \. [ a - f 0 - 9 ] + \. t m p $ / ) ,
493- '/test/file.txt'
495+ '/test/file.txt' ,
496+ { force : true }
494497 ) ;
495498 } ) ;
496499
@@ -505,73 +508,76 @@ describe('Lib Functions', () => {
505508
506509 it ( 'handles complex multi-line edits with indentation' , async ( ) => {
507510 mockFs . readFile . mockResolvedValue ( 'function test() {\n console.log("hello");\n return true;\n}' ) ;
508-
511+
509512 const edits = [
510- {
511- oldText : ' console.log("hello");\n return true;' ,
512- newText : ' console.log("world");\n console.log("test");\n return false;'
513+ {
514+ oldText : ' console.log("hello");\n return true;' ,
515+ newText : ' console.log("world");\n console.log("test");\n return false;'
513516 }
514517 ] ;
515-
516- mockFs . rename . mockResolvedValueOnce ( undefined ) ;
517-
518+
519+ mockFs . cp . mockResolvedValueOnce ( undefined ) ;
520+
518521 await applyFileEdits ( '/test/file.js' , edits , false ) ;
519-
522+
520523 expect ( mockFs . writeFile ) . toHaveBeenCalledWith (
521524 expect . stringMatching ( / \/ t e s t \/ f i l e \. j s \. [ a - f 0 - 9 ] + \. t m p $ / ) ,
522525 'function test() {\n console.log("world");\n console.log("test");\n return false;\n}' ,
523526 'utf-8'
524527 ) ;
525- expect ( mockFs . rename ) . toHaveBeenCalledWith (
528+ expect ( mockFs . cp ) . toHaveBeenCalledWith (
526529 expect . stringMatching ( / \/ t e s t \/ f i l e \. j s \. [ a - f 0 - 9 ] + \. t m p $ / ) ,
527- '/test/file.js'
530+ '/test/file.js' ,
531+ { force : true }
528532 ) ;
529533 } ) ;
530534
531535 it ( 'handles edits with different indentation patterns' , async ( ) => {
532536 mockFs . readFile . mockResolvedValue ( ' if (condition) {\n doSomething();\n }' ) ;
533-
537+
534538 const edits = [
535- {
536- oldText : 'doSomething();' ,
537- newText : 'doSomethingElse();\n doAnotherThing();'
539+ {
540+ oldText : 'doSomething();' ,
541+ newText : 'doSomethingElse();\n doAnotherThing();'
538542 }
539543 ] ;
540-
541- mockFs . rename . mockResolvedValueOnce ( undefined ) ;
542-
544+
545+ mockFs . cp . mockResolvedValueOnce ( undefined ) ;
546+
543547 await applyFileEdits ( '/test/file.js' , edits , false ) ;
544-
548+
545549 expect ( mockFs . writeFile ) . toHaveBeenCalledWith (
546550 expect . stringMatching ( / \/ t e s t \/ f i l e \. j s \. [ a - f 0 - 9 ] + \. t m p $ / ) ,
547551 ' if (condition) {\n doSomethingElse();\n doAnotherThing();\n }' ,
548552 'utf-8'
549553 ) ;
550- expect ( mockFs . rename ) . toHaveBeenCalledWith (
554+ expect ( mockFs . cp ) . toHaveBeenCalledWith (
551555 expect . stringMatching ( / \/ t e s t \/ f i l e \. j s \. [ a - f 0 - 9 ] + \. t m p $ / ) ,
552- '/test/file.js'
556+ '/test/file.js' ,
557+ { force : true }
553558 ) ;
554559 } ) ;
555560
556561 it ( 'handles CRLF line endings in file content' , async ( ) => {
557562 mockFs . readFile . mockResolvedValue ( 'line1\r\nline2\r\nline3\r\n' ) ;
558-
563+
559564 const edits = [
560565 { oldText : 'line2' , newText : 'modified line2' }
561566 ] ;
562-
563- mockFs . rename . mockResolvedValueOnce ( undefined ) ;
564-
567+
568+ mockFs . cp . mockResolvedValueOnce ( undefined ) ;
569+
565570 await applyFileEdits ( '/test/file.txt' , edits , false ) ;
566-
571+
567572 expect ( mockFs . writeFile ) . toHaveBeenCalledWith (
568573 expect . stringMatching ( / \/ t e s t \/ f i l e \. t x t \. [ a - f 0 - 9 ] + \. t m p $ / ) ,
569574 'line1\nmodified line2\nline3\n' ,
570575 'utf-8'
571576 ) ;
572- expect ( mockFs . rename ) . toHaveBeenCalledWith (
577+ expect ( mockFs . cp ) . toHaveBeenCalledWith (
573578 expect . stringMatching ( / \/ t e s t \/ f i l e \. t x t \. [ a - f 0 - 9 ] + \. t m p $ / ) ,
574- '/test/file.txt'
579+ '/test/file.txt' ,
580+ { force : true }
575581 ) ;
576582 } ) ;
577583 } ) ;
0 commit comments