The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(yuanbao): import the plugin module; registration shape test
Teknium12552a2197f0
diff --git a/tests/gateway/platforms/test_yuanbao_state_cleanup.py b/tests/gateway/platforms/test_yuanbao_state_cleanup.pyindex 5304dcb73ba..844cdfbc05f 100644--- a/tests/gateway/platforms/test_yuanbao_state_cleanup.py+++ b/tests/gateway/platforms/test_yuanbao_state_cleanup.py@@ -18,7 +18,7 @@ import timefrom types import SimpleNamespacefrom gateway.platforms.base import BasePlatformAdapter-from gateway.platforms.yuanbao import MessageSender, YuanbaoAdapter+from plugins.platforms.yuanbao.adapter import MessageSender, YuanbaoAdapter# ---------------------------------------------------------------------------diff --git a/tests/gateway/test_access_policy_mixin.py b/tests/gateway/test_access_policy_mixin.pyindex f383fa19f25..a177a2c53e3 100644--- a/tests/gateway/test_access_policy_mixin.py+++ b/tests/gateway/test_access_policy_mixin.py@@ -33,7 +33,7 @@ def _hosts():from plugins.platforms.weixin.adapter import WeixinAdapterfrom plugins.platforms.whatsapp_cloud.adapter import WhatsAppCloudAdapterfrom gateway.platforms.whatsapp_common import WhatsAppBehaviorMixin- from gateway.platforms.yuanbao import AccessPolicy+ from plugins.platforms.yuanbao.adapter import AccessPolicyfrom plugins.platforms.wecom.adapter import WeComAdapterhosts = {diff --git a/tests/gateway/test_adapter_session_key_seam.py b/tests/gateway/test_adapter_session_key_seam.pyindex 1e807b6fa45..d41f2699ccd 100644--- a/tests/gateway/test_adapter_session_key_seam.py+++ b/tests/gateway/test_adapter_session_key_seam.py@@ -14,7 +14,7 @@ import pytestfrom gateway.config import GatewayConfig, Platform, PlatformConfigfrom gateway.platforms.event import MessageEvent-from gateway.platforms.yuanbao import DispatchMiddleware, InboundContext, YuanbaoAdapter+from plugins.platforms.yuanbao.adapter import DispatchMiddleware, InboundContext, YuanbaoAdapterfrom gateway.profile_routing import parse_profile_routesdiff --git a/tests/gateway/test_adapter_settings_scoped_precedence.py b/tests/gateway/test_adapter_settings_scoped_precedence.pyindex dc9e05b91ca..3a05bbbe20c 100644--- a/tests/gateway/test_adapter_settings_scoped_precedence.py+++ b/tests/gateway/test_adapter_settings_scoped_precedence.py@@ -161,7 +161,7 @@ def test_yuanbao_secondary_home_channel_is_live_and_reloadable(homes):"""Auto-sethome from a secondary lands in ``platforms.yuanbao.home_channel`` of ITS config (read backby ``load_gateway_config``) and on the live PlatformConfig; the process env stays untouched."""import os- from gateway.platforms.yuanbao import AutoSetHomeMiddleware+ from plugins.platforms.yuanbao.adapter import AutoSetHomeMiddleware_, secondary = homes(secondary / "config.yaml").write_text("platforms:\n yuanbao:\n enabled: true\n extra:\n app_id: a\n app_secret: b\n", encoding="utf-8")diff --git a/tests/gateway/test_config_driven_access_policy.py b/tests/gateway/test_config_driven_access_policy.pyindex 718178e7b92..9aac32762ed 100644--- a/tests/gateway/test_config_driven_access_policy.py+++ b/tests/gateway/test_config_driven_access_policy.py@@ -110,7 +110,7 @@ def test_base_adapter_defaults_to_not_owning_access_policy():[("plugins.platforms.wecom.adapter", "WeComAdapter"),("plugins.platforms.weixin.adapter", "WeixinAdapter"),- ("gateway.platforms.yuanbao", "YuanbaoAdapter"),+ ("plugins.platforms.yuanbao.adapter", "YuanbaoAdapter"),("plugins.platforms.qqbot.adapter", "QQAdapter"),("plugins.platforms.whatsapp.adapter", "WhatsAppAdapter"),],@@ -267,7 +267,7 @@ def test_pairing_dm_policy_strict_intake_auth_denies_unknown(def test_yuanbao_pairing_dm_intake_denies_blank_principal(monkeypatch, blank_sender):"""Yuanbao pairing intake must not forward senderless C2C callbacks."""_clear_auth_env(monkeypatch)- from gateway.platforms.yuanbao import AccessPolicy+ from plugins.platforms.yuanbao.adapter import AccessPolicypolicy = AccessPolicy(dm_policy="pairing",diff --git a/tests/gateway/test_multiplex_process_global_sinks.py b/tests/gateway/test_multiplex_process_global_sinks.pyindex 87a0127ab32..4d7b657440e 100644--- a/tests/gateway/test_multiplex_process_global_sinks.py+++ b/tests/gateway/test_multiplex_process_global_sinks.py@@ -22,7 +22,7 @@ def _under_secondary(home, fn):def test_yuanbao_auto_sethome_from_secondary_stays_in_its_config(tmp_path, monkeypatch):- from gateway.platforms.yuanbao import AutoSetHomeMiddleware+ from plugins.platforms.yuanbao.adapter import AutoSetHomeMiddlewaremonkeypatch.delenv("YUANBAO_HOME_CHANNEL", raising=False)secondary = tmp_path / "profiles" / "b2"diff --git a/tests/gateway/test_platform_authz_scope.py b/tests/gateway/test_platform_authz_scope.pyindex f1b648f963e..5b6e14caad9 100644--- a/tests/gateway/test_platform_authz_scope.py+++ b/tests/gateway/test_platform_authz_scope.py@@ -56,7 +56,7 @@ def profile_scope():"module_path,helper_name,var",[("plugins.platforms.weixin.adapter", "_wx_secret", "WEIXIN_ALLOWED_USERS"),- ("gateway.platforms.yuanbao", "_yb_secret", "YUANBAO_DM_POLICY"),+ ("plugins.platforms.yuanbao.adapter", "_yb_secret", "YUANBAO_DM_POLICY"),("plugins.platforms.signal.adapter", "_sig_secret", "SIGNAL_ALLOWED_USERS"),("plugins.platforms.wecom.adapter", "_get_scoped_secret", "WECOM_ALLOWED_USERS"),],@@ -87,7 +87,7 @@ def multiplex_on(monkeypatch):"module_path,helper_name",[("plugins.platforms.weixin.adapter", "_wx_secret"),- ("gateway.platforms.yuanbao", "_yb_secret"),+ ("plugins.platforms.yuanbao.adapter", "_yb_secret"),("plugins.platforms.signal.adapter", "_sig_secret"),("plugins.platforms.wecom.adapter", "_get_scoped_secret"),],@@ -122,7 +122,7 @@ def test_helper_does_not_leak_default_env_into_scoped_miss("module_path,helper_name,var",[("plugins.platforms.weixin.adapter", "_wx_secret", "WEIXIN_ALLOWED_USERS"),- ("gateway.platforms.yuanbao", "_yb_secret", "YUANBAO_DM_POLICY"),+ ("plugins.platforms.yuanbao.adapter", "_yb_secret", "YUANBAO_DM_POLICY"),("plugins.platforms.signal.adapter", "_sig_secret", "SIGNAL_ALLOWED_USERS"),("plugins.platforms.wecom.adapter", "_get_scoped_secret", "WECOM_ALLOWED_USERS"),],@@ -162,7 +162,7 @@ def test_weixin_open_gate_honors_scope_opt_in():def test_yuanbao_access_policy_gate_ignores_default_env(profile_scope, multiplex_on, monkeypatch):monkeypatch.setenv("GATEWAY_ALLOW_ALL_USERS", "true")- from gateway.platforms.yuanbao import AccessPolicy+ from plugins.platforms.yuanbao.adapter import AccessPolicypolicy = AccessPolicy(dm_policy="open", dm_allow_from=[], group_policy="pairing", group_allow_from=[]diff --git a/tests/gateway/test_ws_dial_happy_eyeballs.py b/tests/gateway/test_ws_dial_happy_eyeballs.pyindex 46679c2f7d5..0c6d5454bfe 100644--- a/tests/gateway/test_ws_dial_happy_eyeballs.py+++ b/tests/gateway/test_ws_dial_happy_eyeballs.py@@ -42,7 +42,7 @@ async def test_relay_ws_transport_dial_races_ipv6_ipv4(monkeypatch):@pytest.mark.asyncioasync def test_yuanbao_dial_races_ipv6_ipv4():- from gateway.platforms.yuanbao import ConnectionManager, YuanbaoAdapter+ from plugins.platforms.yuanbao.adapter import ConnectionManager, YuanbaoAdapteradapter = MagicMock(spec=YuanbaoAdapter)adapter.name = "yuanbao"@@ -50,7 +50,7 @@ async def test_yuanbao_dial_races_ipv6_ipv4():adapter._ws_url = "wss://test.example.com/ws"cm = ConnectionManager(adapter)rec = _Recorder()- with patch("gateway.platforms.yuanbao.websockets.connect", rec), pytest.raises(ConnectionRefusedError):+ with patch("plugins.platforms.yuanbao.adapter.websockets.connect", rec), pytest.raises(ConnectionRefusedError):await cm._dial({"bot_id": "b", "token": "t"})assert rec.kwargs["happy_eyeballs_delay"] == EXPECTED_DELAYdiff --git a/tests/gateway/test_yuanbao_forwarded_heartbeat.py b/tests/gateway/test_yuanbao_forwarded_heartbeat.pyindex 6ddd578fc73..3938630ad87 100644--- a/tests/gateway/test_yuanbao_forwarded_heartbeat.py+++ b/tests/gateway/test_yuanbao_forwarded_heartbeat.py@@ -11,7 +11,7 @@ import warningsimport pytest-from gateway.platforms.yuanbao import (+from plugins.platforms.yuanbao.adapter import (ForwardedRecordsParseMiddleware,InboundContext,WS_HEARTBEAT_RUNNING,diff --git a/tests/gateway/test_yuanbao_integration.py b/tests/gateway/test_yuanbao_integration.pyindex c82d75330f0..3afe336c98a 100644--- a/tests/gateway/test_yuanbao_integration.py+++ b/tests/gateway/test_yuanbao_integration.py@@ -22,7 +22,7 @@ if _REPO_ROOT not in sys.path:import pytestfrom unittest.mock import MagicMock, patchfrom gateway.config import Platform, PlatformConfig, GatewayConfig-from gateway.platforms.yuanbao import YuanbaoAdapter+from plugins.platforms.yuanbao.adapter import YuanbaoAdapterdef make_config(**kwargs):@@ -123,8 +123,11 @@ class TestGatewayRunnerRegistration:try:runner, _ = self._make_minimal_runner(gw_config)+ # Yuanbao is a bundled platform plugin: the registry learns it through discovery.+ from hermes_cli.plugins import discover_plugins+ discover_plugins()# websockets 在测试环境可能未安装,mock 掉 WEBSOCKETS_AVAILABLE- with patch("gateway.platforms.yuanbao.WEBSOCKETS_AVAILABLE", True):+ with patch("plugins.platforms.yuanbao.adapter.WEBSOCKETS_AVAILABLE", True):adapter = runner._create_adapter(Platform.YUANBAO, config)except ImportError as e:pytest.skip(f"run.py import unavailable in test env: {e}")@@ -198,7 +201,7 @@ class TestP0ChatLockEviction:def test_eviction_skips_locked(self):"""When eviction is needed, locked entries are skipped."""adapter = YuanbaoAdapter(make_config())- from gateway.platforms.yuanbao import MessageSender+ from plugins.platforms.yuanbao.adapter import MessageSender# Fill to capacity with unlocked locksfor i in range(MessageSender.CHAT_DICT_MAX_SIZE):diff --git a/tests/gateway/test_yuanbao_markdown.py b/tests/gateway/test_yuanbao_markdown.pyindex 098e481288a..63d4daec15c 100644--- a/tests/gateway/test_yuanbao_markdown.py+++ b/tests/gateway/test_yuanbao_markdown.py@@ -17,7 +17,7 @@ import unittestsys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))from gateway.platforms import helpers as _mdchunk-from gateway.platforms.yuanbao import MarkdownProcessor+from plugins.platforms.yuanbao.adapter import MarkdownProcessor# ============ has_unclosed_fence ============diff --git a/tests/gateway/test_yuanbao_media_ssrf.py b/tests/gateway/test_yuanbao_media_ssrf.pyindex bd496afc2cf..5c58b797065 100644--- a/tests/gateway/test_yuanbao_media_ssrf.py+++ b/tests/gateway/test_yuanbao_media_ssrf.py@@ -8,7 +8,7 @@ the gateway fetch cloud-metadata endpoints. These tests pin the guard.import pytest-from gateway.platforms.yuanbao_media import download_url+from plugins.platforms.yuanbao.yuanbao_media import download_urlclass TestDownloadUrlSSRF:diff --git a/tests/gateway/test_yuanbao_pipeline.py b/tests/gateway/test_yuanbao_pipeline.pyindex 34c8dc6de5b..9e8ffd51afd 100644--- a/tests/gateway/test_yuanbao_pipeline.py+++ b/tests/gateway/test_yuanbao_pipeline.py@@ -23,7 +23,7 @@ if _REPO_ROOT not in sys.path:import pytestfrom unittest.mock import AsyncMock, MagicMock, patch-from gateway.platforms.yuanbao import (+from plugins.platforms.yuanbao.adapter import (InboundContext,InboundMiddleware,InboundPipeline,diff --git a/tests/gateway/test_yuanbao_plugin_registration.py b/tests/gateway/test_yuanbao_plugin_registration.pynew file mode 100644index 00000000000..e44461527fc--- /dev/null+++ b/tests/gateway/test_yuanbao_plugin_registration.py@@ -0,0 +1,37 @@+"""Yuanbao ships as a bundled platform plugin: registry entry shape + no core wiring left."""++from gateway.config import Platform+++class _Ctx:+ def __init__(self):+ self.kwargs = None++ def register_platform(self, **kwargs):+ self.kwargs = kwargs+++def test_register_shape_and_core_wiring_removed():+ from plugins.platforms.yuanbao import register+ from plugins.platforms.yuanbao.adapter import YuanbaoAdapter, _standalone_send++ ctx = _Ctx()+ register(ctx)+ kw = ctx.kwargs+ assert kw["name"] == "yuanbao" and kw["label"] == "Yuanbao" and kw["emoji"] == "💎"+ assert kw["adapter_factory"] is YuanbaoAdapter+ assert kw["standalone_sender_fn"] is _standalone_send+ assert kw["required_env"] == ["YUANBAO_APP_ID", "YUANBAO_APP_SECRET"]+ assert kw["cron_deliver_env_var"] == "YUANBAO_HOME_CHANNEL"+ assert kw["install_hint"] == "Yuanbao: websockets not installed. Run: pip install websockets"+ # /update was never allowed from Yuanbao (absent from _UPDATE_ALLOWED_PLATFORMS).+ assert kw["allow_update_command"] is False+ assert callable(kw["setup_fn"]) and callable(kw["is_connected"])++ from gateway.run import _BUILTIN_ADAPTERS+ from hermes_cli.gateway_setup_wizard import _PLATFORMS+ from tools import send_message_tool as smt+ assert Platform.YUANBAO not in _BUILTIN_ADAPTERS+ assert all(p["key"] != "yuanbao" for p in _PLATFORMS)+ assert "yuanbao" not in smt._CHUNKED_ROUTES+ assert "yuanbao" in smt._PLUGIN_STANDALONE_MEDIAdiff --git a/tests/gateway/test_yuanbao_proto.py b/tests/gateway/test_yuanbao_proto.pyindex cfee6551577..6280c7c6517 100644--- a/tests/gateway/test_yuanbao_proto.py+++ b/tests/gateway/test_yuanbao_proto.py@@ -20,7 +20,7 @@ if _REPO_ROOT not in sys.path:sys.path.insert(0, _REPO_ROOT)import pytest-from gateway.platforms.yuanbao_proto import (+from plugins.platforms.yuanbao.yuanbao_proto import (# 基础工具_encode_varint,_decode_varint,@@ -217,7 +217,7 @@ class TestDecodeInboundPush:text: str = "Hello!",) -> bytes:"""手工构造 InboundMessagePush bytes(与 proto 字段顺序一致)"""- from gateway.platforms.yuanbao_proto import (+ from plugins.platforms.yuanbao.yuanbao_proto import (_encode_field, _encode_string, _encode_message,_encode_varint, WT_LEN, WT_VARINT,)@@ -263,7 +263,7 @@ class TestDecodeInboundPush:assert result is not None or result is None # 不崩溃即可def test_multiple_msg_body_elements(self):- from gateway.platforms.yuanbao_proto import (+ from plugins.platforms.yuanbao.yuanbao_proto import (_encode_field, _encode_message, WT_LEN,)el1 = _encode_msg_body_element(@@ -409,7 +409,7 @@ class TestEndToEnd:assert dec["head"]["msg_id"] == "e2e-001"# 从 biz payload 中读取 to_account 和 msg_body- from gateway.platforms.yuanbao_proto import (+ from plugins.platforms.yuanbao.yuanbao_proto import (_get_string, _get_repeated_bytes)biz = dec["data"]diff --git a/tests/gateway/test_yuanbao_reconnect_set_active.py b/tests/gateway/test_yuanbao_reconnect_set_active.pyindex 608aa0e4750..77d685eb4e5 100644--- a/tests/gateway/test_yuanbao_reconnect_set_active.py+++ b/tests/gateway/test_yuanbao_reconnect_set_active.py@@ -17,7 +17,7 @@ if _REPO_ROOT not in sys.path:sys.path.insert(0, _REPO_ROOT)import pytest-from gateway.platforms.yuanbao import (+from plugins.platforms.yuanbao.adapter import (YuanbaoAdapter,ConnectionManager,)@@ -52,15 +52,15 @@ async def test_do_reconnect_calls_set_active_on_success():with (patch.object(cm, "_cleanup_ws", new_callable=AsyncMock),patch(- "gateway.platforms.yuanbao.SignManager.force_refresh",+ "plugins.platforms.yuanbao.adapter.SignManager.force_refresh",new_callable=AsyncMock,return_value={"bot_id": "test_bot", "token": "test_token"},),- patch("gateway.platforms.yuanbao.websockets.connect", new_callable=AsyncMock, return_value=mock_ws),+ patch("plugins.platforms.yuanbao.adapter.websockets.connect", new_callable=AsyncMock, return_value=mock_ws),patch.object(cm, "_authenticate", new_callable=AsyncMock, return_value=True),patch.object(cm, "_heartbeat_loop", new_callable=AsyncMock),patch.object(cm, "_receive_loop", new_callable=AsyncMock),- patch("gateway.platforms.yuanbao.MAX_RECONNECT_ATTEMPTS", 1),+ patch("plugins.platforms.yuanbao.adapter.MAX_RECONNECT_ATTEMPTS", 1),):# Clear any existing active instanceYuanbaoAdapter.set_active(None)@@ -85,11 +85,11 @@ async def test_do_reconnect_does_not_set_active_on_failure():with (patch.object(cm, "_cleanup_ws", new_callable=AsyncMock),patch(- "gateway.platforms.yuanbao.SignManager.force_refresh",+ "plugins.platforms.yuanbao.adapter.SignManager.force_refresh",new_callable=AsyncMock,side_effect=Exception("auth failed"),),- patch("gateway.platforms.yuanbao.MAX_RECONNECT_ATTEMPTS", 1),+ patch("plugins.platforms.yuanbao.adapter.MAX_RECONNECT_ATTEMPTS", 1),):# Clear any existing active instanceYuanbaoAdapter.set_active(None)diff --git a/tests/gateway/test_yuanbao_secret_scope.py b/tests/gateway/test_yuanbao_secret_scope.pyindex 0e662280f0b..6065497670a 100644--- a/tests/gateway/test_yuanbao_secret_scope.py+++ b/tests/gateway/test_yuanbao_secret_scope.py@@ -10,7 +10,7 @@ import pytestfrom agent import secret_scopefrom gateway.config import PlatformConfig-from gateway.platforms.yuanbao import AccessPolicy, YuanbaoAdapter+from plugins.platforms.yuanbao.adapter import AccessPolicy, YuanbaoAdapter@pytest.fixture()diff --git a/tests/gateway/test_yuanbao_shutdown.py b/tests/gateway/test_yuanbao_shutdown.pyindex 9db65469207..d382f99b7b2 100644--- a/tests/gateway/test_yuanbao_shutdown.py+++ b/tests/gateway/test_yuanbao_shutdown.py@@ -23,7 +23,7 @@ if _REPO_ROOT not in sys.path:import pytestfrom gateway.config import PlatformConfig-from gateway.platforms.yuanbao import (+from plugins.platforms.yuanbao.adapter import (YuanbaoAdapter,ConnectionManager,WS_CLOSE_TIMEOUT_S,diff --git a/tests/plugins/test_multiplex_plugin_cache_scope.py b/tests/plugins/test_multiplex_plugin_cache_scope.pyindex 80363083df0..31245b6f27d 100644--- a/tests/plugins/test_multiplex_plugin_cache_scope.py+++ b/tests/plugins/test_multiplex_plugin_cache_scope.py@@ -196,7 +196,7 @@ def test_disk_cleanup_protected_cron_paths_follow_the_active_home(homes):def test_yuanbao_active_adapter_resolves_per_profile(homes, monkeypatch):"""Each profile's turn reads back its own adapter; the unscoped slot still serves single-profile."""from gateway.config import PlatformConfig- from gateway.platforms.yuanbao import YuanbaoAdapter+ from plugins.platforms.yuanbao.adapter import YuanbaoAdaptera, b = homescfg = PlatformConfig(enabled=True, extra={"app_id": "x", "app_secret": "y"})