"""Smoke: the editable install resolves to this checkout's `src/`.

Background: an earlier Claude session left a git worktree at
`.claude/worktrees/doc-staleness-pass/` and ran `pip install -e .`
from inside it. The venv's `_editable_impl_mgf_hrb.pth` baked in
the worktree path. Every test in this repo for ~24 hours ran
against THAT tree's `src/`, not the main checkout's. Diagnosing
took longer than it should have — the import path was the
authoritative answer and nothing pointed at it.

This test makes the wire visible: if a future install ever points
mgf.hrb at a worktree (or a system path, or a wheel, or anywhere
not under <repo>/src/), this fails immediately with the offending
path. A contributor seeing the failure can `pip install -e .` from
the repo root to fix it.
"""

from __future__ import annotations

from pathlib import Path

import pytest

import mgf.hrb

pytestmark = pytest.mark.smoke

_REPO_ROOT = Path(__file__).resolve().parents[2]
_EXPECTED_PREFIX = _REPO_ROOT / "src" / "mgf" / "hrb"


def test_mgf_hrb_resolves_under_repo_src() -> None:
    """`mgf.hrb.__file__` must live under `<repo>/src/mgf/hrb/`.

    A worktree-shadowed install (`/.claude/worktrees/.../src/...`),
    a wheel install (`site-packages/mgf/hrb/...`), or a system
    install (`/usr/lib/...`) all fail this check. The fix is
    always `pip install -e .` (or `uv pip install -e .`) from
    the repo root.
    """
    actual = Path(mgf.hrb.__file__).resolve()
    assert actual.is_relative_to(_EXPECTED_PREFIX), (
        f"mgf.hrb is loaded from {actual}, not from "
        f"{_EXPECTED_PREFIX}. Re-point the editable install: "
        "  uv pip install -e . --python .venv/bin/python  "
        "(or `pip install -e .` if pip is on PATH). "
        "Tests against an unexpected source tree silently lie."
    )


def test_no_worktree_path_in_install() -> None:
    """Extra-belt-and-suspenders pin against the specific failure
    mode that bit us: any `.claude/worktrees/` segment in the
    import path means the install is wired to a parallel branch.
    Listed separately from the general check so the failure
    message names the actual hazard."""
    actual = Path(mgf.hrb.__file__).resolve()
    parts = actual.parts
    assert ".claude" not in parts or "worktrees" not in parts, (
        f"mgf.hrb is loaded from a Claude worktree: {actual}. "
        "This happens when `pip install -e .` was run inside a "
        "`.claude/worktrees/<name>/` checkout. Re-install from the "
        "main repo root to repair: "
        "  uv pip install -e . --python .venv/bin/python"
    )
