"""vSphere Implementation coverage payload tests."""

from app.vsphere.contracts.compatibility import evidence_ledger, vsphere_compatibility_payload
from app.vsphere.contracts.matrix import VERSIONS, catalog_entries_for_major
from app.vsphere.rest.coverage import catalog_entries


def test_compatibility_payload_matches_matrix() -> None:
    universe = len(catalog_entries())
    for major in VERSIONS:
        payload = vsphere_compatibility_payload(major)
        implemented = len(catalog_entries_for_major(major))
        assert payload["total_declared"] == universe
        assert payload["levels"]["implemented"]["count"] == implemented
        assert payload["levels"]["declared"]["count"] == universe
        assert payload["levels"]["gated"]["count"] == universe - implemented
        assert payload["levels"]["schema_only"]["count"] == universe - implemented
        assert payload["summary"]["coverage"] == round(implemented / universe, 4)
        assert payload["summary"]["universe_by_verb"]
        assert "GET" in payload["summary"]["by_verb"] or implemented == 0


def test_evidence_ledger_includes_levels() -> None:
    ledger = evidence_ledger(9)
    assert ledger["summary"]["implemented_methods"] == len(catalog_entries())
    assert ledger["summary"]["coverage"] == 1.0
    assert ledger["levels"]["implemented"]["count"] == ledger["summary"]["universe_methods"]
