@@ -648,4 +648,147 @@ describe("ApplyDiffTool failure reporting", () => {
648648 expect ( output ) . not . toContain ( "--- Diff block" )
649649 } )
650650 } )
651+
652+ // ApplyDiffTool.ts lines 108-110 hold the three comparisons that decide whether a replacement
653+ // character already in the file is stepped over or reported as the failure position. Each byte
654+ // sequence below was run through the tool in round U35 and the offset it prints is asserted here.
655+ // The offsets each case must not print are the offsets the surviving mutants at those lines print
656+ // instead; the changed-code mutation report numbers those rows one higher than the head lines
657+ // (printed 109, 110, 111 for head 108, 109, 110), the shift I measured and named on the triage
658+ // comment, so the bytes and the printed offset are the anchors, not the report line number. The
659+ // mutant each case kills is named above it. The 0x41 and 0x3f cases are the shape where the
660+ // replacement character is not at the start of the file, so the reported offset is one.
661+ describe ( "the guard that steps past an encoded replacement character" , ( ) => {
662+ async function runBytesFor ( bytes : Buffer ) : Promise < string > {
663+ mockedReadFile . mockResolvedValue ( bytes )
664+ const applyDiff = vi . fn ( ) . mockResolvedValue ( { success : true , content : "unused" } )
665+ mockTask . diffStrategy = { getName : ( ) => "test" , applyDiff }
666+ await applyDiffTool . execute ( { path : testFilePath , diff : buildDiffContent ( 1 ) } , mockTask , {
667+ askApproval : mockAskApproval ,
668+ handleError : mockHandleError ,
669+ toolCallId : "tool-call-1" ,
670+ pushToolResult : vi . fn ( ( result : ToolResponse ) => {
671+ pushedResult = result
672+ } ) ,
673+ } )
674+ return String ( pushedResult ?? "" )
675+ }
676+
677+ // kills line 108 outer_or_and, line 108 inner_or_and, line 109 clauseB_false
678+ it ( "reports offset 0 for the bytes 0xef 0xef 0xbd" , async ( ) => {
679+ const output = await runBytesFor ( Buffer . from ( [ 0xef , 0xef , 0xbd ] ) )
680+
681+ expect ( output ) . toContain ( "is not valid UTF-8" )
682+ expect ( output ) . toContain ( "first undecodable byte at offset 0)." )
683+ expect ( output ) . not . toContain ( "offset 3)" )
684+ } )
685+
686+ // kills line 108 outer_or_and, line 110 clauseC_false
687+ it ( "reports offset 0 for the bytes 0xef 0xbf 0xef" , async ( ) => {
688+ const output = await runBytesFor ( Buffer . from ( [ 0xef , 0xbf , 0xef ] ) )
689+
690+ expect ( output ) . toContain ( "is not valid UTF-8" )
691+ expect ( output ) . toContain ( "first undecodable byte at offset 0)." )
692+ expect ( output ) . not . toContain ( "offset 3)" )
693+ } )
694+
695+ // kills line 108 outer_or_and, line 110 clauseC_false
696+ it ( "reports offset 0 for the bytes 0xef 0xbf 0xff" , async ( ) => {
697+ const output = await runBytesFor ( Buffer . from ( [ 0xef , 0xbf , 0xff ] ) )
698+
699+ expect ( output ) . toContain ( "is not valid UTF-8" )
700+ expect ( output ) . toContain ( "first undecodable byte at offset 0)." )
701+ expect ( output ) . not . toContain ( "offset 3)" )
702+ } )
703+
704+ // kills line 108 outer_or_and, line 110 clauseC_false
705+ it ( "reports offset 0 for the bytes 0xef 0xbf 0x41" , async ( ) => {
706+ const output = await runBytesFor ( Buffer . from ( [ 0xef , 0xbf , 0x41 ] ) )
707+
708+ expect ( output ) . toContain ( "is not valid UTF-8" )
709+ expect ( output ) . toContain ( "first undecodable byte at offset 0)." )
710+ expect ( output ) . not . toContain ( "offset 4)" )
711+ } )
712+
713+ // kills line 108 outer_or_and, line 110 clauseC_false
714+ it ( "reports offset 0 for the bytes 0xef 0xbf 0x3f" , async ( ) => {
715+ const output = await runBytesFor ( Buffer . from ( [ 0xef , 0xbf , 0x3f ] ) )
716+
717+ expect ( output ) . toContain ( "is not valid UTF-8" )
718+ expect ( output ) . toContain ( "first undecodable byte at offset 0)." )
719+ expect ( output ) . not . toContain ( "offset 4)" )
720+ } )
721+
722+ // kills line 108 outer_or_and, line 108 inner_or_and, line 109 clauseB_false
723+ it ( "reports offset 0 for the bytes 0xef 0xff 0xbd" , async ( ) => {
724+ const output = await runBytesFor ( Buffer . from ( [ 0xef , 0xff , 0xbd ] ) )
725+
726+ expect ( output ) . toContain ( "is not valid UTF-8" )
727+ expect ( output ) . toContain ( "first undecodable byte at offset 0)." )
728+ expect ( output ) . not . toContain ( "offset 3)" )
729+ } )
730+
731+ // kills line 108 outer_or_and, line 108 inner_or_and, line 109 clauseB_false
732+ it ( "reports offset 0 for the bytes 0xef 0x41 0xbd" , async ( ) => {
733+ const output = await runBytesFor ( Buffer . from ( [ 0xef , 0x41 , 0xbd ] ) )
734+
735+ expect ( output ) . toContain ( "is not valid UTF-8" )
736+ expect ( output ) . toContain ( "first undecodable byte at offset 0)." )
737+ expect ( output ) . not . toContain ( "offset 4)" )
738+ } )
739+
740+ // kills line 108 outer_or_and, line 108 inner_or_and, line 109 clauseB_false
741+ it ( "reports offset 0 for the bytes 0xef 0x3f 0xbd" , async ( ) => {
742+ const output = await runBytesFor ( Buffer . from ( [ 0xef , 0x3f , 0xbd ] ) )
743+
744+ expect ( output ) . toContain ( "is not valid UTF-8" )
745+ expect ( output ) . toContain ( "first undecodable byte at offset 0)." )
746+ expect ( output ) . not . toContain ( "offset 4)" )
747+ } )
748+
749+ // kills line 108 outer_or_and, line 110 clauseC_false
750+ it ( "reports offset 1 for the bytes 0x41 0xef 0xbf" , async ( ) => {
751+ const output = await runBytesFor ( Buffer . from ( [ 0x41 , 0xef , 0xbf ] ) )
752+
753+ expect ( output ) . toContain ( "is not valid UTF-8" )
754+ expect ( output ) . toContain ( "first undecodable byte at offset 1)." )
755+ expect ( output ) . not . toContain ( "offset 4)" )
756+ } )
757+
758+ // kills line 108 outer_or_and, line 110 clauseC_false
759+ it ( "reports offset 1 for the bytes 0x3f 0xef 0xbf" , async ( ) => {
760+ const output = await runBytesFor ( Buffer . from ( [ 0x3f , 0xef , 0xbf ] ) )
761+
762+ expect ( output ) . toContain ( "is not valid UTF-8" )
763+ expect ( output ) . toContain ( "first undecodable byte at offset 1)." )
764+ expect ( output ) . not . toContain ( "offset 4)" )
765+ } )
766+
767+ // kills line 108 inner_or_and, line 108 clauseA_false
768+ it ( "reports offset 0 for the bytes 0xbf 0xbf 0xbd" , async ( ) => {
769+ const output = await runBytesFor ( Buffer . from ( [ 0xbf , 0xbf , 0xbd ] ) )
770+
771+ expect ( output ) . toContain ( "is not valid UTF-8" )
772+ expect ( output ) . toContain ( "first undecodable byte at offset 0)." )
773+ expect ( output ) . not . toContain ( "offset 3)" )
774+ } )
775+
776+ // kills line 108 inner_or_and, line 108 clauseA_false
777+ it ( "reports offset 0 for the bytes 0xbd 0xbf 0xbd" , async ( ) => {
778+ const output = await runBytesFor ( Buffer . from ( [ 0xbd , 0xbf , 0xbd ] ) )
779+
780+ expect ( output ) . toContain ( "is not valid UTF-8" )
781+ expect ( output ) . toContain ( "first undecodable byte at offset 0)." )
782+ expect ( output ) . not . toContain ( "offset 3)" )
783+ } )
784+
785+ // kills line 108 inner_or_and, line 108 clauseA_false
786+ it ( "reports offset 0 for the bytes 0xff 0xbf 0xbd" , async ( ) => {
787+ const output = await runBytesFor ( Buffer . from ( [ 0xff , 0xbf , 0xbd ] ) )
788+
789+ expect ( output ) . toContain ( "is not valid UTF-8" )
790+ expect ( output ) . toContain ( "first undecodable byte at offset 0)." )
791+ expect ( output ) . not . toContain ( "offset 3)" )
792+ } )
793+ } )
651794} )
0 commit comments