Skip to content

The agent that grows with you

fix(plugins): register deferred platform client tools at discovery (#78050)

Emane42db348c927
diff --git a/hermes_cli/plugins.py b/hermes_cli/plugins.py
index 5124516ca03..ac1246e8109 100644
--- a/hermes_cli/plugins.py
+++ b/hermes_cli/plugins.py
@@ -3454,6 +3454,14 @@ class PluginManager:
# symmetric force-reload lands.
self._ownership_ledger: Dict[str, List[PluginRegistration]] = {}
self._registration_order: List[PluginRegistration] = []
+ # Deferred platform plugins whose client tools were registered at
+ # discovery time (see _register_deferred_platform_tools). Keyed by
+ # plugin id: the already-imported package module, so materializing the
+ # adapter later doesn't re-execute it, and the tool names it
+ # contributed, so `hermes plugins list` still attributes them once the
+ # full plugin loads.
+ self._predeclared_modules: Dict[str, types.ModuleType] = {}
+ self._predeclared_tools: Dict[str, List[str]] = {}
# -----------------------------------------------------------------------
# Registration ledger internals
@@ -3717,6 +3725,8 @@ class PluginManager:
self._system_prompt_sections.clear()
self._approval_transports.clear()
self._slack_action_handlers.clear()
+ self._predeclared_modules.clear()
+ self._predeclared_tools.clear()
self._context_engine = None
self._discovered = False
else:
@@ -4507,6 +4517,131 @@ class PluginManager:
exc_info=True,
)
self._load_plugin(manifest)
+ return
+
+ self._register_deferred_platform_tools(manifest, loaded)
+
+ def _register_deferred_platform_tools(
+ self, manifest: PluginManifest, loaded: LoadedPlugin
+ ) -> None:
+ """Register a deferred platform's *client* tools without its adapter.
+
+ A platform plugin can ship two independent things: an inbound adapter
+ (heavy — it imports the platform SDK) and outbound client tools the
+ agent calls like any other tool. Deferring the plugin defers both, so
+ in a CLI/TUI process the client tools never register at all:
+ ``resolve_toolset()`` returns ``[]``, the toolset is missing from the
+ ``hermes tools`` checklist, and even an explicit ``platform_toolsets``
+ entry is dropped because the key is unknown. The same tools work in
+ gateway/web processes only because those materialize every platform at
+ startup (issue #78050).
+
+ Client tools that live in a dedicated ``tools`` submodule can be
+ registered at discovery time instead: importing ``<plugin>/tools.py``
+ does not import the adapter, so the SDK stays unloaded and startup
+ stays cheap. A plugin taking this path must therefore keep its package
+ ``__init__`` import-light and pull the adapter in from inside
+ ``register()`` (as ``plugins/platforms/a2a`` does).
+
+ Opting in is explicit: the manifest must declare ``provides_tools``
+ (the field the plugin list and web server already read to name a
+ plugin's tools, per #78538). Keying off the mere presence of a
+ ``tools.py`` would opt a plugin in by accident — a platform is free to
+ put internal helpers there — and would leave the contract invisible to
+ anyone reading the manifest. ``tools.py`` remains where the code is
+ imported from; ``provides_tools`` is what asks for it. A platform that
+ does not declare the field is untouched and stays fully deferred.
+ """
+ if not manifest.provides_tools:
+ return
+
+ lookup_key = manifest.key or manifest.name
+ plugin_dir = Path(manifest.path) if manifest.path else None
+ if plugin_dir is None or not (plugin_dir / "tools.py").is_file():
+ # Declared but undeliverable. Staying quiet here reproduces the
+ # exact symptom this path exists to fix — tools the manifest
+ # promises, silently absent from the session (#78050) — so say so.
+ logger.warning(
+ "Plugin '%s' declares provides_tools %s but has no tools.py; "
+ "those tools will not be available in CLI/TUI sessions.",
+ lookup_key,
+ list(manifest.provides_tools),
+ )
+ return
+
+ # Snapshotted outside the try so the failure path can tell which tools
+ # a partially-successful register_tools() left behind.
+ before = set(self._plugin_tool_names)
+ try:
+ module = self._load_directory_module(manifest)
+ # Record the module even if nothing below registers: the package
+ # body has already run, so materializing the adapter later must
+ # reuse it rather than execute it a second time.
+ loaded.module = module
+ self._predeclared_modules[lookup_key] = module
+
+ tools_module = importlib.import_module(f"{module.__name__}.tools")
+ register_tools = getattr(tools_module, "register_tools", None)
+ if register_tools is None:
+ logger.warning(
+ "Plugin '%s' declares provides_tools %s but its tools.py "
+ "has no register_tools(ctx); those tools will not be "
+ "available in CLI/TUI sessions.",
+ lookup_key,
+ list(manifest.provides_tools),
+ )
+ return
+
+ register_tools(PluginContext(manifest, self))
+ registered = [
+ t for t in self._plugin_tool_names if t not in before
+ ]
+
+ loaded.tools_registered = registered
+ self._predeclared_tools[lookup_key] = registered
+ logger.debug(
+ "Deferred platform '%s': pre-registered %d client tool(s) %s",
+ lookup_key,
+ len(registered),
+ registered,
+ )
+ except Exception as exc:
+ # A register_tools() that registered some tools and THEN raised
+ # leaves those tools live in the registry. Credit them, or
+ # `hermes plugins list` under-reports what the process is actually
+ # carrying — and _load_plugin's own diff would miss them later
+ # too, since they are already in its "before" snapshot.
+ partial = [t for t in self._plugin_tool_names if t not in before]
+ if partial:
+ loaded.tools_registered = partial
+ self._predeclared_tools[lookup_key] = partial
+
+ # Never let a client-tool import break discovery — the platform
+ # stays deferred and behaves exactly as it did before. But a
+ # broken tools.py produces the #78050 symptom itself (declared
+ # tools missing from the session), so this has to be visible
+ # without turning on debug logging to find it.
+ #
+ # Where it failed is the first thing an operator needs: nothing
+ # registered points at the import or the module body, a partial
+ # run points at one tool's definition, and a full run that still
+ # raised points past the registrations entirely.
+ declared = len(manifest.provides_tools)
+ if not partial:
+ scope = f"before registering any of its {declared} declared tool(s)"
+ elif len(partial) >= declared:
+ scope = f"after registering all {declared} declared tool(s)"
+ else:
+ scope = f"after registering {len(partial)} of {declared} declared tool(s)"
+ logger.warning(
+ "Plugin '%s': client-tool pre-registration failed %s (%s).%s",
+ lookup_key,
+ scope,
+ exc,
+ "" if len(partial) >= declared else
+ " The remainder will be missing from CLI/TUI sessions.",
+ exc_info=_PLUGINS_DEBUG,
+ )
def _warn_python_dependencies(self, manifest: PluginManifest) -> None:
"""Surface declared pip dependencies (#64165).
@@ -4635,7 +4770,13 @@ class PluginManager:
policy_lease.dispose,
)
try:
- if manifest.source in {"user", "project", "bundled"}:
+ # A deferred platform whose client tools were already registered at
+ # discovery time has its package imported too — reuse it so the
+ # module body doesn't execute twice (#78050).
+ preloaded = self._predeclared_modules.pop(plugin_key, None)
+ if preloaded is not None:
+ module = preloaded
+ elif manifest.source in {"user", "project", "bundled"}:
module = self._load_directory_module(
manifest, module_name=_module_name
)
@@ -4657,10 +4798,20 @@ class PluginManager:
for registration in self._registration_order[registration_start:]
if registration.plugin_key == plugin_key and registration.active
]
- loaded.tools_registered = [
+ # Tools this plugin already contributed at discovery time were
+ # registered before ``registration_start``, so the ledger slice
+ # above cannot see them and `hermes plugins list` would
+ # under-report once the deferred adapter materializes (#78050).
+ # Credit them back to the plugin that actually registered them.
+ _predeclared = [
+ t for t in self._predeclared_tools.pop(plugin_key, [])
+ if t in self._plugin_tool_names
+ ]
+ loaded.tools_registered = _predeclared + [
registration.key
for registration in registrations
if registration.kind == "tool"
+ and registration.key not in _predeclared
]
loaded.hooks_registered = [
registration.key
@@ -4713,6 +4864,16 @@ class PluginManager:
"Failed to load plugin '%s': %s",
manifest.name, exc, exc_info=_PLUGINS_DEBUG,
)
+ # A materialization that did NOT succeed has already had its
+ # discovery-time pre-registrations disposed: the failure path above
+ # sweeps the whole ownership ledger for this plugin key, not just the
+ # ``registration_start:`` slice, so nothing this plugin registered
+ # survives it. There is no live tool left to credit — attribution and
+ # the registry agree at zero. Only the success path pops
+ # _predeclared_tools, so drop the entry here rather than let the
+ # bookkeeping outlive the load attempt (#78050).
+ if not loaded.enabled:
+ self._predeclared_tools.pop(plugin_key, None)
self._plugins[manifest.key or manifest.name] = loaded
def _load_portable_plugin(
diff --git a/plugins/platforms/a2a/plugin.yaml b/plugins/platforms/a2a/plugin.yaml
index 9f08b7f9e68..110267dea59 100644
--- a/plugins/platforms/a2a/plugin.yaml
+++ b/plugins/platforms/a2a/plugin.yaml
@@ -26,6 +26,16 @@ description: >
Pure stdlib transport (http.server + urllib) — no a2a-sdk dependency required.
author: Nous Research
+# The outbound client tools. Declaring them here is what asks discovery to
+# import `tools.py` in CLI/TUI processes, where the plugin is otherwise
+# deferred and the tools would never register at all (#78050). The inbound
+# adapter stays deferred either way — only this submodule is imported.
+provides_tools:
+ - a2a_discover
+ - a2a_call
+ - a2a_list
+ - a2a_history
+ - a2a_orchestrate
# requires_env / optional_env are surfaced in the `hermes config` UI via the
# platform-plugin env var injector in hermes_cli/config.py.
requires_env: []
diff --git a/tests/hermes_cli/test_deferred_platform_client_tools.py b/tests/hermes_cli/test_deferred_platform_client_tools.py
new file mode 100644
index 00000000000..67638f51d4f
--- /dev/null
+++ b/tests/hermes_cli/test_deferred_platform_client_tools.py
@@ -0,0 +1,474 @@
+"""Deferred platform plugins must still register their *client* tools.
+
+Issue #78050: a bundled ``kind: platform`` plugin is registered as a deferred
+loader so ``hermes chat`` doesn't import ~20 gateway SDKs. The a2a plugin ships
+two independent things behind that one deferral — an inbound adapter (heavy)
+and five outbound client tools (``a2a_call``, ``a2a_discover``, ``a2a_list``,
+``a2a_history``, ``a2a_orchestrate``). Deferring the plugin deferred both, so
+in a CLI/TUI process the client tools never registered at all:
+``resolve_toolset("a2a")`` returned ``[]`` and the toolset was absent from the
+``hermes tools`` checklist. The same tools worked in gateway/web processes only
+because those materialize every platform at startup.
+
+Client tools that live in a dedicated ``tools`` submodule are now registered at
+discovery time; the adapter stays deferred.
+"""
+
+from __future__ import annotations
+
+import logging
+import sys
+from pathlib import Path
+
+import pytest
+import yaml
+
+
+A2A_CLIENT_TOOLS = {
+ "a2a_call",
+ "a2a_discover",
+ "a2a_history",
+ "a2a_list",
+ "a2a_orchestrate",
+}
+
+
+# ── synthetic platform plugin helpers ──────────────────────────────────────
+
+
+def _write_platform_plugin(
+ root: Path,
+ platform: str,
+ *,
+ with_tools_module: bool,
+ declares_provides_tools: "bool | None" = None,
+) -> "object":
+ """Create a bundled-style platform plugin and return its manifest.
+
+ The adapter import is the expensive thing we must NOT trigger: it is
+ modelled as ``adapter.py`` setting a module-level sentinel, imported from
+ inside ``register()`` exactly as the real a2a plugin does.
+
+ ``declares_provides_tools`` controls the manifest opt-in independently of
+ whether a ``tools.py`` exists on disk, so a test can pin what actually
+ triggers pre-registration. Defaults to following ``with_tools_module``,
+ which is the shape a real plugin ships.
+ """
+ from hermes_cli.plugins import PluginManifest
+
+ if declares_provides_tools is None:
+ declares_provides_tools = with_tools_module
+ provides_tools = [f"{platform}_call"] if declares_provides_tools else []
+
+ plugin_dir = root / platform
+ plugin_dir.mkdir(parents=True, exist_ok=True)
+ manifest_data = {
+ "name": f"{platform}-platform",
+ "kind": "platform",
+ "version": "1.0.0",
+ }
+ if provides_tools:
+ manifest_data["provides_tools"] = provides_tools
+ (plugin_dir / "plugin.yaml").write_text(
+ yaml.dump(manifest_data),
+ encoding="utf-8",
+ )
+
+ # Sentinels let the tests prove what was and wasn't imported.
+ (plugin_dir / "adapter.py").write_text(
+ "import _deferred_probe\n"
+ "_deferred_probe.adapter_imports += 1\n",
+ encoding="utf-8",
+ )
+ init_body = [
+ "import _deferred_probe",
+ "_deferred_probe.package_execs += 1",
+ "",
+ "def register(ctx):",
+ " from . import adapter # noqa: F401 (heavy import, deferred)",
+ ]
+ if with_tools_module:
+ (plugin_dir / "tools.py").write_text(
+ "import _deferred_probe\n"
+ "_deferred_probe.tools_execs += 1\n"
+ "\n"
+ "\n"
+ "def _handler(**kwargs):\n"
+ " return 'ok'\n"
+ "\n"
+ "\n"
+ "def register_tools(ctx):\n"
+ f" ctx.register_tool(\n"
+ f" name='{platform}_call',\n"
+ f" toolset='{platform}',\n"
+ " schema={'type': 'function', 'function': {'name': "
+ f"'{platform}_call', 'description': 'call a peer', 'parameters': "
+ "{'type': 'object', 'properties': {}}}},\n"
+ " handler=_handler,\n"
+ " description='call a peer',\n"
+ " )\n",
+ encoding="utf-8",
+ )
+ init_body.append(" from .tools import register_tools")
+ init_body.append(" register_tools(ctx)")
+ (plugin_dir / "__init__.py").write_text("\n".join(init_body) + "\n", encoding="utf-8")
+
+ return PluginManifest(
+ name=f"{platform}-platform",
+ kind="platform",
+ source="bundled",
+ path=str(plugin_dir),
+ key=f"{platform}-platform",
+ provides_tools=provides_tools,
+ )
+
+
+def probe(monkeypatch):
+ """A module the synthetic plugin can count imports into."""
+ import types
+
+ mod = types.ModuleType("_deferred_probe")
+ mod.package_execs = 0
+ mod.adapter_imports = 0
+ mod.tools_execs = 0
+ monkeypatch.setitem(sys.modules, "_deferred_probe", mod)
+ return mod
+
+
+def clean_registry():
+ """Undo everything a synthetic plugin leaves behind.
+
+ Each test writes a fresh plugin to its own tmp_path but reuses the
+ ``probeplat`` name, so the imported ``hermes_plugins.*`` modules have to go
+ too — otherwise the next test's ``import_module`` returns the previous
+ test's cached submodule instead of reading the new file.
+ """
+ from gateway.platform_registry import platform_registry
+ from tools.registry import registry
+
+ before_tools = set(registry._tools)
+ before_modules = set(sys.modules)
+ yield
+ for name in set(registry._tools) - before_tools:
+ registry._tools.pop(name, None)
+ for platform in ("probeplat", "barefoot", "quietplat", "promiseplat"):
+ platform_registry.unregister(platform)
+ for name in set(sys.modules) - before_modules:
+ if name.startswith("hermes_plugins."):
+ sys.modules.pop(name, None)
+
+
+# ── the reported symptom, against the real a2a plugin ──────────────────────
+
+
+class TestA2AClientToolsInCliProcess:
+ """The issue's exact repro: a CLI/TUI process, no gateway startup."""
+
+ def test_manifest_declares_the_client_tools(self):
+ """The opt-in lives in the manifest, so it is pinned like any contract.
+
+ Dropping ``provides_tools`` from plugin.yaml silently reverts a2a to
+ the deferred-and-invisible behaviour of #78050, with every other test
+ here still passing on the synthetic plugins — so assert it directly.
+ """
+ manifest_path = (
+ Path(__file__).resolve().parents[2]
+ / "plugins" / "platforms" / "a2a" / "plugin.yaml"
+ )
+ manifest = yaml.safe_load(manifest_path.read_text(encoding="utf-8"))
+
+ assert set(manifest.get("provides_tools") or []) == A2A_CLIENT_TOOLS
+
+ def test_a2a_toolset_resolves_without_materializing_the_platform(self):
+ from hermes_cli.plugins import PluginManager
+ from toolsets import resolve_toolset
+
+ mgr = PluginManager()
+ mgr.discover_and_load()
+
+ a2a = mgr._plugins.get("a2a-platform")
+ assert a2a is not None, "bundled a2a platform plugin was not discovered"
+
+ # The whole point of the deferral is preserved: the inbound adapter is
+ # still not imported in a CLI process.
+ assert a2a.deferred is True
+
+ # ...but the outbound client tools are now reachable. Before the fix
+ # this was [] until a gateway/web process called all_entries().
+ assert set(resolve_toolset("a2a")) == A2A_CLIENT_TOOLS
+
+ def test_a2a_appears_in_the_hermes_tools_checklist(self):
+ """`a2a` is in _DEFAULT_OFF_TOOLSETS, so it must be tickable.
+
+ Every other member of that set (homeassistant, spotify, video_gen,
+ x_search, ...) renders a checkbox; a2a rendered nothing, so the
+ documented opt-in path had nothing to tick.
+ """
+ from hermes_cli.plugins import discover_plugins, get_plugin_toolsets
+
+ # get_plugin_toolsets() reads the process-wide manager, which is what
+ # the `hermes tools` checklist does.
+ discover_plugins()
+
+ assert "a2a" in {key for key, _, _ in get_plugin_toolsets()}
+
+ def test_platform_bundle_includes_the_client_tools(self):
+ """``hermes-a2a`` sessions get the client tools too.
+
+ The bundle path read the tool registry behind a deliberately cheap
+ ``is_registered()`` check, so a deferred platform's own tools were
+ dropped from its bundle as well.
+ """
+ from hermes_cli.plugins import PluginManager
+ from toolsets import resolve_toolset
+
+ mgr = PluginManager()
+ mgr.discover_and_load()
+
+ assert A2A_CLIENT_TOOLS.issubset(set(resolve_toolset("hermes-a2a")))
+
+
+# ── the general mechanism ──────────────────────────────────────────────────
+
+
+class TestDeferredPlatformToolPreregistration:
+ def test_tools_module_registers_without_importing_the_adapter(
+ self, tmp_path, probe, clean_registry
+ ):
+ from hermes_cli.plugins import PluginManager
+ from toolsets import resolve_toolset
+
+ manifest = _write_platform_plugin(tmp_path, "probeplat", with_tools_module=True)
+
+ mgr = PluginManager()
+ mgr._register_deferred_platform(manifest)
+
+ assert resolve_toolset("probeplat") == ["probeplat_call"]
+ # The expensive half stayed deferred — that's what makes this safe.
+ assert probe.adapter_imports == 0
+ assert probe.tools_execs == 1
+ assert mgr._plugins["probeplat-platform"].deferred is True
+
+ def test_plugin_without_tools_module_stays_fully_deferred(
+ self, tmp_path, probe, clean_registry
+ ):
+ """No ``tools.py`` means no behaviour change at all — nothing imported."""
+ from hermes_cli.plugins import PluginManager
+
+ manifest = _write_platform_plugin(tmp_path, "barefoot", with_tools_module=False)
+
+ mgr = PluginManager()
+ mgr._register_deferred_platform(manifest)
+
+ assert probe.package_execs == 0
+ assert probe.adapter_imports == 0
+ assert mgr._plugins["barefoot-platform"].tools_registered == []
+
+ def test_tools_module_alone_does_not_opt_a_platform_in(
+ self, tmp_path, probe, clean_registry
+ ):
+ """``provides_tools`` is the trigger, not the presence of a file.
+
+ A platform is free to keep internal helpers in ``tools.py``; without
+ the manifest declaring what it publishes, discovery must not import
+ the package at all. Otherwise a plugin opts into an eager import by
+ naming a file, and the contract is invisible to anyone reading the
+ manifest.
+ """
+ from hermes_cli.plugins import PluginManager
+
+ manifest = _write_platform_plugin(
+ tmp_path,
+ "quietplat",
+ with_tools_module=True,
+ declares_provides_tools=False,
+ )
+
+ mgr = PluginManager()
+ mgr._register_deferred_platform(manifest)
+
+ assert probe.package_execs == 0
+ assert probe.tools_execs == 0
+ assert probe.adapter_imports == 0
+ assert mgr._plugins["quietplat-platform"].deferred is True
+ assert mgr._plugins["quietplat-platform"].tools_registered == []
+
+ def test_package_body_runs_once_across_discovery_and_materialization(
+ self, tmp_path, probe, clean_registry
+ ):
+ """Pre-importing the package must not double-execute it later.
+
+ Discovery imports ``<plugin>/__init__.py`` to reach ``tools.py``; when
+ the gateway later materializes the adapter, ``_load_plugin`` reuses
+ that module instead of re-running its body.
+ """
+ from gateway.platform_registry import platform_registry
+ from hermes_cli.plugins import PluginManager
+
+ manifest = _write_platform_plugin(tmp_path, "probeplat", with_tools_module=True)
+
+ mgr = PluginManager()
+ mgr._register_deferred_platform(manifest)
+ assert probe.package_execs == 1
+
+ # What gateway/web startup does.
+ platform_registry.get("probeplat")
+
+ assert probe.package_execs == 1
+ assert probe.adapter_imports == 1
+
+ def test_tools_stay_attributed_after_materialization(
+ self, tmp_path, probe, clean_registry
+ ):
+ """`hermes plugins list` must still credit the pre-registered tools.
+
+ ``_load_plugin`` attributes tools by diffing the registry around
+ ``register()``. Tools registered at discovery are already in the
+ "before" snapshot, so the diff alone would report zero.
+ """
+ from gateway.platform_registry import platform_registry
+ from hermes_cli.plugins import PluginManager
+
+ manifest = _write_platform_plugin(tmp_path, "probeplat", with_tools_module=True)
+
+ mgr = PluginManager()
+ mgr._register_deferred_platform(manifest)
+ assert mgr._plugins["probeplat-platform"].tools_registered == ["probeplat_call"]
+
+ platform_registry.get("probeplat")
+
+ loaded = mgr._plugins["probeplat-platform"]
+ assert loaded.tools_registered == ["probeplat_call"]
+ assert loaded.enabled is True
+
+ def test_broken_tools_module_does_not_break_discovery(
+ self, tmp_path, probe, clean_registry, caplog
+ ):
+ """A plugin whose ``tools.py`` raises degrades to the old behaviour.
+
+ Degrading quietly is not enough: the degraded state IS the #78050
+ symptom (declared tools absent from the session), so it has to be
+ visible without enabling debug logging to find it.
+ """
+ from hermes_cli.plugins import PluginManager
+
+ manifest = _write_platform_plugin(tmp_path, "probeplat", with_tools_module=True)
+ (Path(manifest.path) / "tools.py").write_text(
+ "raise RuntimeError('boom')\n", encoding="utf-8"
+ )
+
+ mgr = PluginManager()
+ with caplog.at_level(logging.WARNING, logger="hermes_cli.plugins"):
+ mgr._register_deferred_platform(manifest) # must not raise
+
+ assert mgr._plugins["probeplat-platform"].deferred is True
+ assert mgr._plugins["probeplat-platform"].tools_registered == []
+ assert any(
+ "probeplat-platform" in r.message and r.levelno == logging.WARNING
+ for r in caplog.records
+ ), caplog.text
+
+ def test_partially_registered_tools_are_still_attributed(
+ self, tmp_path, probe, clean_registry, caplog
+ ):
+ """Tools registered before a mid-way failure are live — credit them.
+
+ `register_tools` is not transactional: whatever it registered before
+ raising stays in the registry. Leaving those unattributed makes
+ `hermes plugins list` under-report what the process is carrying, and
+ `_load_plugin`'s own diff cannot recover them later because they are
+ already inside its "before" snapshot.
+ """
+ from hermes_cli.plugins import PluginManager
+
+ manifest = _write_platform_plugin(tmp_path, "probeplat", with_tools_module=True)
+ tools_py = (Path(manifest.path) / "tools.py").read_text(encoding="utf-8")
+ (Path(manifest.path) / "tools.py").write_text(
+ tools_py + " raise RuntimeError('boom after the first tool')\n",
+ encoding="utf-8",
+ )
+
+ mgr = PluginManager()
+ with caplog.at_level(logging.WARNING, logger="hermes_cli.plugins"):
+ mgr._register_deferred_platform(manifest) # must not raise
+
+ # Attribution without a live tool would be a lie, so check the registry
+ # itself rather than only the bookkeeping maps.
+ from toolsets import resolve_toolset
+
+ assert resolve_toolset("probeplat") == ["probeplat_call"]
+ assert mgr._plugins["probeplat-platform"].tools_registered == ["probeplat_call"]
+ assert mgr._predeclared_tools["probeplat-platform"] == ["probeplat_call"]
+ assert mgr._plugins["probeplat-platform"].deferred is True
+ assert any(r.levelno == logging.WARNING for r in caplog.records), caplog.text
+
+ def test_failed_materialization_tears_down_pre_registered_tools(
+ self, tmp_path, probe, clean_registry, caplog
+ ):
+ """A failed materialize takes the pre-registered tools down with it.
+
+ The synthetic plugin's ``register()`` calls the same broken
+ ``register_tools`` without catching, so materializing raises.
+
+ ``_load_plugin_scoped``'s failure path sweeps the *whole* ownership
+ ledger for this plugin key — not the ``registration_start:`` slice —
+ and disposes it, so the discovery-time client tools go with the failed
+ adapter. Attribution and the registry therefore agree at zero: `hermes
+ plugins list` reports no tools because the process really is serving
+ none.
+
+ ``enabled`` stays False on purpose: the adapter genuinely did not load.
+ """
+ from gateway.platform_registry import platform_registry
+ from hermes_cli.plugins import PluginManager
+ from toolsets import resolve_toolset
+
+ manifest = _write_platform_plugin(tmp_path, "probeplat", with_tools_module=True)
+ tools_py = (Path(manifest.path) / "tools.py").read_text(encoding="utf-8")
+ (Path(manifest.path) / "tools.py").write_text(
+ tools_py + " raise RuntimeError('boom after the first tool')\n",
+ encoding="utf-8",
+ )
+
+ mgr = PluginManager()
+ with caplog.at_level(logging.WARNING, logger="hermes_cli.plugins"):
+ mgr._register_deferred_platform(manifest)
+ platform_registry.get("probeplat") # gateway startup; register() raises
+
+ loaded = mgr._plugins["probeplat-platform"]
+ assert resolve_toolset("probeplat") == []
+ assert loaded.tools_registered == []
+ assert loaded.enabled is False
+ assert loaded.error
+ # The bookkeeping entry must not outlive the failed load attempt.
+ assert "probeplat-platform" not in mgr._predeclared_tools
+
+ def test_declared_tools_with_no_tools_module_warns(
+ self, tmp_path, probe, clean_registry, caplog
+ ):
+ """A manifest promising tools it cannot deliver must say so.
+
+ Returning silently here leaves the operator with exactly the bug this
+ path fixes and no thread to pull on.
+ """
+ from hermes_cli.plugins import PluginManager
+
+ manifest = _write_platform_plugin(
+ tmp_path,
+ "promiseplat",
+ with_tools_module=False,
+ declares_provides_tools=True,
+ )
+
+ mgr = PluginManager()
+ with caplog.at_level(logging.WARNING, logger="hermes_cli.plugins"):
+ mgr._register_deferred_platform(manifest)
+
+ assert probe.package_execs == 0
+ assert mgr._plugins["promiseplat-platform"].tools_registered == []
+ assert any(
+ "promiseplat-platform" in r.message and "provides_tools" in r.message
+ for r in caplog.records
+ ), caplog.text