Spaces:
Running
Running
File size: 2,771 Bytes
b2929fc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
"""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.orchestrator_factory 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()
# Mock return value of assess
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),
)
# Run
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.orchestrator_factory.settings") as mock_settings:
# Settings patch ensures factory checks pass (even though mode is explicit)
mock_settings.has_openai_key = True
with patch("src.agents.magentic_agents.OpenAIChatClient"):
# Mock agent creation to avoid real API calls during init
with (
patch("src.orchestrator_magentic.create_search_agent"),
patch("src.orchestrator_magentic.create_judge_agent"),
patch("src.orchestrator_magentic.create_hypothesis_agent"),
patch("src.orchestrator_magentic.create_report_agent"),
):
# Explicit mode="advanced" - tests the explicit path, not auto-detect
orch = create_orchestrator(mode="advanced")
assert orch is not None
|