File size: 1,946 Bytes
b2929fc
 
 
 
 
 
 
 
cd7c282
b2929fc
 
 
 
e82d9c9
b2929fc
 
 
 
cd7c282
e82d9c9
b2929fc
 
 
 
 
 
 
 
 
 
 
cd7c282
 
 
 
b2929fc
cd7c282
b2929fc
 
cd7c282
 
 
b2929fc
 
cd7c282
 
b2929fc
 
cd7c282
 
b2929fc
 
cd7c282
 
 
 
b2929fc
 
cd7c282
 
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
"""Unit tests for Orchestrator Factory."""

from unittest.mock import MagicMock, patch

import pytest

pytestmark = pytest.mark.unit

from src.orchestrators import create_orchestrator


@pytest.fixture
def mock_settings():
    with patch("src.orchestrators.factory.settings", autospec=True) as mock_settings:
        yield mock_settings


@pytest.fixture
def mock_advanced_cls():
    with patch("src.orchestrators.factory._get_advanced_orchestrator_class") as mock:
        # The mock returns a class (callable), which returns an instance
        mock_class = MagicMock()
        mock.return_value = mock_class
        yield mock_class


@pytest.fixture
def mock_handlers():
    return MagicMock(), MagicMock()


def test_create_orchestrator_simple_maps_to_advanced(
    mock_settings, mock_handlers, mock_advanced_cls
):
    """Test that 'simple' mode explicitly maps to AdvancedOrchestrator."""
    search, judge = mock_handlers
    # Pass handlers (they are ignored but shouldn't crash)
    orch = create_orchestrator(search_handler=search, judge_handler=judge, mode="simple")

    # Verify AdvancedOrchestrator was created
    mock_advanced_cls.assert_called_once()
    assert orch == mock_advanced_cls.return_value


def test_create_orchestrator_advanced_explicit(mock_settings, mock_handlers, mock_advanced_cls):
    """Test explicit advanced mode."""
    orch = create_orchestrator(mode="advanced")
    # verify instantiated
    mock_advanced_cls.assert_called_once()
    assert orch == mock_advanced_cls.return_value


def test_create_orchestrator_auto_advanced(mock_settings, mock_advanced_cls):
    """Test auto-detect defaults to Advanced (Unified)."""
    # Even with no keys (handled by factory internally), orchestrator factory returns Advanced
    mock_settings.has_openai_key = False  # Simulate no key

    orch = create_orchestrator()
    mock_advanced_cls.assert_called_once()
    assert orch == mock_advanced_cls.return_value