Skip to content

Commit c137906

Browse files
tools: pin the undecodable-byte offsets against the message's own delimiter
CodeRabbit's row on eb15d53 (thread on applyDiffTool.failureReporting.spec.ts:245) is right on both counts, and the second is a defect in my assertions rather than in the tool: * `expect(output).toContain("first undecodable byte at offset 1")` is also satisfied by a message reading "offset 10", because the shorter string is a prefix of the longer one. The reported offset is followed in the message by `).`, so every offset assertion in `bytes the decoder cannot read` now asserts "first undecodable byte at offset N)." - eight assertions, including the two rows that were already there. * The adjacency cases it asked for are added in both orders: a truncated sequence followed by a literal U+FFFD (`e2 82 ef bf bd`) reports offset 0, the start byte of the truncated sequence, and a literal U+FFFD followed by a truncated sequence (`61 ef bf bd e2 82`) reports offset 4 where counting through the decoded string would report 3 - the same three-byte-to-one-character shortfall the previous commit fixed, now pinned with a literal replacement character instead of a byte-order mark. Offsets are quoted against the byte positions a hex dump shows. Verification, pinned node v22.23.4 with stdio on file descriptors: - applyDiffTool.failureReporting.spec.ts: 46 passed (1 file), 44 before this commit plus the two adjacency rows. - tsc --noEmit -p tsconfig.json in src: 0 errors; eslint --prune-suppressions --max-warnings=0: 0 on both files, with its rewrite of src/eslint-suppressions.json reverted so no suppression churn rides along; prettier --check clean, formatted before measuring. - The merge candidate (this head onto upstream/main e487cd7, which is what pull_request CI checks out) is built and run locally before the push - both applyDiffTool specs there, including main's own outsideWorkspace.spec.ts - because a head-only green run describes a tree CI does not test. Gate: 355 of 500 counted executable lines at base 73931fe with base...head and --unified=0 on the formatted tree with node v22.23.4 - unchanged from eb15d53, because every line here is in __tests__, which the gate excludes. Mutation state is unchanged by this commit and is still the one published on the PR: 347 lines / 318 valid / 255 killed / 4 timeout / 57 survived / 2 no coverage from the artifact at d5c31a1, and no run has measured this head yet.
1 parent eb15d53 commit c137906

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

‎src/core/tools/__tests__/applyDiffTool.failureReporting.spec.ts‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ describe("ApplyDiffTool failure reporting", () => {
180180
const { output } = await runOnBytes(UNDECODABLE)
181181

182182
expect(output).toContain("is not valid UTF-8")
183-
expect(output).toContain("first undecodable byte at offset 3")
183+
expect(output).toContain("first undecodable byte at offset 3).")
184184
expect(mockTask.say).toHaveBeenCalledWith("error", output)
185185
expect(mockTask.recordToolError).toHaveBeenCalledWith("apply_diff")
186186
expect(mockTask.consecutiveMistakeCount).toBe(1)
@@ -222,7 +222,7 @@ describe("ApplyDiffTool failure reporting", () => {
222222
it("reports the first undecodable byte when invalid bytes repeat", async () => {
223223
const { output } = await runOnBytes(Buffer.from([0x41, 0xc3, 0x28, 0x42, 0xfe, 0x43, 0xff]))
224224

225-
expect(output).toContain("first undecodable byte at offset 1")
225+
expect(output).toContain("first undecodable byte at offset 1).")
226226
expect(output).not.toContain("offset 4")
227227
})
228228

@@ -233,21 +233,21 @@ describe("ApplyDiffTool failure reporting", () => {
233233
it("counts a byte-order mark as the three bytes it is", async () => {
234234
const { output } = await runOnBytes(Buffer.from([0xef, 0xbb, 0xbf, 0x41, 0xff]))
235235

236-
expect(output).toContain("first undecodable byte at offset 4")
236+
expect(output).toContain("first undecodable byte at offset 4).")
237237
expect(output).not.toContain("offset 1")
238238
})
239239

240240
it("does not mistake a literal replacement character for an undecodable byte", async () => {
241241
const { output } = await runOnBytes(Buffer.from([0xef, 0xbf, 0xbd, 0x41, 0xff]))
242242

243-
expect(output).toContain("first undecodable byte at offset 4")
243+
expect(output).toContain("first undecodable byte at offset 4).")
244244
expect(output).not.toContain("offset 0")
245245
})
246246

247247
it("counts past a byte-order mark and a literal replacement character together", async () => {
248248
const { output } = await runOnBytes(Buffer.from([0xef, 0xbb, 0xbf, 0xef, 0xbf, 0xbd, 0xff]))
249249

250-
expect(output).toContain("first undecodable byte at offset 6")
250+
expect(output).toContain("first undecodable byte at offset 6).")
251251
})
252252

253253
// The BOM survives into the text the diff is applied to and the approval baseline is built from,
@@ -262,6 +262,22 @@ describe("ApplyDiffTool failure reporting", () => {
262262
expect(String(appliedTo).startsWith("\uFEFF")).toBe(true)
263263
expect(Buffer.from(String(appliedTo), "utf8").equals(bomFile)).toBe(true)
264264
})
265+
// The row above shows a BOM or a file-written U+FFFD shifting a later failure; these two put a
266+
// truncated sequence next to a literal U+FFFD in both orders, and every offset below is asserted
267+
// against the position a hex dump shows. The closing `).` is included because a substring check on
268+
// "offset 1" is also satisfied by "offset 10", which would let a wrong offset pass.
269+
it("reports the truncated sequence itself when a literal replacement character follows it", async () => {
270+
const { output } = await runOnBytes(Buffer.from([0xe2, 0x82, 0xef, 0xbf, 0xbd]))
271+
272+
expect(output).toContain("first undecodable byte at offset 0).")
273+
})
274+
275+
it("counts past a literal replacement character into a truncated sequence", async () => {
276+
const { output } = await runOnBytes(Buffer.from([0x61, 0xef, 0xbf, 0xbd, 0xe2, 0x82]))
277+
278+
expect(output).toContain("first undecodable byte at offset 4).")
279+
expect(output).not.toContain("first undecodable byte at offset 3).")
280+
})
265281
})
266282

267283
describe("failure accumulation and rendering", () => {

0 commit comments

Comments
 (0)