The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(plugins): register entry-point plugins declared as module:function
mannnrachman9778f00970fb
diff --git a/hermes_cli/plugins_loader.py b/hermes_cli/plugins_loader.pyindex 416eb12f1aa..e072ae9aaf2 100644--- a/hermes_cli/plugins_loader.py+++ b/hermes_cli/plugins_loader.py@@ -19,7 +19,7 @@ import typesfrom contextlib import contextmanagerfrom functools import wrapsfrom pathlib import Path-from typing import TYPE_CHECKING, Any, Dict, List, Mapping, Optional+from typing import TYPE_CHECKING, Any, Callable, Dict, List, Mapping, Optional, Unionfrom hermes_constants import get_hermes_home, reset_hermes_home_override, set_hermes_home_overridefrom registration_lifecycle import replacement_coordinator@@ -309,8 +309,15 @@ class PluginLoaderMixin:module = self._load_directory_module(manifest, module_name=module_name)elif module is None:module = self._load_entrypoint_module(manifest)+ register_fn = None+ if module is not None and not isinstance(module, types.ModuleType) and callable(module):+ # An entry point declared as ``module:function`` resolves to the function object itself via+ # ``ep.load()``, not its module (#72052).+ register_fn = module+ module = sys.modules.get(getattr(register_fn, "__module__", ""))loaded.module = module- register_fn = getattr(module, "register", None)+ if register_fn is None:+ register_fn = getattr(module, "register", None)if register_fn is None:loaded.error = "no register() function"logger.warning("Plugin '%s' has no register() function", manifest.name)@@ -470,8 +477,9 @@ class PluginLoaderMixin:raisereturn module- def _load_entrypoint_module(self, manifest: PluginManifest) -> types.ModuleType:- """Load a pip-installed plugin via its entry-point reference."""+ def _load_entrypoint_module(self, manifest: PluginManifest) -> Union[types.ModuleType, Callable[..., Any]]:+ """Load a pip-installed plugin via its entry-point reference: the module for a bare ``module`` target,+ the referenced attribute (normally ``register``) for the ``module:function`` form."""for ep in _select_entry_point_group(importlib.metadata.entry_points(), ENTRY_POINTS_GROUP):if ep.name == manifest.name:return ep.load()diff --git a/tests/hermes_cli/test_plugins.py b/tests/hermes_cli/test_plugins.pyindex 0459d26500c..d4e5e0ca651 100644--- a/tests/hermes_cli/test_plugins.py+++ b/tests/hermes_cli/test_plugins.py@@ -395,6 +395,54 @@ class TestPluginDiscovery:+ def test_entry_point_function_form_registers(self, tmp_path, monkeypatch):+ """Entry points declared as ``module:function`` register via the callable.++ Regression for #72052: real ``EntryPoint.load()`` returns the referenced+ attribute for the ``module:function`` form, not the module. The loader+ used to look for ``.register`` on that function object, find nothing,+ and warn "no register() function" on every discovery pass.+ """+ hermes_home = tmp_path / "hermes_test"+ hermes_home.mkdir(parents=True, exist_ok=True)+ monkeypatch.setenv("HERMES_HOME", str(hermes_home))+ # Entry-point plugins load only when opted into plugins.enabled.+ (hermes_home / "config.yaml").write_text(+ yaml.safe_dump({"plugins": {"enabled": ["fn_plugin"]}})+ )++ fake_module = types.ModuleType("fake_fn_plugin")+ register_calls = []++ def register(ctx):+ register_calls.append(ctx)++ register.__module__ = "fake_fn_plugin"+ fake_module.register = register # type: ignore[attr-defined]+ monkeypatch.setitem(sys.modules, "fake_fn_plugin", fake_module)++ fake_ep = MagicMock()+ fake_ep.name = "fn_plugin"+ fake_ep.value = "fake_fn_plugin:register"+ fake_ep.group = ENTRY_POINTS_GROUP+ # Mirror real importlib behavior: load() resolves to the attribute.+ fake_ep.load.return_value = register++ def fake_entry_points():+ result = MagicMock()+ result.select = MagicMock(return_value=[fake_ep])+ return result++ with patch("importlib.metadata.entry_points", fake_entry_points):+ mgr = PluginManager()+ mgr.discover_and_load()++ entry = mgr._plugins["fn_plugin"]+ assert entry.error is None, entry.error+ assert entry.enabled+ assert len(register_calls) == 1+ assert entry.module is fake_module+def test_force_rediscover_clears_all_plugin_registries(self, monkeypatch):"""force=True must clear every plugin-populated registry.