"""``mgf.cloud.__version__`` must equal ``pyproject.toml::project.version`` (AP-13).

``__version__`` is single-sourced from the installed package metadata, so this
guard catches version drift on EVERY push (PR-time) rather than only at tag time
via the release WF-05 check — the gap that let v0.1.1 ship with ``__version__``
frozen at 0.1.0 (REL-06).
"""

from __future__ import annotations

import tomllib
from pathlib import Path

import mgf.cloud

_REPO_ROOT = Path(__file__).resolve().parents[2]


def _pyproject_version() -> str:
    data = tomllib.loads((_REPO_ROOT / "pyproject.toml").read_text(encoding="utf-8"))
    return str(data["project"]["version"])


def test_version_matches_pyproject() -> None:
    assert mgf.cloud.__version__ == _pyproject_version(), (
        "mgf.cloud.__version__ (from installed metadata) is out of sync with "
        "pyproject.toml — reinstall the package (`uv pip install -e .`) after a "
        "version bump so the wheel metadata matches the source."
    )
