refactor(app_controller): migrate _push_mma_state_update + _load_beads to Result helpers (Phase 7)

Tasks 7.4 + 7.5: Migrate two more strict-violation sites to proper
Result[T] propagation:
- _push_mma_state_update: legacy wrapper preserved (fire-and-forget
  semantics) but routes errors through _report_worker_error. New
  _push_mma_state_update_result helper returns Result[None].
- _load_active_tickets.beads inner: extracted to
  _load_beads_from_path_result helper; outer merges errors via
  _report_worker_error.

Per Phase 7 spec 22.5.3 + 22.5.4:
- Each helper catches OSError/IOError/ValueError/TypeError/KeyError/
  AttributeError -> ErrorInfo(original=e).
- Drain is Pattern 4 telemetry via _report_worker_error
  (Pattern 4 = in-process telemetry buffer that sub-track 4 forwards
  to GUI per error_handling.md:421).

TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end
before this commit.
This commit is contained in:
ed
2026-06-19 19:13:20 -04:00
parent 9bba317d72
commit bab5d212e5
2 changed files with 64 additions and 25 deletions
+13 -7
View File
@@ -575,17 +575,21 @@ def test_push_mma_state_update_records_error_in_state():
def test_load_beads_from_path_returns_result():
"""
Phase 7 Task 7.5: _load_beads_from_path_result returns Result[List[Ticket]].
Phase 7 Task 7.5: _load_beads_from_path_result returns Result[List[Bead]].
On error: ErrorInfo(original=e).
"""
from pathlib import Path
from src.app_controller import AppController
from unittest.mock import MagicMock
ctrl = AppController()
assert hasattr(ctrl, "_load_beads_from_path_result"), (
"AppController must have _load_beads_from_path_result helper per Phase 7."
)
# Success path returns Result with empty list when no tickets
with patch("src.app_controller.beads_client.list_tickets", return_value=[]):
result = ctrl._load_beads_from_path_result("/tmp/fake_beads_path")
# Success path returns Result with empty list when not initialized
fake_bclient = MagicMock()
fake_bclient.is_initialized.return_value = False
with patch("src.beads_client.BeadsClient", return_value=fake_bclient):
result = ctrl._load_beads_from_path_result(Path("/tmp/fake_beads_path"))
assert isinstance(result, Result)
assert result.ok is True
assert result.data == []
@@ -593,14 +597,16 @@ def test_load_beads_from_path_returns_result():
def test_load_beads_from_path_records_error_on_failure():
"""
Phase 7 Task 7.5: when beads_client.list_tickets raises, the helper returns
Phase 7 Task 7.5: when BeadsClient constructor raises, the helper returns
Result with ErrorInfo(original=e).
"""
from pathlib import Path
from src.app_controller import AppController
from unittest.mock import MagicMock
ctrl = AppController()
with patch("src.app_controller.beads_client.list_tickets",
with patch("src.beads_client.BeadsClient",
side_effect=OSError("beads path not found")):
result = ctrl._load_beads_from_path_result("/tmp/nonexistent")
result = ctrl._load_beads_from_path_result(Path("/tmp/nonexistent"))
assert isinstance(result, Result)
assert result.ok is False
assert len(result.errors) == 1