Repository navigation
fix(tools): match and keep CRLF line endings in diff_edit - #2007
Mahdi-Hasan wants to merge 4 commits into
Conversation
nc-review: needs work — 1 blocking, 2 nits@Mahdi-Hasan — there is a blocking item below. The PR makes
🔴 blocking · This appears to duplicate the still-open PR #1994, "fix(diff-edit): match SEARCH blocks on CRLF files" (branch I could not read #1994's diff from the review context, so I cannot prove the two implementations are identical — but the titles, branches and target issue are the same problem, and merging both would land the same fix twice and close #1993 twice. A maintainer should compare the two diffs and keep one; this PR is the more complete of the two as far as the diff shows (it fits the blocks in the executor, the validator and the VS Code preview path, and adds four tests including a validator test), so keeping this one and closing #1994 would be the reasonable outcome. Note also that the changeset body ends with "Closes #1993." — whichever PR lands should own that. ⚪ nit · The changeset states "an LF block that only matches an LF part of a mixed file is applied as sent". That holds only for multi-line SEARCH blocks. const fittedOld = toLineEnding(oldStr, ending);
if (
fittedOld !== oldStr &&
!fileContent.includes(fittedOld) &&
fileContent.includes(oldStr)
) {
return {oldStr, newStr};
}
return {oldStr: fittedOld, newStr: toLineEnding(newStr, ending)};For a single-line SEARCH (no This is inherited from the shared helper and matches ⚪ nit · The failing-search path changed shape without coverage: A single test that triggers a failed search on a CRLF file and asserts the error still carries usable recovery evidence (a 🔴 blocking · 🟠 a reviewer would ask for a change · ⚪ optional Automated code review — correctness, security, design, tests, plus duplicates and scope. A human still decides; this is not a substitute for review and is not exhaustive. The required status checks separately cover lint, formatting, types, unused dependencies, the test suite and the build. This bot never merges. Maintainers can rerun with |
|
Thanks for the review. All three addressed:
|
951dea1 to
c1e1836
Compare
|
Thanks @Mahdi-Hasan, this fixes #1993 properly. Reusing What looks good
What to fix before merge
I'll close #1994 in favour of this one. Happy to look again once it is rebased. |
|
Hi @Mahdi-Hasan, thanks for this PR! It looks like a maintainer has left feedback Whenever you get a chance, could you take a look at the open comments? |
Models send SEARCH/REPLACE blocks with LF line breaks, so a multi-line block never matched a CRLF file. Fit each block with fitEditToLineEndings before validating and applying it, in the tool, the validator and the VS Code diff. Closes Nano-Collective#1993 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Pin the failed-search path now that the fitted search text reaches EditRecoveryError: the candidate's actualText must apply cleanly and keep CRLF. Also limit the changeset's mixed-file claim to multi-line blocks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Upstream's context-visibility firewall needs the lines marked visible, so the CRLF validator tests use markFileSeenAndVisible. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Block 2 is matched in block 1's output, so block 1's fitted lines must be CRLF. A second test checks that a fitted replacement which repeats block 2's search is rejected by the ordered dry run from Nano-Collective#2248.
c1e1836 to
e254ebb
Compare
|
Thanks, rebased onto main. All three call sites now fit the blocks first, then use #2248's |
Description
diff_editmatched each SEARCH block against the raw file text. Models send LF, so a multi-line SEARCH block on a CRLF file was refused withSearch block 1 was not found in file, and REPLACE text that added lines wrote LF lines into the file. Fixes #1993.It reuses
fitEditToLineEndingsfromsource/utils/line-endings.ts(#1961), as proposed on the issue.fitBlocksToLineEndings(fileContent, blocks)indiff-edit.tsxfits every SEARCH/REPLACE block to the file's line endings.string_replace.diff_editdiff builder, so nothing changes there.string_replace(fix(tools): match and keep CRLF line endings in string_replace #1961),write_file(fix(tools): keep CRLF line endings when write_file overwrites a CRLF file #1992) anddiff_edit.Type of Change
Changeset
pnpm changeset) describing this change for the changelogTesting
Automated Tests
New features include passing tests in
.spec.ts/tsxfilesAll existing tests pass (
pnpm test:allcompletes successfully)Tests cover both success and error scenarios
5 new tests in
diff-edit.spec.tsx: the repro from the issue, multiple blocks that add lines in a CRLF file, the validator, an LF block in the LF region of a mixed file, and recovery evidence for a missed block on a CRLF file.Four fail on
main. The recovery test retries with the suggestedactualTextand checks the file stays CRLF. The mixed-file test passes on both and guards against over-converting.diff-edit.spec.tsx: 36 pass. Types, biome and knip pass.Developed on Windows; I ran the focused spec, not
pnpm test:all.Manual Testing
Checklist
🤖 Generated with Claude Code