Private
Public Access
TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 10: refactor(gui_2): migrate L1647 render_main_interface focus_response to Result[T] (Phase 10 site 8)
Extracted _focus_response_window_result() -> Result[None] helper above the call site in render_main_interface. ANTI-SLIMING: full Result[T] propagation (NO bare-except+pass). 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 render_main_interface code preserves its behavior, calls the helper, drains errors to app._last_request_errors. Tests: 2 new tests verify both paths (success and RuntimeError). Audit: L1647 reclassified from INTERNAL_SILENT_SWALLOW (6 sites remaining, was 7). New helper L1647 is INTERNAL_COMPLIANT.
This commit is contained in:
@@ -2032,4 +2032,40 @@ def test_phase_10_l1466_close_vscode_diff_terminate_result_failure():
|
||||
assert "process already exited" in err.message
|
||||
|
||||
|
||||
def test_phase_10_l1647_focus_response_window_result_success():
|
||||
"""
|
||||
L1647 _focus_response_window_result returns Result(data=None) on success.
|
||||
|
||||
The helper extracts the imgui.set_window_focus("Response") try/except from
|
||||
render_main_interface into a Result-returning helper. On success, returns
|
||||
Result(data=None).
|
||||
"""
|
||||
from unittest.mock import MagicMock, patch
|
||||
import src.gui_2 as gui2_mod
|
||||
with patch("src.gui_2.imgui.set_window_focus", return_value=None):
|
||||
result = gui2_mod._focus_response_window_result()
|
||||
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
|
||||
assert result.data is None
|
||||
|
||||
|
||||
def test_phase_10_l1647_focus_response_window_result_failure():
|
||||
"""
|
||||
L1647 _focus_response_window_result returns Result(data=None, errors=[ErrorInfo]) on failure.
|
||||
|
||||
When imgui.set_window_focus("Response") raises (e.g., native bundle
|
||||
error, IM_ASSERT), the helper converts to ErrorInfo. The caller
|
||||
(render_main_interface) drains to self._last_request_errors.
|
||||
"""
|
||||
from unittest.mock import patch
|
||||
import src.gui_2 as gui2_mod
|
||||
with patch("src.gui_2.imgui.set_window_focus", side_effect=RuntimeError("IM_ASSERT: window scope")):
|
||||
result = gui2_mod._focus_response_window_result()
|
||||
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._focus_response_window_result"
|
||||
assert "IM_ASSERT" in err.message
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user