refactor(gui_2): migrate L4848 render_warmup_status_indicator to Result[T] (Phase 3)
TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 3. Adds _render_warmup_status_indicator_result(app) -> Result[dict] helper that wraps the controller.warmup_status() try/except in render_warmup_status_indicator. The data field carries the status dict so the legacy wrapper can use it for rendering without an additional instance attribute. render_warmup_status_indicator becomes a thin wrapper that drains errors to app.controller._worker_errors under the controller's lock (worker error plane; thread-safe per app_controller pattern). Audit: BROAD_CATCH count 18 -> 17, COMPLIANT count 19 -> 20. Migration target count drops from 42 to 34 (8 sites migrated). Tests: 2/2 pass.
This commit is contained in:
@@ -508,4 +508,41 @@ def test_phase_3_l1284_handle_history_logic_result_failure():
|
||||
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
|
||||
assert "snapshot failed" in err.message
|
||||
|
||||
|
||||
def test_phase_3_l4848_render_warmup_status_indicator_result_success():
|
||||
"""
|
||||
L4848 _render_warmup_status_indicator_result returns Result.ok=True with status dict.
|
||||
|
||||
The helper wraps the controller.warmup_status() try/except in
|
||||
render_warmup_status_indicator. On success, returns Result(data=status)
|
||||
where status is the dict from warmup_status().
|
||||
"""
|
||||
from src import gui_2
|
||||
from unittest.mock import MagicMock
|
||||
app = MagicMock()
|
||||
mock_status = {"pending": [], "completed": ["a"], "failed": []}
|
||||
app.controller.warmup_status.return_value = mock_status
|
||||
result = gui_2._render_warmup_status_indicator_result(app)
|
||||
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
|
||||
assert result.data is mock_status
|
||||
|
||||
|
||||
def test_phase_3_l4848_render_warmup_status_indicator_result_failure():
|
||||
"""
|
||||
L4848 _render_warmup_status_indicator_result returns Result.ok=False on failure.
|
||||
|
||||
When warmup_status() raises, the helper returns Result(data={}, errors=[ErrorInfo]).
|
||||
The legacy wrapper should drain to app.controller._worker_errors (worker error plane).
|
||||
"""
|
||||
from src import gui_2
|
||||
from unittest.mock import MagicMock
|
||||
app = MagicMock()
|
||||
app.controller.warmup_status.side_effect = RuntimeError("warmup backend down")
|
||||
result = gui_2._render_warmup_status_indicator_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_warmup_status_indicator_result"
|
||||
assert "warmup backend down" in err.message
|
||||
Reference in New Issue
Block a user