Repository navigation
fuzzy_match: hoist the strategy table to module constants - #291
Conversation
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
૮ >ﻌ< ა ci reviewran on 839627c — fuzzy_match: hoist the strategy table to module constants
|
Behaviour-preserving refactor. The matching chain and the set of similarity-based strategies were local variables rebuilt on every call to fuzzy_find_and_replace; they are now module constants (MATCH_STRATEGIES, SIMILARITY_STRATEGIES) defined after the strategy functions. Order and contents are unchanged. This lets the strategy table be read, tested and changed without editing the dispatcher body. Equivalence: the pre- and post-change modules were loaded side by side and compared on 10,200 synthetic cases (17 drift families x 300, replace_all False and True) plus 3,914 random edits of real source: 0 differences in the returned (content, count, strategy, error). Existing patch tests: 116 passed. ruff clean.
76b566e to
839627c
Compare
What this does
Moves the
patchtool's fuzzy-matching strategy table intools/fuzzy_match.pyfrom local variables insidefuzzy_find_and_replaceto module-level constants:MATCH_STRATEGIES: the ordered chain of nine(name, function)pairs, fromexacttocontext_aware.SIMILARITY_STRATEGIES: the frozenset{"block_anchor", "context_aware"}thatreplace_allrefuses to use for multiple matches.Order and contents are unchanged, and the dispatcher (
fuzzy_find_and_replace) reads the constants at call time, so the refactor is behaviour-preserving by construction. It makes the matching chain readable and testable on its own, and is a step toward evaluating matcher changes without editing the dispatcher body.One file changed (
tools/fuzzy_match.py, +29/−22), no test files touched, single commit839627con top ofmain6d072e1. To check order and contents directly, diff the strategy list and the similarity set ingit show 6d072e1:tools/fuzzy_match.pyagainst839627c:tools/fuzzy_match.py.Evidence
git show HEAD:tools/fuzzy_match.pywhile HEAD was2312f67; the after-module was the working tree that was then committed unchanged as76b566e. The branch was later rebased ontomain6d072e1(which changes no file this PR touches); thetools/fuzzy_match.pydiff is byte-identical before and after the rebase, and the 116 patch tests pass again at839627c. Both were loaded side by side and called with the same inputs, and the full return tuple(content, match_count, strategy, error)was compared. 0 differences across 14,114 cases:replace_all=Falseandreplace_all=True;old_stringwas whitespace-only. Edits: indentation shifts, inserted blank lines, changed lines, tabs, truncated lines, and unmutated controls; 20% of files with CRLF line endings.This is a probe on one host, not a proof over all inputs; the construction argument above is the main warrant.
tests/tools/test_fuzzy_match.py,test_patch_multimatch_locations.py,test_patch_ws_diagnosis.py,test_patch_already_applied.py,test_patch_parser.py): 116 passed.ruff check tools/fuzzy_match.py(ruff 0.15.10): All checks passed.Scope and limits
block_anchormatches a region whose first and last lines equal those ofold_stringafter whitespace stripping and whose middle is similar enough; when the model'sold_stringhas the same line count but a stale interior line, it is applied without an error and the real interior line is overwritten (reproduced onmain). Strategy selection is unchanged here, so the issue is as reproducible after this PR as before.