"""PUBLIC_API.json pin (DOC-08): the committed companion MUST match the live ``__all__``."""

from __future__ import annotations

import json
from pathlib import Path

import mgf.fed

_PUBLIC_API_JSON = Path(__file__).resolve().parents[2] / "PUBLIC_API.json"


def test_public_api_json_matches_all() -> None:
    data = json.loads(_PUBLIC_API_JSON.read_text(encoding="utf-8"))
    live = [*sorted(n for n in mgf.fed.__all__ if n != "__version__"), "__version__"]
    assert sorted(data["modules"]["mgf.fed"]) == sorted(live), (
        "PUBLIC_API.json is out of sync with mgf.fed.__all__ — "
        "regenerate: `python tools/generate_public_api_json.py`"
    )


def test_public_api_json_version_matches_package() -> None:
    data = json.loads(_PUBLIC_API_JSON.read_text(encoding="utf-8"))
    assert data["__version__"] == mgf.fed.__version__
