test(conductor_engine_v2): wrap mock_send return values in Result(data=...)

The 7 tests in test_conductor_engine_v2.py (already updated to
mock src.ai_client.send_result) were still returning raw strings
from the mocks. The production code in multi_agent_conductor.py
now does "if not result.ok:" which fails on raw strings with
AttributeError.

Changes:
- Add "from src.result_types import Result" import
- Wrap all mock_send.return_value = "..." with Result(data="...") (4 sites)
- Wrap MagicMock(return_value="...") with Result(data="...") (2 sites)
- Wrap side_effect return with Result(data="Success")

10/10 tests pass (was 3/10).
This commit is contained in:
ed
2026-06-15 20:21:46 -04:00
parent 125a226525
commit 64278d5313
+10 -9
View File
@@ -6,6 +6,7 @@ import pytest
from unittest.mock import MagicMock, patch
from src.models import Ticket, Track, WorkerContext
from src import ai_client
from src.result_types import Result
def test_conductor_engine_initialization() -> None:
"""
@@ -48,7 +49,7 @@ def test_conductor_engine_run_executes_tickets_in_order(monkeypatch: pytest.Monk
time.sleep(0.1)
ticket.mark_complete()
threading.Thread(target=do_work).start()
return "Success"
return Result(data="Success")
mock_lifecycle.side_effect = side_effect
engine.run(max_ticks=20)
@@ -78,7 +79,7 @@ def test_run_worker_lifecycle_calls_ai_client_send(monkeypatch: pytest.MonkeyPat
# Mock ai_client.send_result using monkeypatch
mock_send = MagicMock()
monkeypatch.setattr(ai_client, 'send_result', mock_send)
mock_send.return_value = "Task complete. I have updated the file."
mock_send.return_value = Result(data="Task complete. I have updated the file.")
result = run_worker_lifecycle(ticket, context)
assert result == "Task complete. I have updated the file."
assert ticket.status == "completed"
@@ -121,7 +122,7 @@ def test_run_worker_lifecycle_context_injection(monkeypatch: pytest.MonkeyPatch)
mock_ast_parser = mock_ast_parser_class.return_value
mock_ast_parser.get_curated_view.return_value = "CURATED VIEW"
mock_ast_parser.get_skeleton.return_value = "SKELETON VIEW"
mock_send.return_value = "Success"
mock_send.return_value = Result(data="Success")
run_worker_lifecycle(ticket, context, context_files=context_files)
# Verify ASTParser calls:
# First file (primary) should get curated view, others (secondary) get skeleton
@@ -148,7 +149,7 @@ def test_run_worker_lifecycle_handles_blocked_response(monkeypatch: pytest.Monke
mock_send = MagicMock()
monkeypatch.setattr(ai_client, 'send_result', mock_send)
# Simulate a response indicating a block
mock_send.return_value = "I am BLOCKED because I don't have enough information."
mock_send.return_value = Result(data="I am BLOCKED because I don't have enough information.")
run_worker_lifecycle(ticket, context)
assert ticket.status == "blocked"
assert "BLOCKED" in ticket.blocked_reason
@@ -179,7 +180,7 @@ def test_run_worker_lifecycle_step_mode_confirmation(monkeypatch: pytest.MonkeyP
if callback:
# Simulate calling it with some payload
callback('{"tool": "read_file", "args": {"path": "test.txt"}}')
return "Success"
return Result(data="Success")
mock_send.side_effect = mock_send_side_effect
mock_event_queue = MagicMock()
@@ -208,7 +209,7 @@ def test_run_worker_lifecycle_step_mode_rejection(monkeypatch: pytest.MonkeyPatc
patch("src.multi_agent_conductor.confirm_execution") as mock_confirm:
mock_spawn.return_value = (True, "mock prompt", "mock context")
mock_confirm.return_value = False
mock_send.return_value = "Task failed because tool execution was rejected."
mock_send.return_value = Result(data="Task failed because tool execution was rejected.")
mock_event_queue = MagicMock()
run_worker_lifecycle(ticket, context, event_queue=mock_event_queue)
@@ -269,7 +270,7 @@ def test_conductor_engine_dynamic_parsing_and_execution(monkeypatch: pytest.Monk
time.sleep(0.1)
ticket.mark_complete()
threading.Thread(target=do_work).start()
return "Success"
return Result(data="Success")
mock_lifecycle.side_effect = side_effect
engine.run(max_ticks=20)
assert mock_lifecycle.call_count == 3
@@ -296,7 +297,7 @@ def test_run_worker_lifecycle_pushes_response_via_queue(monkeypatch: pytest.Monk
ticket = Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1")
context = WorkerContext(ticket_id="T1", model_name="test-model", messages=[])
mock_event_queue = MagicMock()
mock_send = MagicMock(return_value="Task complete.")
mock_send = MagicMock(return_value=Result(data="Task complete."))
monkeypatch.setattr(ai_client, 'send_result', mock_send)
monkeypatch.setattr(ai_client, 'reset_session', MagicMock())
from src.multi_agent_conductor import run_worker_lifecycle
@@ -326,7 +327,7 @@ def test_run_worker_lifecycle_token_usage_from_comms_log(monkeypatch: pytest.Mon
{"direction": "OUT", "kind": "request", "payload": {"message": "hello"}},
{"direction": "IN", "kind": "response", "payload": {"usage": {"input_tokens": 120, "output_tokens": 45}}},
]
monkeypatch.setattr(ai_client, 'send_result', MagicMock(return_value="Done."))
monkeypatch.setattr(ai_client, 'send_result', MagicMock(return_value=Result(data="Done.")))
monkeypatch.setattr(ai_client, 'reset_session', MagicMock())
monkeypatch.setattr(ai_client, 'get_comms_log', MagicMock(side_effect=[
[], # baseline call (before send_result)