fix(tools): reject fuzzy edits with drifted content - #983
Conversation
Amp-Thread-ID: https://ampcode.com/threads/T-01a0448f-5860-721c-8a47-5119fc57f685 Co-authored-by: Amp <amp@ampcode.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review. WalkthroughThe fuzzy edit cascade removes anchor-based similarity matching. It now uses normalization-based replacers only. Tests verify that interior drift returns an exact-match error and leaves the file unchanged. ChangesFuzzy edit safety
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The change prevents drifted content from being replaced while retaining normalization-only matching, and the supplied validation is passing; no actionable merge-blocking risk remains. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Linked Issues checkExplanation The changes satisfy issue
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Vasanthdev2004
left a comment
There was a problem hiding this comment.
Approving. Deleting 248 lines of matching fallback is the kind of change where the risk is over-deletion rather than the fix itself, so I measured it instead of reading the diff and hoping.
I ran the same eleven inputs through fuzzyEditMatch on main and on this head. Exactly one result changes, and it is the one you set out to change:
| case | main | this PR |
|---|---|---|
| indent drift (spaces to tab) | match | match |
| trailing whitespace | match | match |
| leading blank line | match | match |
| collapsed inner spaces | match | match |
| escape normalization | match | match |
| CRLF content | match | match |
interior drift, y := 2 against y := 99 |
match | no match |
| interior extra line | no match | no match |
| first/last anchor only | no match | no match |
| blank-line drift inside | no match | no match |
Every legitimate normalization still resolves to the same span. The last three are the interesting ones: they did not match on main either, so blockAnchorReplacer and contextAwareReplacer were much narrower in practice than 248 lines suggests. They effectively only fired on the drifted-interior case, which is why removing them costs nothing else.
The honest caveat is that eleven hand-written cases are a sample, not a proof. But they cover each retained normalization plus the shapes the deleted code was supposed to handle, and nothing in that set regressed.
Two other things I checked:
You replaced TestEditFuzzyBlockAnchorToleratesMiddleDrift with TestEditFuzzyRejectsInteriorDrift rather than deleting it. Inverting the assertion is the right way to record a deliberate behaviour change; a bare deletion would have hidden it.
This one is standalone. It shares no files with #892 to #895, so it does not inherit the ordering problem that series has.
go test ./internal/tools passes in full.
Summary
old_stringy := 2/y := 99interior drift and verify the file remains unchangedThe regression test failed before the fix with
Successfully edited target.txt (replaced 1 occurrence).Linked issue
Fixes #963
Checklist
issue-approvedlabel.go build ./...,go vet ./..., andgo test ./...pass locally.gofmtclean.Validation
go vet ./...go test ./...go test ./internal/tools -count=1go run ./cmd/zero-release buildgo run ./cmd/zero-release smokemake lint-static— 0 issuesmake vulncheck— no vulnerabilitiesgit diff HEAD --checkmake fmt-checkremains blocked on the current base by existing formatting findings underinternal/perfbench/testdata/; this PR does not modify those fixtures.Summary by CodeRabbit