File size: 2,752 Bytes
cd7c282
fd1472e
 
 
cd7c282
 
fd1472e
 
 
cd7c282
 
fd1472e
 
cd7c282
 
fd1472e
cd7c282
 
 
 
 
 
 
 
 
 
 
fd1472e
 
 
cd7c282
fd1472e
 
 
 
 
cd7c282
 
 
 
599a754
cd7c282
 
 
 
 
fd1472e
 
 
cd7c282
 
 
fd1472e
 
cd7c282
599a754
fd1472e
599a754
cd7c282
599a754
 
 
 
fd1472e
 
 
cd7c282
fd1472e
 
 
 
 
 
 
cd7c282
fd1472e
cd7c282
 
 
fd1472e
 
 
 
 
cd7c282
fd1472e
cd7c282
 
 
 
fd1472e
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
84
85
86
87
88
89
90
91
92
"""Tests for App domain support (SPEC-16: Unified Architecture)."""

from unittest.mock import ANY, MagicMock, patch

import pytest

from src.app import configure_orchestrator, research_agent
from src.config.domain import ResearchDomain

pytestmark = pytest.mark.unit


class TestAppDomain:
    """Test domain parameter handling in app.py."""

    @patch("src.app.create_orchestrator")
    def test_configure_orchestrator_passes_domain(self, mock_create):
        """Test domain is passed to create_orchestrator (SPEC-16: unified architecture)."""
        # Mock return value
        mock_orch = MagicMock()
        mock_create.return_value = mock_orch

        configure_orchestrator(
            use_mock=False,
            mode="advanced",  # SPEC-16: always advanced
            domain=ResearchDomain.SEXUAL_HEALTH,
        )

        mock_create.assert_called_with(
            config=ANY,
            mode="advanced",
            api_key=None,
            domain=ResearchDomain.SEXUAL_HEALTH,
        )

    @patch("src.app.create_orchestrator")
    def test_configure_orchestrator_with_api_key(self, mock_create):
        """Test API key is passed through."""
        mock_orch = MagicMock()
        mock_create.return_value = mock_orch

        configure_orchestrator(
            use_mock=False,
            user_api_key="sk-test-key",
            domain="sexual_health",
        )

        mock_create.assert_called_with(
            config=ANY,
            mode="advanced",
            api_key="sk-test-key",
            domain="sexual_health",
        )

    @pytest.mark.asyncio
    @patch("src.app.settings")
    @patch("src.app.configure_orchestrator")
    async def test_research_agent_passes_domain(self, mock_config, mock_settings):
        """Test research_agent passes domain to configure_orchestrator."""
        # Mock settings to have some state
        mock_settings.has_openai_key = False
        mock_settings.has_anthropic_key = False

        # Mock orchestrator
        mock_orch = MagicMock()

        # Mock async generator
        async def async_gen(*args):
            if False:
                yield  # Make it a generator

        mock_orch.run = async_gen
        mock_config.return_value = (mock_orch, "Test Backend")

        # SPEC-16: mode parameter removed from research_agent
        gen = research_agent(
            message="query",
            history=[],
            domain=ResearchDomain.SEXUAL_HEALTH.value,
        )

        async for _ in gen:
            pass

        # SPEC-16: mode is always "advanced"
        mock_config.assert_called_with(
            use_mock=False,
            mode="advanced",
            user_api_key=None,
            domain=ResearchDomain.SEXUAL_HEALTH.value,
        )