Skip to content

The agent that grows with you

test: the home-I/O guard exempts the PM generation around the running venv

Teknium0c7eade36f9e
diff --git a/tests/hermes_cli/test_real_home_tripwire.py b/tests/hermes_cli/test_real_home_tripwire.py
index 24680c199b5..8bbcafc4b38 100644
--- a/tests/hermes_cli/test_real_home_tripwire.py
+++ b/tests/hermes_cli/test_real_home_tripwire.py
@@ -216,6 +216,21 @@ def test_checkout_inside_a_guarded_root_is_not_hermes_state():
guard.check(PROJECT_ROOT.parent / "config.yaml")
[email protected]("kind", ["environments", "test-environment"])
+def test_pm_generation_dir_around_the_running_venv_is_the_interpreter(tmp_path, kind):
+ """scripts/run_tests.sh runs ``<home>/installs/<key>/<kind>/<gen>/venv`` with HOME pointed at the
+ run's fake home, so that venv sits under the guarded root. `hermes update` probes
+ ``<venv>/../hermes_cli/main.py`` (update_owning_install) and must not trip the guard."""
+ from tests.home_io_guard import _pm_generation_dirs
+
+ generation = tmp_path / ".hermes" / "installs" / "0123456789abcdef" / kind / "gen-1"
+ venv = generation / "venv"
+ venv.mkdir(parents=True)
+ assert _pm_generation_dirs([venv]) == {generation.resolve()}
+ # Only a generation venv: a checkout's .venv or a venv elsewhere adds nothing new.
+ assert _pm_generation_dirs([tmp_path / "checkout" / ".venv", tmp_path / "other" / "venv"]) == set()
+
+
def test_hermes_exported_scratch_tmp_is_not_the_test_temp_root(tmp_path):
"""A Hermes-launched shell hands pytest TMPDIR=<home>/cache/scratch (tagged by
HERMES_SCRATCH_DIR). With that home guarded, honoring it would put the session
diff --git a/tests/home_io_guard.py b/tests/home_io_guard.py
index 660939a18b6..6f0b7384ac0 100644
--- a/tests/home_io_guard.py
+++ b/tests/home_io_guard.py
@@ -11,6 +11,18 @@ import sqlite3
import sys
import threading
+
+def _pm_generation_dirs(prefixes) -> set[Path]:
+ """The PM generation dir (``<installs>/<key>/{environments,test-environment}/<gen>``) around
+ each prefix that is a generation's ``venv``."""
+ found = set()
+ for prefix in prefixes:
+ venv = Path(prefix).resolve()
+ if venv.name in ("venv", ".venv") and venv.parent.parent.name in ("environments", "test-environment"):
+ found.add(venv.parent)
+ return found
+
+
_INTERPRETER_PREFIXES = tuple({
Path(p).resolve() for p in (sys.prefix, sys.base_prefix, sys.exec_prefix, sys.base_exec_prefix)
} | {
@@ -18,6 +30,12 @@ _INTERPRETER_PREFIXES = tuple({
# whose site-packages sits under the (real) Hermes home; third-party imports from it are the
# interpreter's installation, not Hermes state.
Path(p).resolve() for p in sys.path if p and Path(p).name in ("site-packages", "dist-packages")
+} | {
+ # scripts/run_tests.sh runs a PM generation venv (<installs>/<key>/{environments,test-environment}
+ # /<gen>/venv) that sits under the home whenever HOME is the run's fake home. The generation dir
+ # around the venv is that interpreter's installation too: `hermes update` probes
+ # <venv>/../hermes_cli/main.py to find the checkout owning its venv (update_owning_install).
+ *_pm_generation_dirs((sys.prefix, sys.exec_prefix)),
} | {
# The default install checks the repo out INSIDE the home (install.sh:
# INSTALL_DIR=$HERMES_HOME/hermes-agent). Reading test data, sources for tracebacks, or the