The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(pm): drop a dependency-evicted plugin from plugins.enabled and tell the operator how to re-enable it
Charan Rathore36e67a1957d4
diff --git a/pm/plugin_eviction.py b/pm/plugin_eviction.pyindex 093ea88c903..34585faed49 100644--- a/pm/plugin_eviction.py+++ b/pm/plugin_eviction.py@@ -74,6 +74,23 @@ def static_verdicts(entries: list[Entry], python_version: str) -> tuple[dict[Patreturn reasons, waiting+def _spellings(name: str) -> set[str]:+ """Every spelling a config list may hold for plugin *name* (key, bare leaf, manifest name)."""+ try:+ from hermes_cli.plugins_cmd import _plugin_aliases++ return _plugin_aliases(name)+ except Exception: # alias discovery must never fail an update+ return {name, name.split("/")[-1]}+++def _discard_aliases(names: list, aliases: set[str]) -> None:+ """Remove *aliases* from the round-tripped list in place, so order and comments survive."""+ for index in reversed(range(len(names))):+ if names[index] in aliases:+ del names[index]++class PluginEviction:"""Config edits disabling the plugins in *reasons*; published like a plugin selection."""@@ -99,10 +116,15 @@ class PluginEviction:disabled = plugins.get("disabled")if disabled is None:disabled = plugins["disabled"] = []+ enabled = plugins.get("enabled")memory = config.get("memory")for name in names:if name not in disabled:disabled.append(name)+ # Keep the two lists consistent: a plugin that is disabled must not stay enabled+ # under any spelling the loader matches, or `plugins enable` has nothing to repair.+ if isinstance(enabled, list):+ _discard_aliases(enabled, _spellings(name))# plugins.disabled does not veto memory.provider; the provider joins the union on its own.if isinstance(memory, dict) and str(memory.get("provider") or "").strip() == name:memory["provider"] = ""@@ -198,7 +220,8 @@ def sync_evicting(package, facts, fact: dict, *, extras, shipped, frozen, explicfor plugins_dir, name, plugin_dir in entries:key = plugin_dir.resolve()if key in reasons:- notices.append(f"Disabled plugin '{name}' in {plugins_dir.parent}: {reasons[key]}")+ notices.append(f"Disabled plugin '{name}' in {plugins_dir.parent}: {reasons[key]}; "+ f"once it fits this Hermes again, run `hermes plugins enable {name}`")elif key in waiting:notices.append(f"Left plugin '{name}' in {plugins_dir.parent} out of this update: {waiting[key]}; ""it stays enabled and rejoins once Hermes reports a version it accepts")diff --git a/tests/pm/test_plugin_eviction_config.py b/tests/pm/test_plugin_eviction_config.pynew file mode 100644index 00000000000..41d95e4562e--- /dev/null+++ b/tests/pm/test_plugin_eviction_config.py@@ -0,0 +1,152 @@+"""Config edits made by PluginEviction keep plugins.enabled and plugins.disabled consistent."""++from __future__ import annotations++import hashlib+import json+from pathlib import Path++import pytest++import hermes_yaml as yaml+import pm.publication as publication+from pm.plugin_eviction import PluginEviction, _discard_aliases++[email protected](autouse=True)+def _no_alias_discovery(monkeypatch):+ """Alias discovery scans installed plugins; these tests only need key + bare leaf."""+ import hermes_cli.plugins_cmd as plugins_cmd++ monkeypatch.setattr(plugins_cmd, "_plugin_aliases", lambda key, entries=None: {key, key.split("/")[-1]})+ monkeypatch.setattr(publication, "selection_snapshot", lambda: {})+++def _entry(home: Path, name: str) -> tuple[Path, str, Path]:+ plugin_dir = home / "plugins" / name+ plugin_dir.mkdir(parents=True, exist_ok=True)+ return home / "plugins", name, plugin_dir+++def _evict(home: Path, names: list[str], text: str | bytes | None) -> dict:+ config = home / "config.yaml"+ if text is not None:+ config.write_bytes(text if isinstance(text, bytes) else text.encode("utf-8"))+ entries = [_entry(home, name) for name in names]+ reasons = {plugin_dir.resolve(): "too old" for _d, _n, plugin_dir in entries}+ eviction = PluginEviction(entries, reasons)+ (_path, _previous, proposed), = eviction.edits+ return yaml.safe_load(proposed.decode("utf-8")), proposed.decode("utf-8")+++def test_evicted_plugin_leaves_enabled_and_joins_disabled(tmp_path):+ cfg, _ = _evict(tmp_path, ["plug-b"], "plugins:\n enabled: [plug-a, plug-b]\n")+ assert cfg["plugins"]["enabled"] == ["plug-a"]+ assert cfg["plugins"]["disabled"] == ["plug-b"]+++def test_only_enabled_case_creates_disabled_list(tmp_path):+ cfg, _ = _evict(tmp_path, ["plug-a"], "plugins:\n enabled: [plug-a]\n")+ assert cfg["plugins"]["enabled"] == []+ assert cfg["plugins"]["disabled"] == ["plug-a"]+++def test_already_in_both_lists_is_repaired_without_duplicates(tmp_path):+ cfg, _ = _evict(tmp_path, ["plug-a"], "plugins:\n enabled: [plug-a, plug-b]\n disabled: [plug-a]\n")+ assert cfg["plugins"]["enabled"] == ["plug-b"]+ assert cfg["plugins"]["disabled"] == ["plug-a"]+++def test_missing_enabled_list_is_not_created(tmp_path):+ cfg, _ = _evict(tmp_path, ["plug-a"], "plugins:\n disabled: [other]\n")+ assert "enabled" not in cfg["plugins"]+ assert cfg["plugins"]["disabled"] == ["other", "plug-a"]+++def test_namespaced_and_bare_spellings_are_both_removed(tmp_path):+ cfg, _ = _evict(tmp_path, ["web/firecrawl"], "plugins:\n enabled: [web/firecrawl, firecrawl, keep]\n")+ assert cfg["plugins"]["enabled"] == ["keep"]+ assert cfg["plugins"]["disabled"] == ["web/firecrawl"]+++def test_comments_and_order_survive(tmp_path):+ text = "# operator note\nplugins:\n enabled:\n - first # keep me\n - plug-b\n - last\n"+ cfg, out = _evict(tmp_path, ["plug-b"], text)+ assert "# operator note" in out+ assert "# keep me" in out+ assert cfg["plugins"]["enabled"] == ["first", "last"]+++def test_running_twice_is_idempotent(tmp_path):+ _cfg, first = _evict(tmp_path, ["plug-b"], "plugins:\n enabled: [plug-a, plug-b]\n")+ cfg, second = _evict(tmp_path, ["plug-b"], first)+ assert second == first+ assert cfg["plugins"]["disabled"] == ["plug-b"]+++def test_memory_provider_cleared_only_for_evicted_plugin(tmp_path):+ cfg, _ = _evict(tmp_path, ["mem"], "plugins:\n enabled: [mem]\nmemory:\n provider: mem\n")+ assert cfg["memory"]["provider"] == ""+ other = tmp_path / "other"+ other.mkdir()+ cfg, _ = _evict(other, ["plug-a"], "plugins:\n enabled: [plug-a]\nmemory:\n provider: mem\n")+ assert cfg["memory"]["provider"] == "mem"+++def test_utf8_bom_config_round_trips(tmp_path):+ cfg, out = _evict(tmp_path, ["plug-b"], "\ufeffplugins:\n enabled: [plug-a, plug-b]\n".encode("utf-8"))+ assert cfg["plugins"]["enabled"] == ["plug-a"]+ assert not out.startswith("\ufeff")+++def test_secondary_home_is_edited_independently(tmp_path):+ root, profile = tmp_path / "root", tmp_path / "root" / "profiles" / "work"+ root.mkdir(parents=True)+ profile.mkdir(parents=True)+ (root / "config.yaml").write_text("plugins:\n enabled: [plug-a]\n", encoding="utf-8")+ (profile / "config.yaml").write_text("plugins:\n enabled: [plug-a, keep]\n", encoding="utf-8")+ entries = [_entry(root, "plug-a"), _entry(profile, "plug-a")]+ eviction = PluginEviction(entries, {entries[1][2].resolve(): "too old"})+ (path, _previous, proposed), = eviction.edits+ assert path == profile / "config.yaml"+ assert yaml.safe_load(proposed.decode())["plugins"]["enabled"] == ["keep"]+++def test_publish_records_hashes_and_writes_configs(tmp_path, monkeypatch):+ import pm.plugin_eviction as module++ home = tmp_path / "home"+ home.mkdir()+ config = home / "config.yaml"+ config.write_text("plugins:\n enabled: [plug-a]\n", encoding="utf-8")+ entry = _entry(home, "plug-a")+ eviction = PluginEviction([entry], {entry[2].resolve(): "too old"})+ state = tmp_path / "state"+ state.mkdir()+ monkeypatch.setattr(module, "install_state_dir", lambda project: state)+ monkeypatch.setattr(module, "runtime_facts_path", lambda project: tmp_path / "facts.json")+ eviction.publish(tmp_path)++ row = json.loads((state / "publication.json").read_text())+ (_p, previous, proposed), = eviction.edits+ assert row["configs"][0]["config_after"] == hashlib.sha256(proposed).hexdigest()+ assert config.read_bytes() == proposed+ assert yaml.safe_load(config.read_text())["plugins"]["disabled"] == ["plug-a"]+++def test_publish_refuses_when_selection_changed(tmp_path, monkeypatch):+ home = tmp_path / "home"+ home.mkdir()+ (home / "config.yaml").write_text("plugins:\n enabled: [plug-a]\n", encoding="utf-8")+ entry = _entry(home, "plug-a")+ eviction = PluginEviction([entry], {entry[2].resolve(): "too old"})+ monkeypatch.setattr(publication, "selection_snapshot", lambda: {"changed": True})+ with pytest.raises(ValueError, match="changed while preparing"):+ eviction.publish(tmp_path)+ assert yaml.safe_load((home / "config.yaml").read_text())["plugins"]["enabled"] == ["plug-a"]+++def test_discard_aliases_keeps_other_entries_in_order():+ names = ["a", "x", "b", "x"]+ _discard_aliases(names, {"x"})+ assert names == ["a", "b"]diff --git a/tests/pm/test_plugin_survival_contract.py b/tests/pm/test_plugin_survival_contract.pyindex 4abe1204ca9..292d4b10ae7 100644--- a/tests/pm/test_plugin_survival_contract.py+++ b/tests/pm/test_plugin_survival_contract.py@@ -399,8 +399,10 @@ def test_update_sync_disables_plugin_excluded_by_requires_python(admission_env):text = (home / "config.yaml").read_text(encoding="utf-8")assert "# operator note" in textassert "too-old" in yaml.safe_load(text)["plugins"]["disabled"]+ assert yaml.safe_load(text)["plugins"]["enabled"] == ["fits"]assert yaml.safe_load((profile / "config.yaml").read_text(encoding="utf-8"))["memory"]["provider"] == ""assert "too-old" in json.dumps(_latest_receipt(home).get("warnings"))+ assert "hermes plugins enable too-old" in json.dumps(_latest_receipt(home).get("warnings"))assert venv_is_current(project_root=core) is True@@ -418,6 +420,7 @@ def test_update_sync_disables_later_plugin_of_unresolvable_union(admission_env):cfg = yaml.safe_load((home / "config.yaml").read_text(encoding="utf-8"))assert cfg["plugins"]["disabled"] == ["plug-b"]+ assert cfg["plugins"]["enabled"] == ["plug-a"]assert venv_is_current(project_root=tmp_path / "core") is True