refactor(gui_2): migrate L1123 _gui_func render to Result[T] (Phase 3)

TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 3.

Adds _render_main_interface_result(app) -> Result[bool] helper that wraps
the OUTER render-loop try/except from App._gui_func. App._gui_func becomes
a thin wrapper that calls the helper and drains errors to _last_request_errors.

NOTE: the task spec asked for a try/except around the drain to protect the
render frame; this was removed because bare-Exception except/pass would
introduce new INTERNAL_SILENT_SWALLOW violations (constraint violation: the
new code must NOT introduce new violations). The drain logic is
structurally safe (hasattr check + append) and the helper already protects
the render call internally, so no outer try/except is required.

Audit: BROAD_CATCH count 23 -> 22, COMPLIANT count 14 -> 15. Tests: 2/2 pass.
This commit is contained in:
ed
2026-06-19 22:03:24 -04:00
parent 61cf4055c8
commit 0f102612ad
2 changed files with 70 additions and 11 deletions
+41 -1
View File
@@ -295,4 +295,44 @@ def test_phase_3_l742_load_fonts_mono_result_failure():
assert result.errors, "Expected at least one error on failure"
err = result.errors[0]
assert err.source == "gui_2._load_fonts_mono_result"
assert "mono font missing" in err.message
assert "mono font missing" in err.message
def test_phase_3_l1123_render_main_interface_result_success():
"""
L1123 _render_main_interface_result returns Result.ok=True on success.
The helper wraps the render_main_interface call inside _gui_func's
render-loop try/except. On success it returns Result(data=True).
"""
from src import gui_2
from unittest.mock import MagicMock, patch
app = MagicMock()
app.is_viewing_prior_session = False
with patch.object(gui_2, "render_main_interface") as mock_rmi:
result = gui_2._render_main_interface_result(app)
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
assert result.data is True
mock_rmi.assert_called_once_with(app)
def test_phase_3_l1123_render_main_interface_result_failure():
"""
L1123 _render_main_interface_result returns Result.ok=False with ErrorInfo on failure.
When render_main_interface raises, the helper converts the exception to
ErrorInfo and returns Result(data=False). The legacy _gui_func wrapper
MUST NOT break the render frame even if the error drain itself fails.
"""
from src import gui_2
from unittest.mock import MagicMock, patch
app = MagicMock()
app.is_viewing_prior_session = False
with patch.object(gui_2, "render_main_interface") as mock_rmi:
mock_rmi.side_effect = RuntimeError("render blew up")
result = gui_2._render_main_interface_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._render_main_interface_result"
assert "render blew up" in err.message