"""Pin `pyproject.toml::version` to `__init__.py::__version__`.

Mirrors mgf-common's equivalent test
(`tests/unit/test_version_in_sync.py`). Caught a real bug in
0.1.3: `__version__` was the literal `"0.1.0"` for all three
prior releases (0.1.0, 0.1.1, 0.1.2) because only pyproject.toml
got bumped. The wheel's METADATA reported the right version (it
reads from pyproject) but runtime introspection reported `0.1.0`
for every release.

This test fails loudly when only one side gets bumped. Future
releases must bump both in the same commit.
"""

from __future__ import annotations

import tomllib
from pathlib import Path

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


def test_pyproject_version_matches_dunder() -> None:
    pyproject = _REPO_ROOT / "pyproject.toml"
    assert pyproject.is_file(), f"pyproject.toml not found at {pyproject}"
    with pyproject.open("rb") as fh:
        data = tomllib.load(fh)
    pyproject_version = data["project"]["version"]

    import mgf.test_supervisor

    runtime_version = mgf.test_supervisor.__version__

    assert pyproject_version == runtime_version, (
        f"version drift: pyproject says {pyproject_version!r} but "
        f"`mgf.test_supervisor.__version__` says {runtime_version!r}. "
        f"Bump both in the same commit. Bug history: 0.1.0..0.1.2 "
        f"all shipped with __version__ = '0.1.0' because only "
        f"pyproject got bumped each cycle; 0.1.3 added this test "
        f"to prevent recurrence."
    )
