"""A REST API must not advertise an unimplemented A2A interface — and once
implemented, the card must describe only what actually exists."""
from fastapi.testclient import TestClient
from src.core.agent_card import build_agent_card
from src.main import app


def test_a2a_card_is_unpublished_while_agent_access_is_disabled():
    client = TestClient(app)
    for method in ("GET", "HEAD"):
        assert client.request(method, "/.well-known/agent-card.json").status_code == 404


def test_agent_card_points_to_dashboard_not_mcp_or_core():
    card = build_agent_card("https://dashboard.p2hs.com", a2a_url="https://dashboard.p2hs.com/a2a")
    assert card["url"] == "https://dashboard.p2hs.com/a2a"
    assert card["preferredTransport"] == "JSONRPC"
    assert "beapipie" not in str(card)
    assert "mcp.p2hs.com" not in str(card)


def test_agent_card_skills_match_the_real_tool_catalog():
    card = build_agent_card("https://dashboard.p2hs.com", a2a_url="https://dashboard.p2hs.com/a2a")
    skill_ids = {skill["id"] for skill in card["skills"]}
    assert skill_ids == {
        "list_projects", "get_project", "list_builds", "get_build", "estimate_build",
        "create_project", "start_build", "get_operation", "list_credit_packages",
        "create_credit_checkout", "purchase_credits",
    }
    for skill in card["skills"]:
        assert skill["description"], skill["id"]


def test_agent_card_declares_oauth_security_not_a_fake_scheme():
    card = build_agent_card("https://dashboard.p2hs.com", a2a_url="https://dashboard.p2hs.com/a2a")
    scheme = card["securitySchemes"]["p2hsOAuth"]
    assert scheme["type"] == "oauth2"
    assert scheme["flows"]["authorizationCode"]["tokenUrl"] == "https://dashboard.p2hs.com/api/agent-access/token"
    assert card["capabilities"]["pushNotifications"] is False
    assert card["capabilities"]["streaming"] is False
