| """Tests for app timeout and history preservation.""" |
|
|
| import os |
| from unittest.mock import MagicMock, patch |
|
|
| import pytest |
|
|
| from src.app import research_agent |
| from src.utils.models import AgentEvent |
|
|
|
|
| async def async_gen(items): |
| for item in items: |
| yield item |
|
|
|
|
| @pytest.mark.asyncio |
| async def test_complete_event_preserves_history(): |
| """ |
| Verify that a 'complete' event (like timeout) appends to the history |
| instead of replacing it. |
| """ |
| |
| mock_events = [ |
| AgentEvent(type="thinking", message="Step 1: Thinking...", iteration=0), |
| AgentEvent(type="search_complete", message="Step 2: Found data", iteration=1), |
| AgentEvent(type="complete", message="Timeout: Synthesizing...", iteration=1), |
| ] |
|
|
| |
| mock_orchestrator = MagicMock() |
| |
| mock_orchestrator.run.side_effect = lambda msg: async_gen(mock_events) |
|
|
| |
| with patch("src.app.configure_orchestrator") as mock_config: |
| mock_config.return_value = (mock_orchestrator, "Mock Backend") |
|
|
| |
| results = [] |
| async for output in research_agent("test query", [], "simple"): |
| results.append(output) |
|
|
| |
| final_output = results[-1] |
|
|
| |
| assert "Step 1: Thinking..." in final_output |
| assert "Step 2: Found data" in final_output |
| assert "Timeout: Synthesizing..." in final_output |
|
|
|
|
| @pytest.mark.asyncio |
| async def test_timeout_configurable(): |
| """Verify MAGENTIC_TIMEOUT env var is respected.""" |
| from src.utils.config import Settings |
|
|
| with patch.dict(os.environ, {"MAGENTIC_TIMEOUT": "120"}): |
| settings = Settings() |
| assert settings.magentic_timeout == 120 |
|
|