"""Tests for native tool support in AnthropicOAuthProvider."""

from nanobot.providers.anthropic_oauth import AnthropicOAuthProvider


def test_convert_tools_passes_through_native_tools():
    """Test that native tool format is passed through unchanged."""
    provider = AnthropicOAuthProvider(oauth_token="test", thinking_budget=0)

    tools = [
        {
            "type": "bash_20250124",
            "name": "bash"
        }
    ]

    result = provider._convert_tools_to_anthropic(tools)
    assert len(result) == 1
    assert result[0]["type"] == "bash_20250124"
    assert result[0]["name"] == "bash"


def test_convert_tools_handles_mixed_tool_types():
    """Test conversion of both function and native tools."""
    provider = AnthropicOAuthProvider(oauth_token="test", thinking_budget=0)

    tools = [
        {
            "type": "function",
            "function": {
                "name": "custom_tool",
                "description": "A custom tool",
                "parameters": {"type": "object", "properties": {"arg": {"type": "string"}}}
            }
        },
        {
            "type": "bash_20250124",
            "name": "bash"
        }
    ]

    result = provider._convert_tools_to_anthropic(tools)
    assert len(result) == 2

    # Function tool gets converted
    assert result[0]["name"] == "custom_tool"
    assert result[0]["description"] == "A custom tool"
    assert "input_schema" in result[0]

    # Native tool passed through
    assert result[1]["type"] == "bash_20250124"
    assert result[1]["name"] == "bash"


def test_convert_tools_preserves_function_tool_conversion():
    """Test that existing function tool conversion still works."""
    provider = AnthropicOAuthProvider(oauth_token="test", thinking_budget=0)

    tools = [
        {
            "type": "function",
            "function": {
                "name": "test",
                "description": "desc",
                "parameters": {"type": "object"}
            }
        }
    ]

    result = provider._convert_tools_to_anthropic(tools)
    assert len(result) == 1
    assert result[0]["name"] == "test"
    assert result[0]["description"] == "desc"
    assert result[0]["input_schema"] == {"type": "object"}
