Skip to content

The agent that grows with you

fix(signal): register under the canonical module name (one SignalAdapter class)

Teknium0496f7e42067
diff --git a/plugins/platforms/signal/__init__.py b/plugins/platforms/signal/__init__.py
index d4f1d7bf0e3..15b98c45fb2 100644
--- a/plugins/platforms/signal/__init__.py
+++ b/plugins/platforms/signal/__init__.py
@@ -1,3 +1,6 @@
-from .adapter import register
+# Absolute import (not ``from .adapter``): the plugin loader executes this package under a synthetic
+# ``hermes_plugins.platforms__signal`` name, and the adapter's own absolute sibling imports would then
+# load a second ``plugins.platforms.signal.adapter``. One canonical name = one SignalAdapter class.
+from plugins.platforms.signal.adapter import register
__all__ = ["register"]
diff --git a/plugins/platforms/yuanbao/__init__.py b/plugins/platforms/yuanbao/__init__.py
index 19f7559ca2c..2b3ee0d05f4 100644
--- a/plugins/platforms/yuanbao/__init__.py
+++ b/plugins/platforms/yuanbao/__init__.py
@@ -1,5 +1,5 @@
# Absolute import (not ``from .adapter``): the plugin loader executes this package as
-# ``hermes_plugins.yuanbao_platform``; importing the adapter by its canonical module name keeps
+# ``hermes_plugins.platforms__yuanbao``; importing the adapter by its canonical module name keeps
# ONE ``YuanbaoAdapter`` class object, so ``YuanbaoAdapter.get_active()`` from tools/yuanbao_tools.py
# and the standalone sender see the instance the gateway registry created.
from plugins.platforms.yuanbao.register import register
diff --git a/tests/gateway/test_platform_plugin_canonical_class.py b/tests/gateway/test_platform_plugin_canonical_class.py
new file mode 100644
index 00000000000..01f6edca945
--- /dev/null
+++ b/tests/gateway/test_platform_plugin_canonical_class.py
@@ -0,0 +1,22 @@
+"""Plugins whose own code imports siblings by absolute path must register by that same path.
+
+The loader executes a bundled platform package under a synthetic ``hermes_plugins.platforms__<name>``
+name. A package whose adapter (or standalone sender / tools) imports ``plugins.platforms.<name>.*``
+would then hold two adapter classes: the registry's and the one the rest of the code sees
+(Yuanbao's ``get_active()`` singleton, isinstance checks, monkeypatches).
+"""
+
+import importlib
+
+import pytest
+
+
[email protected]("platform, cls", [("signal", "SignalAdapter"), ("yuanbao", "YuanbaoAdapter")])
+def test_registry_factory_is_the_canonical_adapter_class(platform, cls):
+ from gateway.platform_registry import platform_registry
+ from hermes_cli.plugins import discover_plugins
+
+ discover_plugins()
+ entry = platform_registry.get(platform)
+ canonical = getattr(importlib.import_module(f"plugins.platforms.{platform}.adapter"), cls)
+ assert entry.adapter_factory is canonical, entry.adapter_factory.__module__