|
|
from unittest.mock import MagicMock, patch |
|
|
|
|
|
import pytest |
|
|
|
|
|
|
|
|
agent_framework = pytest.importorskip("agent_framework") |
|
|
from agent_framework import MagenticAgentMessageEvent, MagenticFinalResultEvent |
|
|
|
|
|
from src.orchestrators.advanced import AdvancedOrchestrator as MagenticOrchestrator |
|
|
|
|
|
|
|
|
class MockChatMessage: |
|
|
def __init__(self, content): |
|
|
self.content = content |
|
|
|
|
|
@property |
|
|
def text(self): |
|
|
return self.content |
|
|
|
|
|
|
|
|
@pytest.mark.asyncio |
|
|
@pytest.mark.e2e |
|
|
async def test_advanced_mode_completes_mocked(): |
|
|
"""Verify Advanced mode runs without crashing (mocked workflow).""" |
|
|
|
|
|
|
|
|
with patch("src.orchestrators.advanced.check_magentic_requirements"): |
|
|
orchestrator = MagenticOrchestrator(max_rounds=5) |
|
|
|
|
|
|
|
|
mock_workflow = MagicMock() |
|
|
|
|
|
|
|
|
|
|
|
mock_msg_1 = MockChatMessage("Found 5 papers on PubMed") |
|
|
event1 = MagenticAgentMessageEvent(agent_id="SearchAgent", message=mock_msg_1) |
|
|
|
|
|
|
|
|
mock_result_msg = MockChatMessage("# Final Report\n\nFindings...") |
|
|
event2 = MagenticFinalResultEvent(message=mock_result_msg) |
|
|
|
|
|
async def mock_stream(task): |
|
|
yield event1 |
|
|
yield event2 |
|
|
|
|
|
mock_workflow.run_stream = mock_stream |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with ( |
|
|
patch.object(orchestrator, "_build_workflow", return_value=mock_workflow), |
|
|
patch("src.orchestrators.advanced.init_magentic_state"), |
|
|
patch.object(orchestrator, "_init_embedding_service", return_value=None), |
|
|
): |
|
|
events = [] |
|
|
async for event in orchestrator.run("test query"): |
|
|
events.append(event) |
|
|
|
|
|
|
|
|
types = [e.type for e in events] |
|
|
assert "started" in types |
|
|
assert "thinking" in types |
|
|
assert "search_complete" in types |
|
|
assert "progress" in types |
|
|
assert "complete" in types |
|
|
|
|
|
complete_event = next(e for e in events if e.type == "complete") |
|
|
assert "Final Report" in complete_event.message |
|
|
|