Private
Public Access
refactor(gui_2): migrate L1284 _handle_history_logic to Result[T] (Phase 3)
TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 3. Adds _handle_history_logic_result(app) -> Result[bool] helper that wraps the snapshot debounce try/except from App._handle_history_logic. The _is_applying_snapshot pre-condition guard stays in the legacy wrapper (not error handling; the original early return has no try/except). App._handle_history_logic becomes a thin wrapper that drains errors to _last_request_errors. The drain failure mode is structurally safe (hasattr check + append) so no outer try/except is required (per the L1123 wrapper decision; avoiding new INTERNAL_SILENT_SWALLOW violations). Audit: BROAD_CATCH count 19 -> 18, COMPLIANT count 18 -> 19. Tests: 2/2 pass.
This commit is contained in:
@@ -463,4 +463,49 @@ def test_phase_3_l1222_show_menus_is_max_result_failure():
|
||||
assert result.errors, "Expected at least one error on failure"
|
||||
err = result.errors[0]
|
||||
assert err.source == "gui_2._show_menus_is_max_result"
|
||||
assert result.data is False
|
||||
assert result.data is False
|
||||
|
||||
|
||||
def test_phase_3_l1284_handle_history_logic_result_success():
|
||||
"""
|
||||
L1284 _handle_history_logic_result returns Result.ok=True on success.
|
||||
|
||||
The helper wraps the snapshot try/except in App._handle_history_logic.
|
||||
The simplest success path is when _last_ui_snapshot is None (first
|
||||
snapshot, early return) or when nothing changed (no push needed).
|
||||
"""
|
||||
from src import gui_2
|
||||
from unittest.mock import MagicMock
|
||||
app = MagicMock()
|
||||
app._is_applying_snapshot = False
|
||||
app._last_ui_snapshot = None
|
||||
mock_snapshot = MagicMock(name="mock_snapshot")
|
||||
mock_snapshot.disc_entries = []
|
||||
mock_snapshot.files = []
|
||||
mock_snapshot.context_files = []
|
||||
mock_snapshot.screenshots = []
|
||||
app._take_snapshot.return_value = mock_snapshot
|
||||
result = gui_2._handle_history_logic_result(app)
|
||||
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
|
||||
assert result.data is True
|
||||
|
||||
|
||||
def test_phase_3_l1284_handle_history_logic_result_failure():
|
||||
"""
|
||||
L1284 _handle_history_logic_result returns Result.ok=False with ErrorInfo on failure.
|
||||
|
||||
When _take_snapshot raises (or any other code in the try body), the
|
||||
helper returns Result(data=False, errors=[ErrorInfo]).
|
||||
"""
|
||||
from src import gui_2
|
||||
from unittest.mock import MagicMock
|
||||
app = MagicMock()
|
||||
app._is_applying_snapshot = False
|
||||
app._last_ui_snapshot = MagicMock()
|
||||
app._take_snapshot.side_effect = ValueError("snapshot failed")
|
||||
result = gui_2._handle_history_logic_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._handle_history_logic_result"
|
||||
assert "snapshot failed" in err.message
|
||||
Reference in New Issue
Block a user