Skip to content

The agent that grows with you

fix(dashboard): use current PM provider admission contracts

ethernetdb9112a1fc80
diff --git a/hermes_cli/web_routers/memory_providers.py b/hermes_cli/web_routers/memory_providers.py
index c42f7ffe373..0234c05957c 100644
--- a/hermes_cli/web_routers/memory_providers.py
+++ b/hermes_cli/web_routers/memory_providers.py
@@ -341,40 +341,24 @@ def _install_memory_provider_pip_dependencies(name: str, dependencies: List[str]
if not dependencies:
return []
return [_command_result(kind="pip", name=", ".join(dependencies), status="already_installed")]
- # Route through pm's venv sync — the ONE install authority (uv.lock owns the
- # pins; no pip against sys.executable, and tools.lazy_deps is deleted).
- # Extras come from the existing ``_provider_extras`` owner: the declared
- # plugin.yaml ``extra:`` — or, for legacy third-party declared python
- # dependencies, it materializes the specs into a generated pyproject and
- # admits the provider dir into the workspace union BEFORE the post-config
- # selection; one sync then carries the deps.
+ # Setup precedes config selection. Include the candidate without dropping
+ # active providers; PM resolves legacy declarations and pyprojects alike.
target = ", ".join(missing) or extra
command = "hermes pm install"
try:
- from hermes_cli.memory_setup import _provider_extras
+ from hermes_cli.plugins_admission import candidate_member_dirs
+ from pm.workspace import _is_member_candidate
from plugins.memory import find_provider_dir
plugin_dir = find_provider_dir(name)
- extras = _provider_extras(name, manifest, plugin_dir=plugin_dir)
- if extras:
- pm.sync_venv(extras, explicit=True)
- elif plugin_dir is not None and any(
- manifest.get(k) for k in ("pip_dependencies", "python_dependencies")
- ):
- # Legacy declared deps with no own extra: admit the provider dir
- # into the workspace union (materialize is idempotent; it also
- # covers the python_dependencies key _provider_extras doesn't
- # read), then one sync carries the deps.
- from pm.workspace import enabled_member_dirs
-
- members = enabled_member_dirs()
- candidate = Path(plugin_dir)
- pm.sync_venv(explicit=True, plugin_dirs=members + ([candidate] if candidate not in members else []))
- else:
+ member = plugin_dir is not None and _is_member_candidate(plugin_dir)
+ if not extra and not member:
return [_command_result(
kind="pip", name=target, status="failed", command=command,
error="no declared extra and no plugin directory to materialize declared dependencies from",
)]
+ inputs = {"plugin_dirs": lambda: candidate_member_dirs((), extra_dirs=[plugin_dir])} if member else {}
+ pm.sync_venv([extra] if extra else None, explicit=True, **inputs)
except Exception as exc:
return [_command_result(kind="pip", name=target, status="failed", command=command, error=str(exc))]
still_missing = [dep for dep in missing if not _dependency_importable(dep)]
diff --git a/tests/hermes_cli/test_web_memory_provider_setup_install.py b/tests/hermes_cli/test_web_memory_provider_setup_install.py
index 99a6651a9a3..b26b6acb85a 100644
--- a/tests/hermes_cli/test_web_memory_provider_setup_install.py
+++ b/tests/hermes_cli/test_web_memory_provider_setup_install.py
@@ -7,6 +7,10 @@ can't see a fresh install."""
from types import SimpleNamespace
from pathlib import Path
from unittest.mock import MagicMock
+import json
+import shutil
+import subprocess
+import sys
import pytest
@@ -48,7 +52,7 @@ def routed(monkeypatch):
monkeypatch.setattr(pm, "available", lambda extra: extra in state.importable)
def fake_sync_venv(extras=None, *, explicit=False, plugin_dirs=None):
state.sync_calls.append((extras, explicit))
- state.materialized.extend(plugin_dirs or [])
+ state.materialized.extend(plugin_dirs() if callable(plugin_dirs) else plugin_dirs or [])
if state.sync_error:
raise state.sync_error
# A successful sync makes freshly installed dists importable in-process.
@@ -101,17 +105,23 @@ class TestDeclaredExtraRouting:
class TestLegacyPythonDependencies:
- def test_third_party_python_dependencies_bridge(self, routed, tmp_path):
+ @pytest.mark.parametrize("extra", [None, "mem0"])
+ def test_third_party_python_dependencies_preserve_active_union(self, routed, tmp_path, monkeypatch, extra):
routed.manifest = {"python_dependencies": ["freshpkg"]}
+ if extra:
+ routed.manifest["extra"] = extra
routed.plugin_dir = tmp_path / "external-provider"
routed.plugin_dir.mkdir()
(routed.plugin_dir / "plugin.yaml").write_text("name: ext\npython_dependencies: [freshpkg]\n")
routed.importable = set()
+ active = tmp_path / "active-provider"
+ active.mkdir()
+ monkeypatch.setattr("pm.workspace.enabled_member_dirs", lambda **kwargs: [active])
rows = mp._install_memory_provider_pip_dependencies("ext", ["freshpkg"])
- assert routed.materialized == [routed.plugin_dir]
- assert routed.sync_calls == [(None, True)]
+ assert routed.materialized == [active, routed.plugin_dir]
+ assert routed.sync_calls == [([extra] if extra else None, True)]
assert rows[0]["status"] == "installed"
def test_legacy_specs_without_plugin_dir_fail_honestly(self, routed):
@@ -153,3 +163,56 @@ class TestRestartTruthfulness:
result = mp._install_memory_provider_setup("mem0")
assert result["ok"] is True
+
+
+def test_dashboard_admits_real_provider_union_and_keeps_selection_on_failure(tmp_path, monkeypatch):
+ import pm
+ from hermes_constants import venv_python_path
+ from hermes_cli.runtime_paths import selected_venv
+ from tests.pm.test_workspace_build_inputs import _wheel
+
+ uv = shutil.which("uv")
+ assert uv, "real PM admission test requires uv"
+ core, home, wheels = (tmp_path / name for name in ("core", "home", "wheels"))
+ for directory in (core, home, wheels):
+ directory.mkdir()
+ for name in ("existing_dep", "provider_dep"):
+ _wheel(wheels, name, "1.0")
+ (core / "pyproject.toml").write_text(
+ '[project]\nname="core"\nversion="1"\nrequires-python=">=3.14"\n'
+ '[tool.uv]\npackage=false\nno-index=true\n'
+ f'find-links=[{json.dumps(wheels.as_posix())}]\n')
+ incumbent, candidate = (home / "plugins" / name for name in ("incumbent", "candidate"))
+ for directory in (incumbent, candidate):
+ directory.mkdir(parents=True)
+ (incumbent / "plugin.yaml").write_text('name: incumbent\npython_dependencies: ["existing_dep==1.0"]\n')
+ manifest = candidate / "plugin.yaml"
+ manifest.write_text('name: candidate\npython_dependencies: ["provider_dep==1.0", "provider_dep==2.0"]\n')
+ config = home / "config.yaml"
+ config.write_text('plugins:\n enabled: [incumbent]\n')
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ monkeypatch.setenv("HERMES_RUNTIME_DIR", str(tmp_path / "tools"))
+ monkeypatch.setattr("pm.paths.repo_root", lambda: core)
+ monkeypatch.setattr("pm._uv._toolchain", lambda **kwargs: (Path(uv), Path(sys.executable)))
+ monkeypatch.setattr("pm.client.is_runtime", lambda: True)
+ monkeypatch.setattr("plugins.memory.find_provider_dir", lambda name: candidate)
+ monkeypatch.setattr(mp, "_memory_provider_manifest", lambda name: {"python_dependencies": ["provider_dep"]})
+ monkeypatch.setattr(mp, "_dependency_importable", lambda dep: False)
+ pm.lock_project(core, explicit=True, offline=True)
+ pm.sync_venv(explicit=True)
+ original = selected_venv(core)
+ original_config = config.read_bytes()
+
+ failed = mp._install_memory_provider_pip_dependencies("candidate", ["provider_dep"])
+ assert failed[0]["status"] == "failed"
+ assert selected_venv(core) == original
+ assert config.read_bytes() == original_config
+
+ manifest.write_text('name: candidate\npython_dependencies: ["provider_dep==1.0"]\n')
+ success = mp._install_memory_provider_pip_dependencies("candidate", ["provider_dep"])
+ assert success[0]["status"] == "restart_required", success
+ python = venv_python_path(selected_venv(core))
+ result = subprocess.run([str(python), "-I", "-c", "import existing_dep, provider_dep; print('both')"],
+ check=True, capture_output=True, text=True, timeout=30)
+ assert result.stdout.strip() == "both"
+ assert config.read_bytes() == original_config