Private
Public Access
TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 10: refactor(gui_2): migrate L612 _post_init callback to Result[T] (Phase 10 site 3)
Extracted _post_init_callback_result(app) -> Result[None] helper above the App._post_init method. ANTI-SLIMING: full Result[T] propagation (NO pass-after-logging). 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 _post_init method preserves its signature and calls the helper, draining errors to self._startup_timeline_errors. Tests: 2 new tests verify both paths (success and RuntimeError). Audit: L612 reclassified from INTERNAL_SILENT_SWALLOW (10 sites remaining, was 11). New helper L612 is INTERNAL_COMPLIANT.
This commit is contained in:
@@ -1815,4 +1815,46 @@ def test_phase_10_l264_resolve_font_path_result_is_relative_to_raises():
|
||||
assert err.source == "gui_2._resolve_font_path_result"
|
||||
|
||||
|
||||
def test_phase_10_l612_post_init_callback_result_success():
|
||||
"""
|
||||
L612 _post_init_callback_result returns Result(data=None) on success.
|
||||
|
||||
The helper extracts the warmup-complete callback registration from
|
||||
App._post_init into a Result-returning helper. On success, it registers
|
||||
the lambda callback via self.controller.on_warmup_complete() and returns
|
||||
Result(data=None).
|
||||
"""
|
||||
from unittest.mock import MagicMock
|
||||
import src.gui_2 as gui2_mod
|
||||
app = MagicMock()
|
||||
app.controller = MagicMock()
|
||||
result = gui2_mod._post_init_callback_result(app)
|
||||
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
|
||||
assert result.data is None
|
||||
app.controller.on_warmup_complete.assert_called_once()
|
||||
|
||||
|
||||
def test_phase_10_l612_post_init_callback_result_failure():
|
||||
"""
|
||||
L612 _post_init_callback_result returns Result(data=None, errors=[ErrorInfo]) on failure.
|
||||
|
||||
When self.controller.on_warmup_complete() raises (e.g., controller not
|
||||
ready or invalid callback), the helper converts to ErrorInfo and returns
|
||||
Result(data=None, errors=[ErrorInfo]). The legacy _post_init wrapper
|
||||
drains to self._startup_timeline_errors.
|
||||
"""
|
||||
from unittest.mock import MagicMock
|
||||
import src.gui_2 as gui2_mod
|
||||
app = MagicMock()
|
||||
app.controller = MagicMock()
|
||||
app.controller.on_warmup_complete.side_effect = RuntimeError("controller not ready")
|
||||
result = gui2_mod._post_init_callback_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._post_init_callback_result"
|
||||
assert "controller not ready" in err.message
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user