from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]


def test_gitignore_covers_runtime_and_local_artifacts():
    text = (ROOT / ".gitignore").read_text(encoding="utf-8")
    required = [
        "__pycache__/",
        ".venv/",
        ".pytest_cache/",
        ".env.*",
        "!.env.example",
        "settings/",
        "hockey_data/snapshots/",
        "*.log",
        "*.zip",
        "*.sqlite3",
        ".vscode/",
        ".idea/",
        "BUILD[0-9]*.md",
    ]
    for entry in required:
        assert entry in text


def test_runtime_has_hockey_account_logout_button_and_handler():
    html = (ROOT / "ui_builder/static/index.html").read_text(encoding="utf-8")
    js = (ROOT / "ui_builder/static/app.js").read_text(encoding="utf-8")
    auth_router = (ROOT / "hockey_data/auth_router.py").read_text(encoding="utf-8")

    assert 'id="runtimeLogoutBtn"' in html
    assert "Выйти из аккаунта" in html
    assert "async function logoutHockeyAccount()" in js
    assert 'fetch("/logout"' in js
    assert 'el.runtimeLogoutBtn?.addEventListener("click", logoutHockeyAccount)' in js
    assert '@router.post("/logout"' in auth_router


def test_build_version_bumped():
    app = (ROOT / "app.py").read_text(encoding="utf-8")
    assert 'BUILD_VERSION = "2026.08.19.22"' in app
