WIP: PAIN3
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
import pytest
|
||||
from unittest.mock import MagicMock, patch
|
||||
from models import Ticket, Track, WorkerContext
|
||||
import ai_client
|
||||
from src.models import Ticket, Track, WorkerContext
|
||||
from src import ai_client
|
||||
|
||||
# These tests define the expected interface for multi_agent_conductor.py
|
||||
# which will be implemented in the next phase of TDD.
|
||||
@@ -11,7 +11,7 @@ def test_conductor_engine_initialization() -> None:
|
||||
Test that ConductorEngine can be initialized with a Track.
|
||||
"""
|
||||
track = Track(id="test_track", description="Test Track")
|
||||
from multi_agent_conductor import ConductorEngine
|
||||
from src.multi_agent_conductor import ConductorEngine
|
||||
engine = ConductorEngine(track=track, auto_queue=True)
|
||||
assert engine.track == track
|
||||
|
||||
@@ -23,7 +23,7 @@ async def test_conductor_engine_run_executes_tickets_in_order(monkeypatch: pytes
|
||||
ticket1 = Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1")
|
||||
ticket2 = Ticket(id="T2", description="Task 2", status="todo", assigned_to="worker2", depends_on=["T1"])
|
||||
track = Track(id="track1", description="Track 1", tickets=[ticket1, ticket2])
|
||||
from multi_agent_conductor import ConductorEngine
|
||||
from src.multi_agent_conductor import ConductorEngine
|
||||
engine = ConductorEngine(track=track, auto_queue=True)
|
||||
|
||||
vlogger.log_state("Ticket Count", 0, 2)
|
||||
@@ -34,7 +34,7 @@ async def test_conductor_engine_run_executes_tickets_in_order(monkeypatch: pytes
|
||||
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:
|
||||
with patch("src.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, *args, **kwargs):
|
||||
@@ -64,7 +64,7 @@ async def test_run_worker_lifecycle_calls_ai_client_send(monkeypatch: pytest.Mon
|
||||
"""
|
||||
ticket = Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1")
|
||||
context = WorkerContext(ticket_id="T1", model_name="test-model", messages=[])
|
||||
from multi_agent_conductor import run_worker_lifecycle
|
||||
from src.multi_agent_conductor import run_worker_lifecycle
|
||||
# Mock ai_client.send using monkeypatch
|
||||
mock_send = MagicMock()
|
||||
monkeypatch.setattr(ai_client, 'send', mock_send)
|
||||
@@ -86,12 +86,12 @@ async def test_run_worker_lifecycle_context_injection(monkeypatch: pytest.Monkey
|
||||
ticket = Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1")
|
||||
context = WorkerContext(ticket_id="T1", model_name="test-model", messages=[])
|
||||
context_files = ["primary.py", "secondary.py"]
|
||||
from multi_agent_conductor import run_worker_lifecycle
|
||||
from src.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("multi_agent_conductor.ASTParser") as mock_ast_parser_class, \
|
||||
with patch("src.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
|
||||
file_contents = {
|
||||
@@ -131,7 +131,7 @@ async def test_run_worker_lifecycle_handles_blocked_response(monkeypatch: pytest
|
||||
"""
|
||||
ticket = Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1")
|
||||
context = WorkerContext(ticket_id="T1", model_name="test-model", messages=[])
|
||||
from multi_agent_conductor import run_worker_lifecycle
|
||||
from src.multi_agent_conductor import run_worker_lifecycle
|
||||
# Mock ai_client.send using monkeypatch
|
||||
mock_send = MagicMock()
|
||||
monkeypatch.setattr(ai_client, 'send', mock_send)
|
||||
@@ -150,14 +150,14 @@ async def test_run_worker_lifecycle_step_mode_confirmation(monkeypatch: pytest.M
|
||||
"""
|
||||
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
|
||||
from src.multi_agent_conductor import run_worker_lifecycle
|
||||
# Mock ai_client.send using monkeypatch
|
||||
mock_send = MagicMock()
|
||||
monkeypatch.setattr(ai_client, 'send', mock_send)
|
||||
|
||||
# Important: confirm_spawn is called first if event_queue is present!
|
||||
with patch("multi_agent_conductor.confirm_spawn") as mock_spawn, \
|
||||
patch("multi_agent_conductor.confirm_execution") as mock_confirm:
|
||||
with patch("src.multi_agent_conductor.confirm_spawn") as mock_spawn, \
|
||||
patch("src.multi_agent_conductor.confirm_execution") as mock_confirm:
|
||||
mock_spawn.return_value = (True, "mock prompt", "mock context")
|
||||
mock_confirm.return_value = True
|
||||
|
||||
@@ -186,12 +186,12 @@ async def test_run_worker_lifecycle_step_mode_rejection(monkeypatch: pytest.Monk
|
||||
"""
|
||||
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
|
||||
from src.multi_agent_conductor import run_worker_lifecycle
|
||||
# Mock ai_client.send using monkeypatch
|
||||
mock_send = MagicMock()
|
||||
monkeypatch.setattr(ai_client, 'send', mock_send)
|
||||
with patch("multi_agent_conductor.confirm_spawn") as mock_spawn, \
|
||||
patch("multi_agent_conductor.confirm_execution") as mock_confirm:
|
||||
with patch("src.multi_agent_conductor.confirm_spawn") as mock_spawn, \
|
||||
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."
|
||||
@@ -209,7 +209,7 @@ async def test_conductor_engine_dynamic_parsing_and_execution(monkeypatch: pytes
|
||||
Test that parse_json_tickets correctly populates the track and run executes them in dependency order.
|
||||
"""
|
||||
import json
|
||||
from multi_agent_conductor import ConductorEngine
|
||||
from src.multi_agent_conductor import ConductorEngine
|
||||
track = Track(id="dynamic_track", description="Dynamic Track")
|
||||
engine = ConductorEngine(track=track, auto_queue=True)
|
||||
tickets_json = json.dumps([
|
||||
@@ -246,7 +246,7 @@ async def test_conductor_engine_dynamic_parsing_and_execution(monkeypatch: pytes
|
||||
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:
|
||||
with patch("src.multi_agent_conductor.run_worker_lifecycle") as mock_lifecycle:
|
||||
def side_effect(ticket, context, *args, **kwargs):
|
||||
ticket.mark_complete()
|
||||
return "Success"
|
||||
@@ -279,9 +279,9 @@ def test_run_worker_lifecycle_pushes_response_via_queue(monkeypatch: pytest.Monk
|
||||
mock_send = MagicMock(return_value="Task complete.")
|
||||
monkeypatch.setattr(ai_client, 'send', mock_send)
|
||||
monkeypatch.setattr(ai_client, 'reset_session', MagicMock())
|
||||
from multi_agent_conductor import run_worker_lifecycle
|
||||
with patch("multi_agent_conductor.confirm_spawn") as mock_spawn, \
|
||||
patch("multi_agent_conductor._queue_put") as mock_queue_put:
|
||||
from src.multi_agent_conductor import run_worker_lifecycle
|
||||
with patch("src.multi_agent_conductor.confirm_spawn") as mock_spawn, \
|
||||
patch("src.multi_agent_conductor._queue_put") as mock_queue_put:
|
||||
mock_spawn.return_value = (True, "prompt", "context")
|
||||
run_worker_lifecycle(ticket, context, event_queue=mock_event_queue, loop=mock_loop)
|
||||
mock_queue_put.assert_called_once()
|
||||
@@ -309,14 +309,13 @@ def test_run_worker_lifecycle_token_usage_from_comms_log(monkeypatch: pytest.Mon
|
||||
[], # baseline call (before send)
|
||||
fake_comms, # after-send call
|
||||
]))
|
||||
from multi_agent_conductor import run_worker_lifecycle, ConductorEngine
|
||||
from models import Track
|
||||
from src.multi_agent_conductor import run_worker_lifecycle, ConductorEngine
|
||||
from src.models import Track
|
||||
track = Track(id="test_track", description="Test")
|
||||
engine = ConductorEngine(track=track, auto_queue=True)
|
||||
with patch("multi_agent_conductor.confirm_spawn") as mock_spawn, \
|
||||
patch("multi_agent_conductor._queue_put"):
|
||||
with patch("src.multi_agent_conductor.confirm_spawn") as mock_spawn, \
|
||||
patch("src.multi_agent_conductor._queue_put"):
|
||||
mock_spawn.return_value = (True, "prompt", "ctx")
|
||||
run_worker_lifecycle(ticket, context, event_queue=MagicMock(), loop=MagicMock(), engine=engine)
|
||||
assert engine.tier_usage["Tier 3"]["input"] == 120
|
||||
assert engine.tier_usage["Tier 3"]["output"] == 45
|
||||
|
||||
|
||||
Reference in New Issue
Block a user