WIP: STILL FIXING FUNDAMENTAL TRASH
This commit is contained in:
@@ -1,18 +1,13 @@
|
||||
|
||||
from src import ai_client
|
||||
from src import models
|
||||
from src import multi_agent_conductor
|
||||
import pytest
|
||||
from unittest.mock import MagicMock, patch
|
||||
from src.models import Ticket, Track, WorkerContext
|
||||
from src import ai_client
|
||||
from src import models
|
||||
from src import multi_agent_conductor
|
||||
|
||||
-> None:
|
||||
def test_conductor_engine_initialization() -> None:
|
||||
"""
|
||||
Test that ConductorEngine can be initialized with a models.Track.
|
||||
Test that ConductorEngine can be initialized with a Track.
|
||||
"""
|
||||
track = models.Track(id="test_track", description="Test models.Track")
|
||||
track = Track(id="test_track", description="Test Track")
|
||||
from src.multi_agent_conductor import ConductorEngine
|
||||
engine = ConductorEngine(track=track, auto_queue=True)
|
||||
assert engine.track == track
|
||||
@@ -21,13 +16,13 @@ def test_conductor_engine_run_executes_tickets_in_order(monkeypatch: pytest.Monk
|
||||
"""
|
||||
Test that run iterates through executable tickets and calls the worker lifecycle.
|
||||
"""
|
||||
ticket1 = models.Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1")
|
||||
ticket2 = models.Ticket(id="T2", description="Task 2", status="todo", assigned_to="worker2", depends_on=["T1"])
|
||||
track = models.Track(id="track1", description="src.models.Track 1", tickets=[ticket1, ticket2])
|
||||
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 src.multi_agent_conductor import ConductorEngine
|
||||
engine = ConductorEngine(track=track, auto_queue=True)
|
||||
|
||||
vlogger.log_state("src.models.Ticket Count", 0, 2)
|
||||
|
||||
vlogger.log_state("Ticket Count", 0, 2)
|
||||
vlogger.log_state("T1 Status", "todo", "todo")
|
||||
vlogger.log_state("T2 Status", "todo", "todo")
|
||||
|
||||
@@ -43,11 +38,11 @@ def test_conductor_engine_run_executes_tickets_in_order(monkeypatch: pytest.Monk
|
||||
return "Success"
|
||||
mock_lifecycle.side_effect = side_effect
|
||||
engine.run()
|
||||
|
||||
|
||||
vlogger.log_state("T1 Status Final", "todo", ticket1.status)
|
||||
vlogger.log_state("T2 Status Final", "todo", ticket2.status)
|
||||
|
||||
# models.Track.get_executable_tickets() should be called repeatedly until all are done
|
||||
|
||||
# Track.get_executable_tickets() should be called repeatedly until all are done
|
||||
# T1 should run first, then T2.
|
||||
assert mock_lifecycle.call_count == 2
|
||||
assert ticket1.status == "completed"
|
||||
@@ -62,15 +57,14 @@ def test_run_worker_lifecycle_calls_ai_client_send(monkeypatch: pytest.MonkeyPat
|
||||
"""
|
||||
Test that run_worker_lifecycle triggers the AI client and updates ticket status on success.
|
||||
"""
|
||||
ticket = models.Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1")
|
||||
ticket = Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1")
|
||||
context = WorkerContext(ticket_id="T1", model_name="test-model", messages=[])
|
||||
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)
|
||||
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."
|
||||
run_worker_lifecycle(ticket, context)
|
||||
assert ticket.status == "completed"
|
||||
mock_send.assert_called_once()
|
||||
# Check if description was passed to send()
|
||||
@@ -82,7 +76,7 @@ def test_run_worker_lifecycle_context_injection(monkeypatch: pytest.MonkeyPatch)
|
||||
"""
|
||||
Test that run_worker_lifecycle can take a context_files list and injects AST views into the prompt.
|
||||
"""
|
||||
ticket = models.Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1")
|
||||
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 src.multi_agent_conductor import run_worker_lifecycle
|
||||
@@ -127,7 +121,7 @@ def test_run_worker_lifecycle_handles_blocked_response(monkeypatch: pytest.Monke
|
||||
"""
|
||||
Test that run_worker_lifecycle marks the ticket as blocked if the AI indicates it cannot proceed.
|
||||
"""
|
||||
ticket = models.Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1")
|
||||
ticket = Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1")
|
||||
context = WorkerContext(ticket_id="T1", model_name="test-model", messages=[])
|
||||
from src.multi_agent_conductor import run_worker_lifecycle
|
||||
# Mock ai_client.send using monkeypatch
|
||||
@@ -145,13 +139,13 @@ def test_run_worker_lifecycle_step_mode_confirmation(monkeypatch: pytest.MonkeyP
|
||||
Verify that if confirm_execution is called (simulated by mocking ai_client.send to call its callback),
|
||||
the flow works as expected.
|
||||
"""
|
||||
ticket = models.Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1", step_mode=True)
|
||||
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 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("src.multi_agent_conductor.confirm_spawn") as mock_spawn, \
|
||||
patch("src.multi_agent_conductor.confirm_execution") as mock_confirm:
|
||||
@@ -165,10 +159,10 @@ def test_run_worker_lifecycle_step_mode_confirmation(monkeypatch: pytest.MonkeyP
|
||||
callback('{"tool": "read_file", "args": {"path": "test.txt"}}')
|
||||
return "Success"
|
||||
mock_send.side_effect = mock_send_side_effect
|
||||
|
||||
|
||||
mock_event_queue = MagicMock()
|
||||
run_worker_lifecycle(ticket, context, event_queue=mock_event_queue)
|
||||
|
||||
|
||||
# Verify confirm_spawn was called because event_queue was present
|
||||
mock_spawn.assert_called_once()
|
||||
# Verify confirm_execution was called
|
||||
@@ -180,7 +174,7 @@ def test_run_worker_lifecycle_step_mode_rejection(monkeypatch: pytest.MonkeyPatc
|
||||
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.
|
||||
"""
|
||||
ticket = models.Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1", step_mode=True)
|
||||
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 src.multi_agent_conductor import run_worker_lifecycle
|
||||
# Mock ai_client.send using monkeypatch
|
||||
@@ -191,10 +185,10 @@ def test_run_worker_lifecycle_step_mode_rejection(monkeypatch: pytest.MonkeyPatc
|
||||
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_event_queue = MagicMock()
|
||||
run_worker_lifecycle(ticket, context, event_queue=mock_event_queue)
|
||||
|
||||
|
||||
# Verify it was passed to send
|
||||
args, kwargs = mock_send.call_args
|
||||
assert kwargs["pre_tool_callback"] is not None
|
||||
@@ -205,7 +199,7 @@ def test_conductor_engine_dynamic_parsing_and_execution(monkeypatch: pytest.Monk
|
||||
"""
|
||||
import json
|
||||
from src.multi_agent_conductor import ConductorEngine
|
||||
track = models.Track(id="dynamic_track", description="Dynamic models.Track")
|
||||
track = Track(id="dynamic_track", description="Dynamic Track")
|
||||
engine = ConductorEngine(track=track, auto_queue=True)
|
||||
tickets_json = json.dumps([
|
||||
{
|
||||
@@ -231,8 +225,8 @@ def test_conductor_engine_dynamic_parsing_and_execution(monkeypatch: pytest.Monk
|
||||
}
|
||||
])
|
||||
engine.parse_json_tickets(tickets_json)
|
||||
|
||||
vlogger.log_state("Parsed models.Ticket Count", 0, len(engine.track.tickets))
|
||||
|
||||
vlogger.log_state("Parsed Ticket Count", 0, len(engine.track.tickets))
|
||||
assert len(engine.track.tickets) == 3
|
||||
assert engine.track.tickets[0].id == "T1"
|
||||
assert engine.track.tickets[1].id == "T2"
|
||||
@@ -252,10 +246,10 @@ def test_conductor_engine_dynamic_parsing_and_execution(monkeypatch: pytest.Monk
|
||||
calls = [call[0][0].id for call in mock_lifecycle.call_args_list]
|
||||
t1_idx = calls.index("T1")
|
||||
t2_idx = calls.index("T2")
|
||||
|
||||
|
||||
vlogger.log_state("T1 Sequence Index", "N/A", t1_idx)
|
||||
vlogger.log_state("T2 Sequence Index", "N/A", t2_idx)
|
||||
|
||||
|
||||
assert t1_idx < t2_idx
|
||||
# T3 can be anywhere relative to T1 and T2, but T1 < T2 is mandatory
|
||||
assert "T3" in calls
|
||||
@@ -266,7 +260,7 @@ def test_run_worker_lifecycle_pushes_response_via_queue(monkeypatch: pytest.Monk
|
||||
Test that run_worker_lifecycle pushes a 'response' event with the correct stream_id
|
||||
via _queue_put when event_queue is provided.
|
||||
"""
|
||||
ticket = models.Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1")
|
||||
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.")
|
||||
@@ -290,7 +284,7 @@ def test_run_worker_lifecycle_token_usage_from_comms_log(monkeypatch: pytest.Mon
|
||||
Test that run_worker_lifecycle reads token usage from the comms log and
|
||||
updates engine.tier_usage['Tier 3'] with real input/output token counts.
|
||||
"""
|
||||
ticket = models.Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1")
|
||||
ticket = Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1")
|
||||
context = WorkerContext(ticket_id="T1", model_name="test-model", messages=[])
|
||||
fake_comms = [
|
||||
{"direction": "OUT", "kind": "request", "payload": {"message": "hello"}},
|
||||
@@ -303,8 +297,7 @@ def test_run_worker_lifecycle_token_usage_from_comms_log(monkeypatch: pytest.Mon
|
||||
fake_comms, # after-send call
|
||||
]))
|
||||
from src.multi_agent_conductor import run_worker_lifecycle, ConductorEngine
|
||||
from src.models import models.Track
|
||||
track = models.Track(id="test_track", description="Test")
|
||||
track = Track(id="test_track", description="Test")
|
||||
engine = ConductorEngine(track=track, auto_queue=True)
|
||||
with patch("src.multi_agent_conductor.confirm_spawn") as mock_spawn, \
|
||||
patch("src.multi_agent_conductor._queue_put"):
|
||||
|
||||
Reference in New Issue
Block a user