|
|
"""End-to-End Integration Tests for Dual-Mode Architecture.""" |
|
|
|
|
|
from unittest.mock import AsyncMock, MagicMock, patch |
|
|
|
|
|
import pytest |
|
|
|
|
|
pytestmark = [pytest.mark.integration, pytest.mark.slow] |
|
|
|
|
|
from src.orchestrators import create_orchestrator |
|
|
from src.utils.models import Citation, Evidence, OrchestratorConfig |
|
|
|
|
|
|
|
|
@pytest.fixture |
|
|
def mock_search_handler(): |
|
|
handler = MagicMock() |
|
|
handler.execute = AsyncMock( |
|
|
return_value=[ |
|
|
Evidence( |
|
|
citation=Citation( |
|
|
title="Test Paper", url="http://test", date="2024", source="pubmed" |
|
|
), |
|
|
content="Metformin increases lifespan in mice.", |
|
|
) |
|
|
] |
|
|
) |
|
|
return handler |
|
|
|
|
|
|
|
|
@pytest.fixture |
|
|
def mock_judge_handler(): |
|
|
handler = MagicMock() |
|
|
|
|
|
assessment = MagicMock() |
|
|
assessment.sufficient = True |
|
|
assessment.recommendation = "synthesize" |
|
|
handler.assess = AsyncMock(return_value=assessment) |
|
|
return handler |
|
|
|
|
|
|
|
|
@pytest.mark.asyncio |
|
|
async def test_simple_mode_e2e(mock_search_handler, mock_judge_handler): |
|
|
"""Test Simple Mode Orchestration flow.""" |
|
|
orch = create_orchestrator( |
|
|
search_handler=mock_search_handler, |
|
|
judge_handler=mock_judge_handler, |
|
|
mode="simple", |
|
|
config=OrchestratorConfig(max_iterations=1), |
|
|
) |
|
|
|
|
|
|
|
|
results = [] |
|
|
async for event in orch.run("Test query"): |
|
|
results.append(event) |
|
|
|
|
|
assert len(results) > 0 |
|
|
assert mock_search_handler.execute.called |
|
|
assert mock_judge_handler.assess.called |
|
|
|
|
|
|
|
|
@pytest.mark.asyncio |
|
|
async def test_advanced_mode_explicit_instantiation(): |
|
|
"""Test explicit Advanced Mode instantiation (not auto-detect). |
|
|
|
|
|
This tests the explicit mode="advanced" path, verifying that |
|
|
MagenticOrchestrator can be instantiated when explicitly requested. |
|
|
The settings patch ensures any internal checks pass. |
|
|
""" |
|
|
with patch("src.orchestrators.factory.settings") as mock_settings: |
|
|
|
|
|
mock_settings.has_openai_key = True |
|
|
|
|
|
with patch("src.agents.magentic_agents.OpenAIChatClient"): |
|
|
|
|
|
with ( |
|
|
patch("src.orchestrators.advanced.check_magentic_requirements"), |
|
|
patch("src.orchestrators.advanced.create_search_agent"), |
|
|
patch("src.orchestrators.advanced.create_judge_agent"), |
|
|
patch("src.orchestrators.advanced.create_hypothesis_agent"), |
|
|
patch("src.orchestrators.advanced.create_report_agent"), |
|
|
): |
|
|
|
|
|
orch = create_orchestrator(mode="advanced") |
|
|
assert orch is not None |
|
|
|