"""Resolve the interpreter a project's tests must run under.

A project's tests carry that project's own test-deps *and* its ``pyproject``
pins (``minversion`` &c.), so they can only be collected or run with the
project's own ``.venv`` interpreter — never whatever runs the warden/testctl.
testctl in particular is installed as an isolated ``uv`` tool and doesn't even
have pytest on its interpreter, so enumerating with ``sys.executable`` yields a
silent, empty catalog.

Preferring ``<root>/.venv`` mirrors mtest's ``_find_pytest_cmd`` and the warden
runner, so the **catalog lists exactly what a warden run will execute** — the
two can never drift onto different interpreters.
"""

from __future__ import annotations

import sys
from pathlib import Path


def project_python(project_root: str | Path) -> str:
    """The project's own venv interpreter if present, else the current one."""
    venv_py = Path(project_root) / ".venv" / "bin" / "python"
    return str(venv_py) if venv_py.exists() else sys.executable


def pytest_cmd(project_root: str | Path) -> list[str]:
    """``python -m pytest`` under the project's interpreter (see module doc)."""
    return [project_python(project_root), "-m", "pytest"]
