Skip to content

The agent that grows with you

fix: relocate pytest basetemp to a sibling of the native home, not the repo

teknium11e1e5c0fa717
diff --git a/tests/conftest.py b/tests/conftest.py
index e12d56ad0b6..0fd5ef8e693 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1247,12 +1247,15 @@ def _relocate_basetemp_outside_operator_home(config) -> None:
if not candidate.resolve().is_relative_to(native):
return
# The system temp dir may itself be inside the home (Windows TEMP under the
- # Hermes home); the repo's ignored cache dir is always outside it.
- fallback = PROJECT_ROOT / ".pytest_cache"
- safe_root = None if not Path(tempfile.gettempdir()).resolve().is_relative_to(native) else fallback
- if safe_root is not None:
- safe_root.mkdir(exist_ok=True)
+ # Hermes home). The repo is no escape either: the default install checks it
+ # out *inside* the home (~/.hermes/hermes-agent). A sibling of the native
+ # home is outside it by construction.
+ safe_root = None if not Path(tempfile.gettempdir()).resolve().is_relative_to(native) else native.parent
safe = Path(tempfile.mkdtemp(prefix="hermes-pytest-basetemp-", dir=safe_root))
+ assert not safe.resolve().is_relative_to(native), (
+ f"pytest basetemp {safe} still resolves inside the operator's Hermes home {native}; "
+ "refusing to run the suite against the live install (pass --basetemp outside it)"
+ )
factory._given_basetemp = safe
config.option.basetemp = str(safe)
diff --git a/tests/test_basetemp_isolation.py b/tests/test_basetemp_isolation.py
index 3819b4bf8ab..57cc1658701 100644
--- a/tests/test_basetemp_isolation.py
+++ b/tests/test_basetemp_isolation.py
@@ -49,3 +49,19 @@ def test_basetemp_outside_the_native_home_is_left_alone(tmp_path, monkeypatch):
assert config._tmp_path_factory._given_basetemp == given
assert config.option.basetemp == str(given)
+
+
+def test_fallback_root_escapes_a_repo_checked_out_inside_the_native_home(tmp_path, monkeypatch):
+ # Default install: repo at ~/.hermes/hermes-agent and TEMP under the home (Windows).
+ native = tmp_path / "native-home"
+ (native / "hermes-agent").mkdir(parents=True)
+ monkeypatch.setattr(hermes_constants, "_get_platform_default_hermes_home", lambda: native)
+ monkeypatch.setattr(suite_conftest, "PROJECT_ROOT", native / "hermes-agent")
+ monkeypatch.setattr(suite_conftest.tempfile, "gettempdir", lambda: str(native / "tmp"))
+ monkeypatch.delenv("PYTEST_DEBUG_TEMPROOT", raising=False)
+ config = _config_with_basetemp(None)
+
+ suite_conftest._relocate_basetemp_outside_operator_home(config)
+
+ relocated = config._tmp_path_factory._given_basetemp
+ assert relocated is not None and not relocated.resolve().is_relative_to(native.resolve())