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

Extract _populate_auto_slices_outline_result helper from the
mcp_client.{py,ts_c,ts_cpp}_get_code_outline try/except in
App._populate_auto_slices. Legacy wrapper drains errors to
app._last_request_errors per FR-BC-4 event-handler pattern.

[pre-audit] L1284 INTERNAL_BROAD_CATCH
[post-audit] V count: 14 -> 13 (L1284 removed)
This commit is contained in:
ed
2026-06-19 23:29:10 -04:00
parent 3c34913caa
commit 38b6f5c00f
2 changed files with 89 additions and 10 deletions
+49
View File
@@ -790,3 +790,52 @@ def test_phase_4_invariant_all_3_migration_sites_have_tests():
f"Phase 4 invariant: missing failure test for L{line}. "
f"Expected a test matching '{failure_pattern}'."
)
# =============================================================================
# Phase 5 Tests - Migration of 11 INTERNAL_BROAD_CATCH event-handler sites to Result[T]
# Each site gets 2 tests: success and failure.
# Migration pattern: legacy wrapper routes errors to app._last_request_errors (per FR-BC-4).
# =============================================================================
def test_phase_5_l1284_populate_auto_slices_outline_result_success():
"""
L1284 _populate_auto_slices_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 App._populate_auto_slices. On success (Python file extension matches),
returns Result(data=outline).
"""
from src import gui_2
from unittest.mock import MagicMock, patch
app = MagicMock()
f_item = MagicMock()
f_item.path = "/proj/foo/src/bar.py"
abs_path = "/proj/foo/src/bar.py"
with patch.object(gui_2.mcp_client, "py_get_code_outline", return_value="[def] foo (Lines 1-10)"):
result = gui_2._populate_auto_slices_outline_result(app, f_item, abs_path)
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
assert result.data == "[def] foo (Lines 1-10)"
def test_phase_5_l1284_populate_auto_slices_outline_result_failure():
"""
L1284 _populate_auto_slices_outline_result returns Result.ok=False with ErrorInfo on failure.
When the underlying mcp_client outline fetch raises, the helper converts the
exception to ErrorInfo and returns Result(data="", errors=[ErrorInfo]).
"""
from src import gui_2
from unittest.mock import MagicMock, patch
app = MagicMock()
f_item = MagicMock()
f_item.path = "/proj/foo/src/bar.py"
abs_path = "/proj/foo/src/bar.py"
with patch.object(gui_2.mcp_client, "py_get_code_outline", side_effect=RuntimeError("outline fetch failed")):
result = gui_2._populate_auto_slices_outline_result(app, f_item, abs_path)
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._populate_auto_slices_outline_result"
assert "outline fetch failed" in err.message