refactor(edit): unify fuzzy uniqueness check with the fuzzy matcher

The uniqueness guard counted occurrences via normalize_for_fuzzy_match,
while fuzzy_find_text located matches with a whitespace-flexible regex,
so the two could disagree. Extract the pattern builder as a single
source of truth (_build_fuzzy_pattern) and add count_matches, which
counts with the same exact-then-fuzzy strategy used to locate and
replace. This is the optional follow-up suggested in the review of #2942.

Adds regression tests for exact and fuzzy multi-match rejection.
This commit is contained in:
weijun-xia
2026-07-08 11:13:30 +08:00
parent ce09efe640
commit ed36ca99c0
4 changed files with 101 additions and 27 deletions

View File

@@ -15,6 +15,7 @@ from .diff import (
normalize_to_lf,
restore_line_endings,
normalize_for_fuzzy_match,
count_matches,
fuzzy_find_text,
generate_diff_string,
FuzzyMatchResult
@@ -39,6 +40,7 @@ __all__ = [
'normalize_to_lf',
'restore_line_endings',
'normalize_for_fuzzy_match',
'count_matches',
'fuzzy_find_text',
'generate_diff_string',
'FuzzyMatchResult',