TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 4: refactor(gui_2): migrate L3718 render_ast_inspector_modal outline to Result[T] (Phase 4)

Adds _render_ast_inspector_outline_result(app, f_path) -> Result[str] helper that wraps
the mcp_client.configure + outline fetch try/except in render_ast_inspector_modal.
The data field carries the outline string so the legacy wrapper can iterate it
without an additional instance attribute. Errors drain to app._last_request_errors
(per FR-BC-3 modal pattern; data plane attribute).

Audit: BROAD_CATCH count 16 -> 15, COMPLIANT count 21 -> 22. Migration
target count drops by 1. Tests: 2/2 pass.
This commit is contained in:
ed
2026-06-19 22:48:43 -04:00
parent 1ef0e07093
commit e558da81e1
2 changed files with 79 additions and 10 deletions
+40
View File
@@ -658,3 +658,43 @@ def test_phase_4_l3398_render_persona_editor_save_result_failure():
assert err.source == "gui_2._render_persona_editor_save_result"
assert "validation failed" in err.message
assert "Error:" in app.ai_status
def test_phase_4_l3718_render_ast_inspector_outline_result_success():
"""
L3718 _render_ast_inspector_outline_result returns Result.ok=True on success.
The helper wraps the mcp_client.{py,ts_c,ts_cpp}_get_code_outline try/except
in render_ast_inspector_modal. On success, returns Result(data=outline)
where outline is the string from the appropriate outline function.
"""
from src import gui_2
from unittest.mock import MagicMock, patch
app = MagicMock()
app.controller.active_project_path = "/proj/foo"
with patch.object(gui_2.mcp_client, "configure") as _cfg, \
patch.object(gui_2.mcp_client, "py_get_code_outline", return_value="[def] foo (Lines 1-10)") as _outline:
result = gui_2._render_ast_inspector_outline_result(app, "/proj/foo/src/bar.py")
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
assert result.data == "[def] foo (Lines 1-10)"
def test_phase_4_l3718_render_ast_inspector_outline_result_failure():
"""
L3718 _render_ast_inspector_outline_result returns Result.ok=False on failure.
When mcp_client configure or outline fetch raises, the helper returns
Result(data="", errors=[ErrorInfo]). The legacy wrapper should drain
to app._last_request_errors (per FR-BC-3 modal pattern).
"""
from src import gui_2
from unittest.mock import MagicMock, patch
app = MagicMock()
app.controller.active_project_path = "/proj/foo"
with patch.object(gui_2.mcp_client, "configure", side_effect=RuntimeError("configure failed")):
result = gui_2._render_ast_inspector_outline_result(app, "/proj/foo/src/bar.py")
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_ast_inspector_outline_result"
assert "Error fetching outline" in result.data