feat(mma): Finalize Orchestrator Integration and fix all regressions
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import pytest
|
||||
from unittest.mock import MagicMock, patch
|
||||
from models import Ticket, Track, WorkerContext
|
||||
import ai_client
|
||||
|
||||
# These tests define the expected interface for multi_agent_conductor.py
|
||||
# which will be implemented in the next phase of TDD.
|
||||
@@ -14,7 +15,8 @@ def test_conductor_engine_initialization():
|
||||
engine = ConductorEngine(track=track)
|
||||
assert engine.track == track
|
||||
|
||||
def test_conductor_engine_run_linear_executes_tickets_in_order():
|
||||
@pytest.mark.asyncio
|
||||
async def test_conductor_engine_run_linear_executes_tickets_in_order(monkeypatch):
|
||||
"""
|
||||
Test that run_linear iterates through executable tickets and calls the worker lifecycle.
|
||||
"""
|
||||
@@ -25,15 +27,19 @@ def test_conductor_engine_run_linear_executes_tickets_in_order():
|
||||
from multi_agent_conductor import ConductorEngine
|
||||
engine = ConductorEngine(track=track)
|
||||
|
||||
# Mock ai_client.send using monkeypatch
|
||||
mock_send = MagicMock()
|
||||
monkeypatch.setattr(ai_client, 'send', mock_send)
|
||||
|
||||
# We mock run_worker_lifecycle as it is expected to be in the same module
|
||||
with patch("multi_agent_conductor.run_worker_lifecycle") as mock_lifecycle:
|
||||
# Mocking lifecycle to mark ticket as complete so dependencies can be resolved
|
||||
def side_effect(ticket, context):
|
||||
def side_effect(ticket, context, *args, **kwargs):
|
||||
ticket.mark_complete()
|
||||
return "Success"
|
||||
mock_lifecycle.side_effect = side_effect
|
||||
|
||||
engine.run_linear()
|
||||
await engine.run_linear()
|
||||
|
||||
# Track.get_executable_tickets() should be called repeatedly until all are done
|
||||
# T1 should run first, then T2.
|
||||
@@ -46,7 +52,8 @@ def test_conductor_engine_run_linear_executes_tickets_in_order():
|
||||
assert calls[0][0][0].id == "T1"
|
||||
assert calls[1][0][0].id == "T2"
|
||||
|
||||
def test_run_worker_lifecycle_calls_ai_client_send():
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_worker_lifecycle_calls_ai_client_send(monkeypatch):
|
||||
"""
|
||||
Test that run_worker_lifecycle triggers the AI client and updates ticket status on success.
|
||||
"""
|
||||
@@ -55,21 +62,25 @@ def test_run_worker_lifecycle_calls_ai_client_send():
|
||||
|
||||
from multi_agent_conductor import run_worker_lifecycle
|
||||
|
||||
with patch("ai_client.send") as mock_send:
|
||||
mock_send.return_value = "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"
|
||||
mock_send.assert_called_once()
|
||||
|
||||
# Check if description was passed to send()
|
||||
args, kwargs = mock_send.call_args
|
||||
# user_message is passed as a keyword argument
|
||||
assert ticket.description in kwargs["user_message"]
|
||||
# Mock ai_client.send using monkeypatch
|
||||
mock_send = MagicMock()
|
||||
monkeypatch.setattr(ai_client, 'send', mock_send)
|
||||
|
||||
mock_send.return_value = "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"
|
||||
mock_send.assert_called_once()
|
||||
|
||||
# Check if description was passed to send()
|
||||
args, kwargs = mock_send.call_args
|
||||
# user_message is passed as a keyword argument
|
||||
assert ticket.description in kwargs["user_message"]
|
||||
|
||||
def test_run_worker_lifecycle_context_injection():
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_worker_lifecycle_context_injection(monkeypatch):
|
||||
"""
|
||||
Test that run_worker_lifecycle can take a context_files list and injects AST views into the prompt.
|
||||
"""
|
||||
@@ -79,9 +90,12 @@ def test_run_worker_lifecycle_context_injection():
|
||||
|
||||
from multi_agent_conductor import run_worker_lifecycle
|
||||
|
||||
# Mock ai_client.send using monkeypatch
|
||||
mock_send = MagicMock()
|
||||
monkeypatch.setattr(ai_client, 'send', mock_send)
|
||||
|
||||
# We mock ASTParser which is expected to be imported in multi_agent_conductor
|
||||
with patch("ai_client.send") as mock_send, \
|
||||
patch("multi_agent_conductor.ASTParser") as mock_ast_parser_class, \
|
||||
with patch("multi_agent_conductor.ASTParser") as mock_ast_parser_class, \
|
||||
patch("builtins.open", new_callable=MagicMock) as mock_open:
|
||||
|
||||
# Setup open mock to return different content for different files
|
||||
@@ -121,7 +135,8 @@ def test_run_worker_lifecycle_context_injection():
|
||||
assert "primary.py" in user_message
|
||||
assert "secondary.py" in user_message
|
||||
|
||||
def test_run_worker_lifecycle_handles_blocked_response():
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_worker_lifecycle_handles_blocked_response(monkeypatch):
|
||||
"""
|
||||
Test that run_worker_lifecycle marks the ticket as blocked if the AI indicates it cannot proceed.
|
||||
"""
|
||||
@@ -130,16 +145,20 @@ def test_run_worker_lifecycle_handles_blocked_response():
|
||||
|
||||
from multi_agent_conductor import run_worker_lifecycle
|
||||
|
||||
with patch("ai_client.send") as mock_send:
|
||||
# Simulate a response indicating a block
|
||||
mock_send.return_value = "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
|
||||
# Mock ai_client.send using monkeypatch
|
||||
mock_send = MagicMock()
|
||||
monkeypatch.setattr(ai_client, 'send', mock_send)
|
||||
|
||||
# Simulate a response indicating a block
|
||||
mock_send.return_value = "I am BLOCKED because I don't have enough information."
|
||||
|
||||
run_worker_lifecycle(ticket, context)
|
||||
|
||||
def test_run_worker_lifecycle_step_mode_confirmation():
|
||||
assert ticket.status == "blocked"
|
||||
assert "BLOCKED" in ticket.blocked_reason
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_worker_lifecycle_step_mode_confirmation(monkeypatch):
|
||||
"""
|
||||
Test that run_worker_lifecycle passes confirm_execution to ai_client.send when step_mode is True.
|
||||
Verify that if confirm_execution is called (simulated by mocking ai_client.send to call its callback),
|
||||
@@ -148,13 +167,16 @@ def test_run_worker_lifecycle_step_mode_confirmation():
|
||||
ticket = Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1", step_mode=True)
|
||||
context = WorkerContext(ticket_id="T1", model_name="test-model", messages=[])
|
||||
|
||||
from multi_agent_conductor import run_worker_lifecycle, confirm_execution
|
||||
from multi_agent_conductor import run_worker_lifecycle
|
||||
|
||||
with patch("ai_client.send") as mock_send, \
|
||||
patch("multi_agent_conductor.confirm_execution") as mock_confirm:
|
||||
# Mock ai_client.send using monkeypatch
|
||||
mock_send = MagicMock()
|
||||
monkeypatch.setattr(ai_client, 'send', mock_send)
|
||||
|
||||
with patch("multi_agent_conductor.confirm_execution") as mock_confirm:
|
||||
|
||||
# We simulate ai_client.send by making it call the pre_tool_callback it received
|
||||
def mock_send_side_effect(*args, **kwargs):
|
||||
def mock_send_side_effect(md_content, user_message, **kwargs):
|
||||
callback = kwargs.get("pre_tool_callback")
|
||||
if callback:
|
||||
# Simulate calling it with some payload
|
||||
@@ -164,13 +186,15 @@ def test_run_worker_lifecycle_step_mode_confirmation():
|
||||
mock_send.side_effect = mock_send_side_effect
|
||||
mock_confirm.return_value = True
|
||||
|
||||
run_worker_lifecycle(ticket, context)
|
||||
mock_event_queue = MagicMock()
|
||||
run_worker_lifecycle(ticket, context, event_queue=mock_event_queue)
|
||||
|
||||
# Verify confirm_execution was called
|
||||
mock_confirm.assert_called_once()
|
||||
assert ticket.status == "completed"
|
||||
|
||||
def test_run_worker_lifecycle_step_mode_rejection():
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_worker_lifecycle_step_mode_rejection(monkeypatch):
|
||||
"""
|
||||
Verify that if confirm_execution returns False, the logic (in ai_client, which we simulate here)
|
||||
would prevent execution. In run_worker_lifecycle, we just check if it's passed.
|
||||
@@ -180,8 +204,11 @@ def test_run_worker_lifecycle_step_mode_rejection():
|
||||
|
||||
from multi_agent_conductor import run_worker_lifecycle
|
||||
|
||||
with patch("ai_client.send") as mock_send, \
|
||||
patch("multi_agent_conductor.confirm_execution") as mock_confirm:
|
||||
# Mock ai_client.send using monkeypatch
|
||||
mock_send = MagicMock()
|
||||
monkeypatch.setattr(ai_client, 'send', mock_send)
|
||||
|
||||
with patch("multi_agent_conductor.confirm_execution") as mock_confirm:
|
||||
|
||||
mock_confirm.return_value = False
|
||||
mock_send.return_value = "Task failed because tool execution was rejected."
|
||||
@@ -195,7 +222,8 @@ def test_run_worker_lifecycle_step_mode_rejection():
|
||||
# Since we've already tested ai_client's implementation of pre_tool_callback (mentally or via other tests),
|
||||
# here we just verify the wiring.
|
||||
|
||||
def test_conductor_engine_dynamic_parsing_and_execution():
|
||||
@pytest.mark.asyncio
|
||||
async def test_conductor_engine_dynamic_parsing_and_execution(monkeypatch):
|
||||
"""
|
||||
Test that parse_json_tickets correctly populates the track and run_linear executes them in dependency order.
|
||||
"""
|
||||
@@ -236,14 +264,18 @@ def test_conductor_engine_dynamic_parsing_and_execution():
|
||||
assert engine.track.tickets[1].id == "T2"
|
||||
assert engine.track.tickets[2].id == "T3"
|
||||
|
||||
# Mock ai_client.send using monkeypatch
|
||||
mock_send = MagicMock()
|
||||
monkeypatch.setattr(ai_client, 'send', mock_send)
|
||||
|
||||
# Mock run_worker_lifecycle to mark tickets as complete
|
||||
with patch("multi_agent_conductor.run_worker_lifecycle") as mock_lifecycle:
|
||||
def side_effect(ticket, context):
|
||||
def side_effect(ticket, context, *args, **kwargs):
|
||||
ticket.mark_complete()
|
||||
return "Success"
|
||||
mock_lifecycle.side_effect = side_effect
|
||||
|
||||
engine.run_linear()
|
||||
await engine.run_linear()
|
||||
|
||||
assert mock_lifecycle.call_count == 3
|
||||
|
||||
|
||||
Reference in New Issue
Block a user