TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 10: refactor(gui_2): migrate L728 run() immapp call to Result[T] (Phase 10 site 4)

Extracted _run_immapp_result(app) -> Result[None] helper above the
App.run method.
ANTI-SLIMING: full Result[T] propagation (NO pass-after-print). The
helper returns Result(data=None) on success or Result(data=None,
errors=[ErrorInfo]) on exception (logging NOT a drain per the user's
principle 2026-06-17). The legacy run() wrapper sets
controller._gui_degraded_reason and _last_imgui_assert (the canonical
degradation drain), appends to _startup_timeline_errors, and returns
WITHOUT the original stderr.print logging.

Tests: 2 new tests verify both paths (success and RuntimeError).

Audit: L728 reclassified from INTERNAL_SILENT_SWALLOW (10 sites remaining,
was 11). New helper L728 is INTERNAL_COMPLIANT.
This commit is contained in:
ed
2026-06-20 00:46:43 -04:00
parent e761244c4a
commit ad702f7e88
2 changed files with 83 additions and 27 deletions
+46
View File
@@ -1857,4 +1857,50 @@ def test_phase_10_l612_post_init_callback_result_failure():
assert "controller not ready" in err.message
def test_phase_10_l728_run_immapp_result_success():
"""
L728 _run_immapp_result returns Result(data=None) on success.
The helper extracts the immapp.run() call from App.run into a Result-returning
helper. On success, returns Result(data=None). The legacy run method
proceeds to self.shutdown() and session_logger.close_session().
"""
from unittest.mock import MagicMock, patch
import src.gui_2 as gui2_mod
app = MagicMock()
app.runner_params = MagicMock()
with patch("src.gui_2.immapp") as mock_immapp:
mock_immapp.AddOnsParams.return_value = MagicMock()
result = gui2_mod._run_immapp_result(app)
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
assert result.data is None
mock_immapp.run.assert_called_once()
def test_phase_10_l728_run_immapp_result_failure():
"""
L728 _run_immapp_result returns Result(data=None, errors=[ErrorInfo]) on failure.
When immapp.run() raises RuntimeError (IM_ASSERT, native bundle crash, etc.),
the helper converts to ErrorInfo. The legacy run method sets the
controller._gui_degraded_reason and _last_imgui_assert drain attributes,
appends to _startup_timeline_errors, and returns.
"""
from unittest.mock import MagicMock, patch
import src.gui_2 as gui2_mod
app = MagicMock()
app.runner_params = MagicMock()
app.controller = MagicMock()
with patch("src.gui_2.immapp") as mock_immapp:
mock_immapp.AddOnsParams.return_value = MagicMock()
mock_immapp.run.side_effect = RuntimeError("IM_ASSERT: invalid scope")
result = gui2_mod._run_immapp_result(app)
assert not result.ok, f"Expected ok=False on failure, got data: {result.data}"
assert result.data is None
assert result.errors, "Expected at least one error on failure"
err = result.errors[0]
assert err.source == "gui_2._run_immapp_result"
assert "IM_ASSERT" in err.message