Python
fix(auto-approve): deletes and moves always reach the reviewer (OPE-233)
Devika Verma9f9a9de4b560
diff --git a/coworker/workspace_safety.py b/coworker/workspace_safety.pyindex c7b2cc0a..0fed5c73 100644--- a/coworker/workspace_safety.py+++ b/coworker/workspace_safety.py@@ -143,6 +143,17 @@ def git_file_state(path: Path) -> str:return UNTRACKED+# A patch that deletes a file, or moves one (which removes the original name). Deletes always+# reach the reviewer, even when git could restore the file (Devika, 26 Oct 2026): a clearly+# requested delete is allowed there, one nobody asked for becomes a card.+_REMOVES_FILE = re.compile(r"^\*\*\* (?:Delete File|Move to): ", re.MULTILINE)+++def removes_files(arguments: dict[str, Any]) -> bool:+ """True when a write removes or renames a file (a patch's Delete File or Move to)."""+ return bool(_REMOVES_FILE.search(str((arguments or {}).get("patch", ""))))++def inert_write_check(arguments: dict[str, Any],targets: list[Path],@@ -155,6 +166,8 @@ def inert_write_check(return False, ""if has_secret_value(arguments):return False, ""+ if removes_files(arguments):+ return False, ""parts: list[str] = []for target in targets:name = target.namediff --git a/tests/test_inert_writes.py b/tests/test_inert_writes.pyindex eb7f3e65..abb37e36 100644--- a/tests/test_inert_writes.py+++ b/tests/test_inert_writes.py@@ -205,9 +205,38 @@ def test_an_ignored_existing_file_goes_to_the_reviewer(tmp_path):@git-def test_deleting_a_tracked_unmodified_file_is_eligible(tmp_path):+def test_deleting_even_a_tracked_unmodified_file_goes_to_the_reviewer(tmp_path):+ # Devika, 26 Oct 2026: git could restore it, but the reviewer should see every delete.+ # A clearly requested delete is still allowed there (Rule 1b); one taken from a to-do+ # file with no approved plan becomes a card._repo(tmp_path, {"old-notes.txt": "old"})patch = "*** Begin Patch\n*** Delete File: old-notes.txt\n*** End Patch"+ assert _goes_to_reviewer(_gate(tmp_path).evaluate("apply_patch", {"patch": patch}))+++@git+def test_moving_a_file_goes_to_the_reviewer(tmp_path):+ # A move removes the original name, so it is treated like a delete.+ _repo(tmp_path, {"notes.md": "old"})+ patch = (+ "*** Begin Patch\n*** Update File: notes.md\n*** Move to: archive.md\n"+ "@@\n-old\n+old\n*** End Patch"+ )+ assert _goes_to_reviewer(_gate(tmp_path).evaluate("apply_patch", {"patch": patch}))+++@git+def test_a_patch_that_deletes_one_file_and_adds_another_goes_to_the_reviewer(tmp_path):+ _repo(tmp_path, {"old-notes.txt": "old"})+ patch = (+ "*** Begin Patch\n*** Add File: summary.txt\n+done\n"+ "*** Delete File: old-notes.txt\n*** End Patch"+ )+ assert _goes_to_reviewer(_gate(tmp_path).evaluate("apply_patch", {"patch": patch}))+++def test_adding_an_inert_file_by_patch_is_still_eligible(tmp_path):+ patch = "*** Begin Patch\n*** Add File: notes.md\n+hi\n*** End Patch"assert _ran_without_reviewer(_gate(tmp_path).evaluate("apply_patch", {"patch": patch}))