diff --git a/src/gui_2.py b/src/gui_2.py index 378a9143..5fd000a3 100644 --- a/src/gui_2.py +++ b/src/gui_2.py @@ -1644,10 +1644,32 @@ def render_main_interface(app: App) -> None: if app.controller._process_pending_tool_calls(): app._tool_log_dirty = True if app._pending_focus_response: app._pending_focus_response = False - try: - imgui.set_window_focus("Response") # type: ignore[call-arg] - except: - pass + focus_result = _focus_response_window_result() + if not focus_result.ok: + if not hasattr(app, '_last_request_errors'): app._last_request_errors = [] + app._last_request_errors.append(("render_main_interface.focus_response", focus_result.errors[0])) + +def _focus_response_window_result() -> Result[None]: + """Drain-aware variant of render_main_interface imgui.set_window_focus try block (L1647 INTERNAL_SILENT_SWALLOW). + + Extracts the thirdparty imgui.set_window_focus("Response") try/except from + render_main_interface into a Result-returning helper. On exception (native + bundle error, IM_ASSERT), converts to ErrorInfo (logging NOT a drain per + the user's principle 2026-06-17). The caller drains to + app._last_request_errors. + + [C: src/gui_2.py:render_main_interface (L1647 legacy wrapper)] + """ + try: + imgui.set_window_focus("Response") # type: ignore[call-arg] + return Result(data=None) + except Exception as e: + return Result(data=None, errors=[ErrorInfo( + kind=ErrorKind.INTERNAL, + message=f"imgui.set_window_focus('Response') failed: {e}", + source="gui_2._focus_response_window_result", + original=e, + )]) #endregion: Process GUI task queue render_track_proposal_modal(app) diff --git a/tests/test_gui_2_result.py b/tests/test_gui_2_result.py index 247d6114..19d2592d 100644 --- a/tests/test_gui_2_result.py +++ b/tests/test_gui_2_result.py @@ -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 + +