Skip to content

The agent that grows with you

test: select verified PM tools for isolated plugin activation

ethernet6e27b7fbca26
diff --git a/tests/e2e/core/_pm_dependencies.py b/tests/e2e/core/_pm_dependencies.py
index 87bea0eaf56..ca02250defc 100644
--- a/tests/e2e/core/_pm_dependencies.py
+++ b/tests/e2e/core/_pm_dependencies.py
@@ -7,7 +7,11 @@ import shutil
import sys
from pathlib import Path
+from pm.build_operations import verified_tools
from pm.environments import install_key, site_packages
+from pm.lock import Facts, Lockfile
+from pm.paths import lockfile_path
+from pm.store import current_target
def select_test_dependencies(hermes_home: Path, checkout: Path) -> None:
@@ -24,6 +28,27 @@ def select_test_dependencies(hermes_home: Path, checkout: Path) -> None:
target = environment / selected.relative_to(test_venv)
target.parent.mkdir(parents=True)
target.symlink_to(selected, target_is_directory=True)
- (state / "facts.json").write_text(json.dumps({"packages": {"venv": {
+ (state / "facts.json").write_text(json.dumps({"schema": 1, "packages": {"venv": {
"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()))
+ tools = hermes_home / "tools"
+ tools.mkdir()
+ for record in records.values():
+ assert record is not None
+ entry = record["entry"]
+ (tools / entry).symlink_to(source / entry, target_is_directory=True)
+ (tools / "facts.json").write_text(json.dumps({"schema": 1, "packages": records}), encoding="utf-8")
diff --git a/tests/e2e/core/mcp_plugins/test_plugin_activation.py b/tests/e2e/core/mcp_plugins/test_plugin_activation.py
index 28cfeb03a18..f646bc80272 100644
--- a/tests/e2e/core/mcp_plugins/test_plugin_activation.py
+++ b/tests/e2e/core/mcp_plugins/test_plugin_activation.py
@@ -34,9 +34,10 @@ import pytest
from tests.e2e.core.mcp_plugins._helpers import (
FINAL,
+ E2EHome,
_select_test_dependencies,
apply_known,
- build_home,
+ build_home as _build_home,
calls_received,
inbound,
provider,
@@ -76,6 +77,13 @@ def _known(request: pytest.FixtureRequest) -> None:
apply_known(request, KNOWN)
+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)
+ eh.extra_env["HERMES_DISABLE_LAZY_INSTALLS"] = "1"
+ return eh
+
+
PLUGIN = "e2eplug"
SERVER = "plug"
PLUG_TOOL = tool_name(SERVER, "ro_probe")
@@ -118,6 +126,16 @@ def _toggle_on(host, key: str) -> list[dict[str, Any]]:
return ((result.get("activation") or {}).get("live_now") or {}).get("mcp_servers") or []
+def test_plugin_sandbox_selects_real_pm_tools_offline(tmp_path: Path) -> None:
+ """The same isolated home used by activation can resolve PM's pinned toolchain without downloads."""
+ eh = build_home(tmp_path, "http://127.0.0.1:1")
+ child = subprocess.run([sys.executable, "-c",
+ "from pm._uv import _toolchain; assert _toolchain(realize=False) is not None"],
+ env=eh.env({"HERMES_DISABLE_LAZY_INSTALLS": "1"}), cwd=eh.project,
+ capture_output=True, text=True, timeout=30)
+ assert child.returncode == 0, child.stderr
+
+
# 1. live activation in an open chat ------------------------------------------------------------
@@ -251,8 +269,6 @@ def name_collision(tmp_path_factory: pytest.TempPathFactory) -> dict[str, Any]:
root = tmp_path_factory.mktemp("name_collision")
with provider(script((tool_name("srv", "ro_probe"), {"nonce": "dup"}))) as srv:
eh = build_home(root, srv.base_url, extra={"plugins": {"enabled": ["foo"]}})
- _select_test_dependencies(eh)
- eh.extra_env["HERMES_DISABLE_LAZY_INSTALLS"] = "1"
live = write_portable_plugin(eh, "foo", {"srv": portable_stdio(
root / "live.jsonl", eh.tag, MCPE2E_CANARY="CANARY-LIVE")}, name="foo", version="2.0.0")
backup = write_portable_plugin(eh, "foo.bak-x", {"srv": portable_stdio(