Skip to content

The agent that grows with you

fix: plugin-host profile extraction no longer imports hermes_cli from the launch directory

Teknium4d0d67ba38f1
diff --git a/hermes_cli/plugin_host_profiles.py b/hermes_cli/plugin_host_profiles.py
index 16df810ec84..15ac251803a 100644
--- a/hermes_cli/plugin_host_profiles.py
+++ b/hermes_cli/plugin_host_profiles.py
@@ -86,11 +86,13 @@ def _extract(plugin_dir: Path, module_name: str) -> dict[str, Any]:
env.update(HOME=str(Path.home()), USERPROFILE=str(Path.home()), HERMES_HOME=str(get_hermes_home()),
PYTHONPATH=repo_root,
**{HOST_PROCESS_ENV: "1"})
- argv = [*host_launcher(), sys.executable, "-m", "hermes_cli.plugin_host_child", "--extract-profiles",
+ # -P and a trusted cwd: ``-m`` otherwise puts the launch directory ahead of PYTHONPATH, so a
+ # ``hermes_cli/`` package in the directory Hermes was started from would run instead of ours.
+ argv = [*host_launcher(), sys.executable, "-P", "-m", "hermes_cli.plugin_host_child", "--extract-profiles",
str(plugin_dir), module_name]
try:
done = subprocess.run(argv, stdin=subprocess.DEVNULL, capture_output=True, env=env,
- timeout=_EXTRACT_TIMEOUT_SECS, check=False)
+ cwd=str(get_hermes_home()), timeout=_EXTRACT_TIMEOUT_SECS, check=False)
except (OSError, subprocess.TimeoutExpired) as exc:
return {"error": f"profile extraction failed: {exc}"}
try:
diff --git a/tests/hermes_cli/test_plugin_host_profiles_launch_dir.py b/tests/hermes_cli/test_plugin_host_profiles_launch_dir.py
new file mode 100644
index 00000000000..5e849cf84bf
--- /dev/null
+++ b/tests/hermes_cli/test_plugin_host_profiles_launch_dir.py
@@ -0,0 +1,42 @@
+"""Plugin-host profile extraction runs the Hermes tree's code, never a same-named package in the cwd."""
+
+import json
+
+import pytest
+
+from hermes_cli.plugin_host_profiles import load_hosted_profiles
+
+PROVIDER_PLUGIN = '''
+from providers import register_provider
+from providers.base import ProviderProfile
+
+register_provider(ProviderProfile(name="cwdprobe", base_url="https://cwdprobe.example/v1"))
+'''
+
+# A launch directory (e.g. a cloned repository) that happens to contain a ``hermes_cli`` package.
+SHADOW_INIT = '''
+from pathlib import Path
+Path(__file__).resolve().parents[1].joinpath("shadow-imported.txt").write_text("imported")
+'''
+SHADOW_CHILD = 'import json\nprint(json.dumps({"profiles": []}))\n'
+
+
[email protected]("any") # a real child interpreter: sys.path rules are per-OS
+def test_profile_extraction_ignores_a_hermes_cli_package_in_the_launch_directory(tmp_path, monkeypatch):
+ home = tmp_path / "hermes-home"
+ plugin_dir = home / "plugins" / "model-providers" / "cwdprobe"
+ plugin_dir.mkdir(parents=True)
+ (plugin_dir / "__init__.py").write_text(PROVIDER_PLUGIN, encoding="utf-8")
+ (home / "config.yaml").write_text(json.dumps({"plugins": {"isolation": "host"}}), encoding="utf-8")
+ launch_dir = tmp_path / "cloned-repo"
+ (launch_dir / "hermes_cli").mkdir(parents=True)
+ (launch_dir / "hermes_cli" / "__init__.py").write_text(SHADOW_INIT, encoding="utf-8")
+ (launch_dir / "hermes_cli" / "plugin_host_child.py").write_text(SHADOW_CHILD, encoding="utf-8")
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ monkeypatch.chdir(launch_dir)
+
+ profiles = load_hosted_profiles(plugin_dir, "_hermes_test_cwdprobe")
+
+ assert not (launch_dir / "shadow-imported.txt").exists()
+ assert [p.name for p in profiles] == ["cwdprobe"]
+ assert profiles[0].base_url == "https://cwdprobe.example/v1"