-
Notifications
You must be signed in to change notification settings - Fork 52.3k
fix(tools): patch idempotency guard prevents duplicate-content loops on re-edit (#18426) #56570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Tranquil-Flow
wants to merge
2
commits into
NousResearch:main
Choose a base branch
from
Tranquil-Flow:fix/18426-patch-duplicate-loop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+213
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| """Sweeper feedback regression: guard must be scoped to candidate position.""" | ||
| from __future__ import annotations | ||
|
|
||
| from tools.fuzzy_match import fuzzy_find_and_replace | ||
|
|
||
|
|
||
| class TestIdempotencyGuardScoping: | ||
| """Unrelated new_string occurrences must not block fuzzy matching.""" | ||
|
|
||
| def test_unrelated_new_string_occurrence_does_not_block(self): | ||
| """If new_string appears ELSEWHERE in the file but old_string's | ||
| context doesn't overlap with that occurrence, fuzzy match should proceed.""" | ||
| content = ( | ||
| "import os\n" | ||
| "def foo():\n" | ||
| " x = 1\n" | ||
| " return x\n" | ||
| "def bar():\n" | ||
| " return 'new_value'\n" | ||
| ) | ||
| old = " x = 1\n return x" | ||
| new = " x = 2\n return 'new_value'" | ||
| # new_string's "return 'new_value'" appears in bar() but that's | ||
| # an unrelated occurrence. The patch should still apply to foo(). | ||
| result, count, strat, err = fuzzy_find_and_replace(content, old, new) | ||
| assert err is None, f"unrelated occurrence should not block: {err}" | ||
| assert count == 1 | ||
| assert "x = 2" in result | ||
|
|
||
| def test_patch_replace_retry_error_and_unchanged_content(self): | ||
| """Re-applying the same patch must error and leave content unchanged.""" | ||
| content = "value = 1\n" | ||
| old = "value = 1" | ||
| new = "value = 2" | ||
| once, _, _, _ = fuzzy_find_and_replace(content, old, new) | ||
| twice, count2, _, err2 = fuzzy_find_and_replace(once, old, new) | ||
| assert err2 is not None, "re-applying must error" | ||
| assert count2 == 0 | ||
| assert twice == once, "content must be unchanged" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole-file predicate rejects a valid first fuzzy edit when
new_stringalready occurs elsewhere. For example, production may already containstatus = enabledwhile a whitespace-drifted stagingstatus = disabledshould be changed to the same value; current main matches staging throughwhitespace_normalized, but this condition returns early. Please scope the check to the selected candidate rather than global content presence.