

# --- parse-helper coverage: dict-shaped responses + edge cases ---------------
import pytest
from abom.adapters.anthropic import parse, _output_text, _tokens, AnthropicAdapter


def test_parse_dict_shaped_response():
    resp = {
        "content": [{"type": "text", "text": "hi"}, {"type": "text", "text": " there"}],
        "usage": {"input_tokens": 10, "output_tokens": 5},
    }
    mc = parse("claude-3-5-sonnet", resp)
    assert mc.model == "claude-3-5-sonnet"
    assert mc.tokens == 15
    assert mc.output_sha256 is not None
    assert mc.endpoint == "api.anthropic.com"


def test_tokens_none_when_no_usage():
    assert _tokens({}) is None
    assert _tokens({"usage": {}}) is None


def test_output_text_empty_when_no_content():
    assert _output_text({}) == ""


def test_wrap_rejects_non_anthropic_client():
    class NotAClient:
        pass

    with pytest.raises(TypeError, match="messages.create"):
        AnthropicAdapter().wrap(NotAClient(), run=None)
