The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: prepare verified E2E PM tools before home isolation guards
ethernet2a30f6fee170
diff --git a/tests/e2e/core/_pm_dependencies.py b/tests/e2e/core/_pm_dependencies.pyindex ca02250defc..f8056137f32 100644--- a/tests/e2e/core/_pm_dependencies.py+++ b/tests/e2e/core/_pm_dependencies.py@@ -2,9 +2,11 @@from __future__ import annotations+import atexitimport jsonimport shutilimport sys+import tempfilefrom pathlib import Pathfrom pm.build_operations import verified_tools@@ -14,6 +16,45 @@ from pm.paths import lockfile_pathfrom pm.store import current_target+def _prepare_test_tools() -> tuple[Path, dict] | None:+ """Verify the PM store before per-test home-I/O guards, then isolate its contents."""+ test_venv = Path(sys.prefix)+ if not (test_venv / "pyvenv.cfg").is_file():+ return None+ source = Path(sys.base_prefix).resolve().parent+ if not (source / "facts.json").is_file():+ return None # A system/Nix test interpreter has no selected PM tool store.+ facts = Facts(source / "facts.json", strict=True)+ records = {name: facts.get(name) for name in ("uv", "python")}+ python = records["python"]+ if not python or (source / python["entry"]).resolve() != Path(sys.base_prefix).resolve():+ raise AssertionError(f"test interpreter is not from the selected PM store: {source}")+ target = current_target()+ lock = Lockfile(lockfile_path())+ verified_tools(("uv", "python"), source_store=source, target=target, lock=lock)++ # The source may live under the real ~/.hermes. Per-test guards must never+ # read it, nor follow a sandbox tool symlink back into it. Copy the verified+ # entries once per pytest process into the runner's throwaway scratch root.+ prepared = Path(tempfile.mkdtemp(prefix="pm-e2e-tools-"))+ try:+ for record in records.values():+ assert record is not None+ shutil.copytree(source / record["entry"], prepared / record["entry"], symlinks=True)+ (prepared / "facts.json").write_text(+ json.dumps({"schema": 1, "packages": records}), encoding="utf-8"+ )+ verified_tools(("uv", "python"), source_store=prepared, target=target, lock=lock)+ except BaseException:+ shutil.rmtree(prepared, ignore_errors=True)+ raise+ atexit.register(shutil.rmtree, prepared, ignore_errors=True)+ return prepared, records+++_PREPARED_TOOLS = _prepare_test_tools()++def select_test_dependencies(hermes_home: Path, checkout: Path) -> None:"""Point sandbox PM facts at the real test venv instead of bootstrapping a second one."""test_venv = Path(sys.prefix)@@ -32,19 +73,9 @@ def select_test_dependencies(hermes_home: Path, checkout: Path) -> None:"environment": str(environment),}}}), encoding="utf-8")- # The test venv is built from PM's pinned Python. Reuse ONLY its verified- # tool artifacts; a venv selection alone leaves plugin activation trying- # to download Python from the network inside this isolated home.- source = Path(sys.base_prefix).resolve().parent- if not (source / "facts.json").is_file():- return # A system/Nix test interpreter has no selected PM tool store.- facts = Facts(source / "facts.json", strict=True)- records = {name: facts.get(name) for name in ("uv", "python")}- python = records["python"]- if not python or (source / python["entry"]).resolve() != Path(sys.base_prefix).resolve():- raise AssertionError(f"test interpreter is not from the selected PM store: {source}")- verified_tools(("uv", "python"), source_store=source, target=current_target(),- lock=Lockfile(lockfile_path()))+ if _PREPARED_TOOLS is None:+ return+ source, records = _PREPARED_TOOLStools = hermes_home / "tools"tools.mkdir()for record in records.values():diff --git a/tests/e2e/core/mcp_plugins/test_plugin_activation.py b/tests/e2e/core/mcp_plugins/test_plugin_activation.pyindex f646bc80272..891fbe013c0 100644--- a/tests/e2e/core/mcp_plugins/test_plugin_activation.py+++ b/tests/e2e/core/mcp_plugins/test_plugin_activation.py@@ -32,10 +32,11 @@ from typing import Anyimport pytest+from tests.e2e.core._pm_dependencies import select_test_dependenciesfrom tests.e2e.core.mcp_plugins._helpers import (FINAL,+ REPO_ROOT,E2EHome,- _select_test_dependencies,apply_known,build_home as _build_home,calls_received,@@ -79,7 +80,7 @@ def _known(request: pytest.FixtureRequest) -> None:def build_home(root: Path, base_url: str, *, extra: dict[str, Any] | None = None) -> E2EHome:eh = _build_home(root, base_url, extra=extra)- _select_test_dependencies(eh)+ select_test_dependencies(eh.hermes_home, REPO_ROOT)eh.extra_env["HERMES_DISABLE_LAZY_INSTALLS"] = "1"return eh