"""Tests for marketing_intelligence.agent.orchestrator routing.""" import asyncio from unittest.mock import AsyncMock, MagicMock, patch import pytest from marketing_intelligence.agent import orchestrator class TestOrchestratorRouting: def test_unknown_backend_raises_value_error(self) -> None: with patch.object(orchestrator, "settings") as mock_settings: mock_settings.agent_backend = "openai" with pytest.raises(ValueError, match="Unknown agent_backend"): asyncio.run(orchestrator.run("task")) def test_anthropic_backend_calls_anthropic_agent(self) -> None: mock_agent = MagicMock() mock_agent.run = AsyncMock(return_value="anthropic result") with ( patch.object(orchestrator, "settings") as mock_settings, patch( "marketing_intelligence.agent.anthropic.agent.AnthropicAgent", return_value=mock_agent, ), ): mock_settings.agent_backend = "anthropic" result = asyncio.run(orchestrator.run("task", {"k": "v"}, "run1")) assert result == "anthropic result" mock_agent.run.assert_awaited_once_with("task", {"k": "v"}, "run1", None) def test_bedrock_backend_calls_bedrock_agent(self) -> None: mock_agent = MagicMock() mock_agent.run = AsyncMock(return_value="bedrock result") with ( patch.object(orchestrator, "settings") as mock_settings, patch( "marketing_intelligence.agent.bedrock.agent.BedrockAgent", return_value=mock_agent, ), ): mock_settings.agent_backend = "bedrock" result = asyncio.run(orchestrator.run("task")) assert result == "bedrock result" def test_run_sync_wraps_async(self) -> None: mock_agent = MagicMock() mock_agent.run = AsyncMock(return_value="sync result") with ( patch.object(orchestrator, "settings") as mock_settings, patch( "marketing_intelligence.agent.anthropic.agent.AnthropicAgent", return_value=mock_agent, ), ): mock_settings.agent_backend = "anthropic" result = orchestrator.run_sync("task") assert result == "sync result"