The loader executes the package as hermes_plugins.platforms__signal, and `from .adapter import register` gave the registry that synthetic copy of the adapter, while the adapter's own absolute sibling imports loaded a second plugins.platforms.signal.adapter. The rate-limit scheduler stayed one object, but SignalAdapter existed twice, so isinstance checks and monkeypatches on the canonical path missed the live adapter, and every start imported it twice. Register by the absolute name, as Yuanbao already does; a test pins both. Also fix the namespace named in Yuanbao's __init__ comment. Found by the independent review of this branch.
23 lines
1.0 KiB
Python
23 lines
1.0 KiB
Python
"""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
|
|
|
|
|
|
@pytest.mark.parametrize("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__
|