"""DOC-08 — PUBLIC_API.json MUST match the generator's output."""

from __future__ import annotations

import json
from pathlib import Path

from tools.generate_public_api_json import build_payload  # type: ignore[import-not-found]


def _root() -> Path:
    p = Path(__file__).resolve()
    for a in p.parents:
        if (a / "pyproject.toml").exists():
            return a
    raise RuntimeError


def test_exists() -> None:
    assert (_root() / "PUBLIC_API.json").exists()


def test_matches_generator() -> None:
    assert json.loads((_root() / "PUBLIC_API.json").read_text(encoding="utf-8")) == build_payload()
