From c0176041027fc65d8f40e9954646b2373bdf08eb Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Fri, 18 Sep 2026 23:43:15 -0700 Subject: [PATCH] test(update): venv-holder live E2E spawns the foreign python from outside the venv Since 7a94b1fbf77 project_venv_dir resolves .venv, and the wine2e runner's `uv run` interpreter lives in the checkout's .venv, so a sys.executable child is a venv holder by design and test_foreign_python_not_detected failed on every wine2e push (baseline run 35427256445 on origin/main). Use the base interpreter the venv was created from as the foreign python; skip when the runner has none outside the venv. --- .../test_venv_holder_windows_live.py | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/hermes_cli/test_venv_holder_windows_live.py b/tests/hermes_cli/test_venv_holder_windows_live.py index b3e7c209c0..749e4020b4 100644 --- a/tests/hermes_cli/test_venv_holder_windows_live.py +++ b/tests/hermes_cli/test_venv_holder_windows_live.py @@ -40,7 +40,7 @@ pytestmark = [ PROJECT_ROOT = Path(__file__).resolve().parents[2] -def _spawn(args: list[str], cwd: Path | None = None) -> subprocess.Popen: +def _spawn(args: list[str], cwd: Path | None = None, python: str | None = None) -> subprocess.Popen: """Spawn a real sleeper process whose argv carries the given tail. ``python -c "sleep" `` — the tail is inert data to the child @@ -48,7 +48,7 @@ def _spawn(args: list[str], cwd: Path | None = None) -> subprocess.Popen: code classifies on. """ proc = subprocess.Popen( - [sys.executable, "-c", "import time; time.sleep(300)", *args], + [python or sys.executable, "-c", "import time; time.sleep(300)", *args], cwd=str(cwd or PROJECT_ROOT), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, @@ -89,12 +89,26 @@ class TestDetection: _kill(proc) def test_foreign_python_not_detected(self): - """A python process with no Hermes argv and cwd OUTSIDE the install - must not be reported as a holder.""" + """A python process with no Hermes argv, cwd OUTSIDE the install AND an + interpreter outside the project venv must not be reported as a holder. + + ``sys.executable`` is the wrong sleeper here: the runner's ``uv run`` interpreter + lives in the checkout's ``.venv``, which ``project_venv_dir`` resolves since + 7a94b1fbf77, so a ``sys.executable`` child IS a venv holder by design. The base + interpreter the venv was created from is the foreign python.""" import tempfile + from hermes_constants import project_venv_dir + + base = getattr(sys, "_base_executable", None) or sys.executable + venv_dir = project_venv_dir(PROJECT_ROOT) + if venv_dir is not None and str(Path(base).resolve()).lower().startswith( + str(venv_dir.resolve()).lower() + ): + pytest.skip("no interpreter outside the project venv available on this runner") + outside = Path(tempfile.mkdtemp()) - proc = _spawn(["totally", "unrelated"], cwd=outside) + proc = _spawn(["totally", "unrelated"], cwd=outside, python=base) try: pids = [pid for pid, _, _ in _detect()] assert proc.pid not in pids