from __future__ import annotations

from pathlib import Path
import re

import app


def test_app_version_matches_docker_version() -> None:
    """The backend version should match the signed off Docker release version."""

    repo_root = Path(__file__).resolve().parents[2]
    version_file = repo_root / "Docker" / "VERSION"
    expected = version_file.read_text(encoding="utf-8").strip().lstrip("v")

    assert app.__version__ == expected


def test_backend_pyproject_version_matches_docker_version() -> None:
    repo_root = Path(__file__).resolve().parents[2]
    version_file = repo_root / "Docker" / "VERSION"
    expected = version_file.read_text(encoding="utf-8").strip().lstrip("v")

    pyproject_file = repo_root / "backend" / "pyproject.toml"
    text = pyproject_file.read_text(encoding="utf-8")
    match = re.search(r"^version\s*=\s*\"([^\"]+)\"", text, re.MULTILINE)
    assert match is not None, "backend/pyproject.toml must contain a version entry"
    assert match.group(1) == expected
