File size: 2,950 Bytes
fd1472e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
599a754
fd1472e
 
599a754
 
 
fd1472e
599a754
 
 
 
fd1472e
 
 
 
 
 
 
 
 
 
 
 
 
599a754
fd1472e
599a754
 
 
 
 
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
"""Tests for App domain support."""

from unittest.mock import ANY, MagicMock, patch

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


class TestAppDomain:
    @patch("src.app.create_orchestrator")
    @patch("src.app.MockJudgeHandler")
    def test_configure_orchestrator_passes_domain_mock_mode(self, mock_judge, mock_create):
        """Test domain is passed when using mock mode (unit test path)."""
        configure_orchestrator(use_mock=True, mode="simple", domain=ResearchDomain.SEXUAL_HEALTH)

        # MockJudgeHandler should receive domain
        mock_judge.assert_called_with(domain=ResearchDomain.SEXUAL_HEALTH)
        mock_create.assert_called_with(
            search_handler=ANY,
            judge_handler=ANY,
            config=ANY,
            mode="simple",
            api_key=None,
            domain=ResearchDomain.SEXUAL_HEALTH,
        )

    @patch.dict("os.environ", {}, clear=True)
    @patch("src.app.settings")
    @patch("src.app.create_orchestrator")
    @patch("src.app.HFInferenceJudgeHandler")
    def test_configure_orchestrator_passes_domain_free_tier(
        self, mock_hf_judge, mock_create, mock_settings
    ):
        """Test domain is passed when using free tier (no API keys)."""
        # Simulate no keys in settings
        mock_settings.has_openai_key = False
        mock_settings.has_anthropic_key = False

        configure_orchestrator(use_mock=False, mode="simple", domain=ResearchDomain.SEXUAL_HEALTH)

        # HFInferenceJudgeHandler should receive domain (no API keys = free tier)
        mock_hf_judge.assert_called_with(domain=ResearchDomain.SEXUAL_HEALTH)
        mock_create.assert_called_with(
            search_handler=ANY,
            judge_handler=ANY,
            config=ANY,
            mode="simple",
            api_key=None,
            domain=ResearchDomain.SEXUAL_HEALTH,
        )

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

        # Mock orchestrator
        mock_orch = MagicMock()
        mock_orch.run.return_value = []  # Async iterator?

        # To 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")

        # Consume the generator from research_agent
        gen = research_agent(
            message="query", history=[], mode="simple", domain=ResearchDomain.SEXUAL_HEALTH
        )

        async for _ in gen:
            pass

        mock_config.assert_called_with(
            use_mock=False, mode="simple", user_api_key=None, domain=ResearchDomain.SEXUAL_HEALTH
        )