"""Test OAuth utility functions."""
import pytest
from nanobot.providers.oauth_utils import is_oauth_token, get_auth_headers


def test_is_oauth_token_detects_oat():
    """Should detect sk-ant-oat tokens as OAuth."""
    assert is_oauth_token("sk-ant-oat01-buSdhCH2XEkebW7ZQZTvGqH5EwAFh4u52LrdJhAP") is True
    assert is_oauth_token("sk-ant-api03-regularkey") is False
    assert is_oauth_token("") is False
    assert is_oauth_token(None) is False


def test_get_auth_headers_oauth():
    """OAuth tokens should use Authorization: Bearer."""
    headers = get_auth_headers("sk-ant-oat01-xxx", is_oauth=True)
    assert "Authorization" in headers
    assert headers["Authorization"] == "Bearer sk-ant-oat01-xxx"
    assert "x-api-key" not in headers
    assert headers["anthropic-beta"] == "claude-code-20250219,oauth-2025-04-20,context-management-2025-06-27"


def test_get_auth_headers_api_key():
    """Regular API keys should use x-api-key."""
    headers = get_auth_headers("sk-ant-api03-xxx", is_oauth=False)
    assert "x-api-key" in headers
    assert headers["x-api-key"] == "sk-ant-api03-xxx"
    assert "Authorization" not in headers
