"""Tests for unified LLM wiring — distiller uses create_client()."""
import os
import importlib
from unittest.mock import patch, MagicMock


class TestLLMWiring:
    def test_distiller_created_with_llm_client(self):
        """Distiller(llm_client) — accepts any LLMClient."""
        from neo_cortex.distiller import Distiller
        from neo_cortex.llm import LLMClient
        mock_llm = MagicMock(spec=LLMClient)
        mock_llm.name = "gemini/gemini-2.0-flash"
        d = Distiller(mock_llm)
        assert d._llm is mock_llm

    def test_create_client_openai_compatible(self):
        """create_client('openai-compatible') should return OpenAICompatibleClient."""
        from neo_cortex.llm import OpenAICompatibleClient
        with patch.dict(os.environ, {
            'LLM_BASE_URL': 'http://localhost:11434/v1',
            'LLM_MODEL': 'llama3.2',
        }):
            from neo_cortex import config
            importlib.reload(config)
            from neo_cortex.llm import create_client
            client = create_client("openai-compatible")
            assert isinstance(client, OpenAICompatibleClient)

    def test_create_client_default_still_gemini(self):
        """Default provider should still be gemini."""
        with patch.dict(os.environ, {'GEMINI_API_KEY': 'test-key'}):
            from neo_cortex import config
            importlib.reload(config)
            from neo_cortex.llm import create_client, GeminiClient
            client = create_client()
            assert isinstance(client, GeminiClient)
