Private
Public Access
TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 5: refactor(gui_2): migrate L1367 _apply_pending_patch to Result[T] (Phase 5)
Extract _apply_pending_patch_result helper from the apply_patch_to_file try/except in App._apply_pending_patch. Legacy wrapper drains errors to app._last_request_errors per FR-BC-4 event-handler pattern. [pre-audit] L1367 INTERNAL_BROAD_CATCH [post-audit] V count: 12 -> 11 (L1367 removed)
This commit is contained in:
@@ -878,3 +878,48 @@ def test_phase_5_l1293_populate_auto_slices_file_read_result_failure():
|
||||
err = result.errors[0]
|
||||
assert err.source == "gui_2._populate_auto_slices_file_read_result"
|
||||
assert "no such file" in err.message
|
||||
|
||||
|
||||
def test_phase_5_l1367_apply_pending_patch_result_success():
|
||||
"""
|
||||
L1367 _apply_pending_patch_result returns Result.ok=True on success.
|
||||
|
||||
The helper wraps the apply_patch_to_file try/except in App._apply_pending_patch.
|
||||
On success (apply_patch_to_file returns (True, msg)), returns Result(data=True)
|
||||
and sets app._show_patch_modal=False, app._pending_patch_text=None,
|
||||
app._pending_patch_files=[], app._patch_error_message=None.
|
||||
"""
|
||||
from src import gui_2
|
||||
from unittest.mock import MagicMock, patch
|
||||
app = MagicMock()
|
||||
app._pending_patch_text = "--- a/foo.py\n+++ b/foo.py\n@@ -1 +1 @@\n-old\n+new\n"
|
||||
app.controller.current_project_dir = "/proj/foo"
|
||||
with patch.object(gui_2, "apply_patch_to_file", return_value=(True, "patched")), \
|
||||
patch.object(gui_2.imgui, "close_current_popup"):
|
||||
result = gui_2._apply_pending_patch_result(app)
|
||||
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
|
||||
assert result.data is True
|
||||
assert app._show_patch_modal is False
|
||||
assert app._patch_error_message is None
|
||||
|
||||
|
||||
def test_phase_5_l1367_apply_pending_patch_result_failure():
|
||||
"""
|
||||
L1367 _apply_pending_patch_result returns Result.ok=False with ErrorInfo on failure.
|
||||
|
||||
When apply_patch_to_file returns (False, msg) or raises, the helper sets
|
||||
app._patch_error_message to the error message and returns
|
||||
Result(data=False, errors=[ErrorInfo]).
|
||||
"""
|
||||
from src import gui_2
|
||||
from unittest.mock import MagicMock, patch
|
||||
app = MagicMock()
|
||||
app._pending_patch_text = "--- a/foo.py\n+++ b/foo.py\n"
|
||||
app.controller.current_project_dir = "/proj/foo"
|
||||
with patch.object(gui_2, "apply_patch_to_file", side_effect=RuntimeError("patch blew up")):
|
||||
result = gui_2._apply_pending_patch_result(app)
|
||||
assert not result.ok, f"Expected ok=False on failure, got data: {result.data}"
|
||||
assert result.errors, "Expected at least one error on failure"
|
||||
err = result.errors[0]
|
||||
assert err.source == "gui_2._apply_pending_patch_result"
|
||||
assert "patch blew up" in err.message
|
||||
|
||||
Reference in New Issue
Block a user