"""Tests for ClaudeCodeClient using Claude Agent SDK."""
import pytest
from unittest.mock import AsyncMock, patch, MagicMock
from neo_cortex.llm import ClaudeCodeClient, LLMClient


class TestClaudeCodeClient:
    def test_implements_llm_client(self):
        client = ClaudeCodeClient(model="haiku")
        assert isinstance(client, LLMClient)

    def test_name_property(self):
        client = ClaudeCodeClient(model="sonnet")
        assert client.name == "claude-code/sonnet"

    def test_default_model_is_haiku(self):
        client = ClaudeCodeClient()
        assert "haiku" in client.name

    @pytest.mark.asyncio
    async def test_call_invokes_sdk(self):
        client = ClaudeCodeClient(model="haiku")

        mock_msg = MagicMock()
        mock_msg.content = '[{"topic":"test","content":"test"}]'

        async def mock_query(*args, **kwargs):
            yield mock_msg

        with patch("neo_cortex.llm._claude_query", mock_query):
            result = await client.call("system prompt", "user text")
            assert "test" in result

    @pytest.mark.asyncio
    async def test_call_handles_sdk_error(self):
        client = ClaudeCodeClient(model="haiku")

        with patch("neo_cortex.llm._claude_query", side_effect=RuntimeError("CLI not found")):
            with pytest.raises(RuntimeError):
                await client.call("prompt", "text")

    @pytest.mark.asyncio
    async def test_close_is_noop(self):
        """Claude CLI has no persistent connection to close."""
        client = ClaudeCodeClient(model="haiku")
        await client.close()  # should not raise
