test(stabilization): Resolve run_linear API drift and implement vlogger high-signal reporting
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import pytest
|
||||
import pytest
|
||||
from unittest.mock import MagicMock, patch
|
||||
from models import Ticket, Track, WorkerContext
|
||||
import ai_client
|
||||
import multi_agent_conductor
|
||||
|
||||
# These tests define the expected interface for multi_agent_conductor.py
|
||||
# which will be implemented in the next phase of TDD.
|
||||
@@ -12,19 +13,24 @@ def test_conductor_engine_initialization() -> None:
|
||||
"""
|
||||
track = Track(id="test_track", description="Test Track")
|
||||
from multi_agent_conductor import ConductorEngine
|
||||
engine = ConductorEngine(track=track)
|
||||
engine = ConductorEngine(track=track, auto_queue=True)
|
||||
assert engine.track == track
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_conductor_engine_run_linear_executes_tickets_in_order(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
async def test_conductor_engine_run_executes_tickets_in_order(monkeypatch: pytest.MonkeyPatch, vlogger) -> None:
|
||||
"""
|
||||
Test that run_linear iterates through executable tickets and calls the worker lifecycle.
|
||||
Test that run iterates through executable tickets and calls the worker lifecycle.
|
||||
"""
|
||||
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
|
||||
engine = ConductorEngine(track=track)
|
||||
engine = ConductorEngine(track=track, auto_queue=True)
|
||||
|
||||
vlogger.log_state("Ticket Count", 0, 2)
|
||||
vlogger.log_state("T1 Status", "todo", "todo")
|
||||
vlogger.log_state("T2 Status", "todo", "todo")
|
||||
|
||||
# Mock ai_client.send using monkeypatch
|
||||
mock_send = MagicMock()
|
||||
monkeypatch.setattr(ai_client, 'send', mock_send)
|
||||
@@ -36,7 +42,11 @@ async def test_conductor_engine_run_linear_executes_tickets_in_order(monkeypatch
|
||||
ticket.mark_complete()
|
||||
return "Success"
|
||||
mock_lifecycle.side_effect = side_effect
|
||||
await engine.run_linear()
|
||||
await engine.run()
|
||||
|
||||
vlogger.log_state("T1 Status Final", "todo", ticket1.status)
|
||||
vlogger.log_state("T2 Status Final", "todo", ticket2.status)
|
||||
|
||||
# Track.get_executable_tickets() should be called repeatedly until all are done
|
||||
# T1 should run first, then T2.
|
||||
assert mock_lifecycle.call_count == 2
|
||||
@@ -46,6 +56,7 @@ async def test_conductor_engine_run_linear_executes_tickets_in_order(monkeypatch
|
||||
calls = mock_lifecycle.call_args_list
|
||||
assert calls[0][0][0].id == "T1"
|
||||
assert calls[1][0][0].id == "T2"
|
||||
vlogger.finalize("Verify dependency execution order", "PASS", "T1 executed before T2")
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_worker_lifecycle_calls_ai_client_send(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
@@ -144,8 +155,12 @@ async def test_run_worker_lifecycle_step_mode_confirmation(monkeypatch: pytest.M
|
||||
# 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
|
||||
|
||||
# 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:
|
||||
mock_spawn.return_value = (True, "mock prompt", "mock context")
|
||||
mock_confirm.return_value = True
|
||||
|
||||
def mock_send_side_effect(md_content, user_message, **kwargs):
|
||||
callback = kwargs.get("pre_tool_callback")
|
||||
@@ -154,9 +169,12 @@ async def test_run_worker_lifecycle_step_mode_confirmation(monkeypatch: pytest.M
|
||||
callback('{"tool": "read_file", "args": {"path": "test.txt"}}')
|
||||
return "Success"
|
||||
mock_send.side_effect = mock_send_side_effect
|
||||
mock_confirm.return_value = True
|
||||
|
||||
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
|
||||
mock_confirm.assert_called_once()
|
||||
assert ticket.status == "completed"
|
||||
@@ -173,25 +191,28 @@ async def test_run_worker_lifecycle_step_mode_rejection(monkeypatch: pytest.Monk
|
||||
# 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:
|
||||
with patch("multi_agent_conductor.confirm_spawn") as mock_spawn, \
|
||||
patch("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."
|
||||
run_worker_lifecycle(ticket, context)
|
||||
|
||||
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
|
||||
# Since we've already tested ai_client's implementation of pre_tool_callback (mentally or via other tests),
|
||||
# here we just verify the wiring.
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_conductor_engine_dynamic_parsing_and_execution(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
async def test_conductor_engine_dynamic_parsing_and_execution(monkeypatch: pytest.MonkeyPatch, vlogger) -> None:
|
||||
"""
|
||||
Test that parse_json_tickets correctly populates the track and run_linear executes them in dependency order.
|
||||
Test that parse_json_tickets correctly populates the track and run executes them in dependency order.
|
||||
"""
|
||||
import json
|
||||
from multi_agent_conductor import ConductorEngine
|
||||
track = Track(id="dynamic_track", description="Dynamic Track")
|
||||
engine = ConductorEngine(track=track)
|
||||
engine = ConductorEngine(track=track, auto_queue=True)
|
||||
tickets_json = json.dumps([
|
||||
{
|
||||
"id": "T1",
|
||||
@@ -216,6 +237,8 @@ async def test_conductor_engine_dynamic_parsing_and_execution(monkeypatch: pytes
|
||||
}
|
||||
])
|
||||
engine.parse_json_tickets(tickets_json)
|
||||
|
||||
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"
|
||||
@@ -229,12 +252,18 @@ async def test_conductor_engine_dynamic_parsing_and_execution(monkeypatch: pytes
|
||||
ticket.mark_complete()
|
||||
return "Success"
|
||||
mock_lifecycle.side_effect = side_effect
|
||||
await engine.run_linear()
|
||||
await engine.run()
|
||||
assert mock_lifecycle.call_count == 3
|
||||
# Verify dependency order: T1 must be called before T2
|
||||
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
|
||||
vlogger.finalize("Dynamic track parsing and dependency execution", "PASS", "Dependency chain T1 -> T2 honored.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user