WIP: PYTHON
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
from typing import Any
|
||||
import pytest
|
||||
from unittest.mock import MagicMock, patch
|
||||
from models import Ticket, Track
|
||||
import multi_agent_conductor
|
||||
from multi_agent_conductor import ConductorEngine
|
||||
from src.models import Ticket, Track
|
||||
from src import multi_agent_conductor
|
||||
from src.multi_agent_conductor import ConductorEngine
|
||||
from src import events
|
||||
from src import ai_client
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_headless_verification_full_run(vlogger) -> None:
|
||||
@@ -16,20 +18,20 @@ async def test_headless_verification_full_run(vlogger) -> None:
|
||||
t1 = Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1")
|
||||
t2 = Ticket(id="T2", description="Task 2", status="todo", assigned_to="worker1", depends_on=["T1"])
|
||||
track = Track(id="track_verify", description="Verification Track", tickets=[t1, t2])
|
||||
from events import AsyncEventQueue
|
||||
queue = AsyncEventQueue()
|
||||
from src.events import SyncEventQueue
|
||||
queue = SyncEventQueue()
|
||||
engine = ConductorEngine(track=track, event_queue=queue, auto_queue=True)
|
||||
|
||||
vlogger.log_state("T1 Status Initial", "todo", t1.status)
|
||||
vlogger.log_state("T2 Status Initial", "todo", t2.status)
|
||||
|
||||
# We must patch where it is USED: multi_agent_conductor
|
||||
with patch("multi_agent_conductor.ai_client.send") as mock_send, \
|
||||
patch("multi_agent_conductor.ai_client.reset_session") as mock_reset, \
|
||||
patch("multi_agent_conductor.confirm_spawn", return_value=(True, "mock_prompt", "mock_ctx")):
|
||||
with patch("src.multi_agent_conductor.ai_client.send") as mock_send, \
|
||||
patch("src.multi_agent_conductor.ai_client.reset_session") as mock_reset, \
|
||||
patch("src.multi_agent_conductor.confirm_spawn", return_value=(True, "mock_prompt", "mock_ctx")):
|
||||
# We need mock_send to return something that doesn't contain "BLOCKED"
|
||||
mock_send.return_value = "Task completed successfully."
|
||||
await engine.run()
|
||||
engine.run()
|
||||
|
||||
vlogger.log_state("T1 Status Final", "todo", t1.status)
|
||||
vlogger.log_state("T2 Status Final", "todo", t2.status)
|
||||
@@ -51,20 +53,19 @@ async def test_headless_verification_error_and_qa_interceptor(vlogger) -> None:
|
||||
"""
|
||||
t1 = Ticket(id="T1", description="Task with error", status="todo", assigned_to="worker1")
|
||||
track = Track(id="track_error", description="Error Track", tickets=[t1])
|
||||
from events import AsyncEventQueue
|
||||
queue = AsyncEventQueue()
|
||||
from src.events import SyncEventQueue
|
||||
queue = SyncEventQueue()
|
||||
engine = ConductorEngine(track=track, event_queue=queue, auto_queue=True)
|
||||
# We need to simulate the tool loop inside ai_client._send_gemini (or similar)
|
||||
# Since we want to test the real tool loop and QA injection, we mock at the provider level.
|
||||
with patch("ai_client._provider", "gemini"), \
|
||||
patch("ai_client._gemini_client") as mock_genai_client, \
|
||||
patch("ai_client.confirm_and_run_callback") as mock_run, \
|
||||
patch("ai_client.run_tier4_analysis") as mock_qa, \
|
||||
patch("ai_client._ensure_gemini_client") as mock_ensure, \
|
||||
patch("ai_client._gemini_tool_declaration", return_value=None), \
|
||||
patch("multi_agent_conductor.confirm_spawn", return_value=(True, "mock_prompt", "mock_ctx")):
|
||||
with patch("src.ai_client._provider", "gemini"), \
|
||||
patch("src.ai_client._gemini_client") as mock_genai_client, \
|
||||
patch("src.ai_client.confirm_and_run_callback") as mock_run, \
|
||||
patch("src.ai_client.run_tier4_analysis", return_value="FIX: Check if path exists.") as mock_qa, \
|
||||
patch("src.ai_client._ensure_gemini_client") as mock_ensure, \
|
||||
patch("src.ai_client._gemini_tool_declaration", return_value=None), \
|
||||
patch("src.multi_agent_conductor.confirm_spawn", return_value=(True, "mock_prompt", "mock_ctx")):
|
||||
# Ensure _gemini_client is restored by the mock ensure function
|
||||
import ai_client
|
||||
|
||||
def restore_client() -> None:
|
||||
ai_client._gemini_client = mock_genai_client
|
||||
@@ -114,13 +115,12 @@ async def test_headless_verification_error_and_qa_interceptor(vlogger) -> None:
|
||||
return f"STDERR: Error: file not found\n\nQA ANALYSIS:\n{analysis}"
|
||||
return "Error: file not found"
|
||||
mock_run.side_effect = run_side_effect
|
||||
mock_qa.return_value = "FIX: Check if path exists."
|
||||
|
||||
vlogger.log_state("T1 Initial Status", "todo", t1.status)
|
||||
|
||||
# Patch engine used in test
|
||||
with patch("multi_agent_conductor.run_worker_lifecycle", wraps=multi_agent_conductor.run_worker_lifecycle):
|
||||
await engine.run()
|
||||
with patch("src.multi_agent_conductor.run_worker_lifecycle", wraps=multi_agent_conductor.run_worker_lifecycle):
|
||||
engine.run()
|
||||
|
||||
vlogger.log_state("T1 Final Status", "todo", t1.status)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user