Skip to content

The agent that grows with you

fix(qqbot): keep the plugin a pure move

Teknium9189f6c69bdb
diff --git a/plugins/platforms/qqbot/plugin.yaml b/plugins/platforms/qqbot/plugin.yaml
index b62b8a39fef..cad38a87002 100644
--- a/plugins/platforms/qqbot/plugin.yaml
+++ b/plugins/platforms/qqbot/plugin.yaml
@@ -1,4 +1,4 @@
-name: qqbot
+name: qqbot-platform
label: QQ Bot
kind: platform
version: 1.0.0
diff --git a/plugins/platforms/qqbot/register.py b/plugins/platforms/qqbot/register.py
index 1b1bb59aa1a..63ea214d6eb 100644
--- a/plugins/platforms/qqbot/register.py
+++ b/plugins/platforms/qqbot/register.py
@@ -1,4 +1,4 @@
-"""QQ Bot platform plugin: env/YAML seeding, interactive setup, and registry entry.
+"""QQ Bot platform plugin: interactive setup and registry entry.
The adapter stays in ``adapter.py``. This module is the only thing ``__init__``
exports, so importing the package registers the platform and does not open a portal
@@ -7,37 +7,17 @@ connection.
from __future__ import annotations
-from typing import Any, Optional
+from typing import Optional
-from gateway.platforms._shared import apply_yaml_bridge, get_scoped_secret
+from gateway.platforms._shared import get_scoped_secret
from .adapter import QQAdapter, check_qq_requirements
-from .constants import MAX_MESSAGE_LENGTH
-
-_PLATFORM_HINT = (
- "You are on QQ, a popular Chinese messaging platform. QQ supports markdown formatting "
- "and emoji. You can send media files natively: include MEDIA:/absolute/path/to/file in "
- "your response. Images are sent as native photos, and other files arrive as downloadable documents."
-)
-
-_YAML_BRIDGE = (
- ("app_id", "QQ_APP_ID", "str"),
- ("client_secret", "QQ_CLIENT_SECRET", "str"),
- ("allow_from", "QQ_ALLOWED_USERS", "csv"),
- ("group_allow_from", "QQ_GROUP_ALLOWED_USERS", "csv"),
- ("markdown_support", "QQ_MARKDOWN_SUPPORT", "lower"),
-)
-_YAML_EXTRA_KEYS = ("dm_policy", "group_policy", "group_allowed_chats", "stt", "sandbox")
def _scoped(name: str) -> str:
return str(get_scoped_secret(name, "") or "").strip()
-def _truthy(raw: str) -> bool:
- return raw.lower() in {"1", "true", "yes", "on"}
-
-
def _credentials_configured(extra: Optional[dict] = None) -> bool:
extra = extra or {}
app_id = str(extra.get("app_id") or "").strip() or _scoped("QQ_APP_ID")
@@ -45,39 +25,6 @@ def _credentials_configured(extra: Optional[dict] = None) -> bool:
return bool(app_id and secret)
-def env_enablement() -> Optional[dict]:
- """Seed ``platforms.qqbot.extra`` from the profile's QQ env. ``None`` when the bot
- is not configured, so importing the plugin never enables a connect loop."""
- if not _credentials_configured():
- return None
- seed: dict[str, Any] = {"app_id": _scoped("QQ_APP_ID"), "client_secret": _scoped("QQ_CLIENT_SECRET")}
- if allow := _scoped("QQ_ALLOWED_USERS"):
- seed["allow_from"] = allow
- if groups := _scoped("QQ_GROUP_ALLOWED_USERS"):
- seed["group_allow_from"] = groups
- if markdown := _scoped("QQ_MARKDOWN_SUPPORT"):
- seed["markdown_support"] = _truthy(markdown)
- chat_id = _scoped("QQBOT_HOME_CHANNEL") or _scoped("QQ_HOME_CHANNEL")
- name = _scoped("QQBOT_HOME_CHANNEL_NAME") or _scoped("QQ_HOME_CHANNEL_NAME")
- thread_id = _scoped("QQBOT_HOME_CHANNEL_THREAD_ID") or _scoped("QQ_HOME_CHANNEL_THREAD_ID")
- if chat_id:
- home = {"chat_id": chat_id, "name": name or "Home"}
- if thread_id:
- home["thread_id"] = thread_id
- seed["home_channel"] = home
- return seed
-
-
-def apply_yaml_config(_yaml_cfg: dict, platform_cfg: dict) -> Optional[dict]:
- if not isinstance(platform_cfg, dict):
- return None
- seeded = apply_yaml_bridge(platform_cfg, _YAML_BRIDGE) or {}
- for key in _YAML_EXTRA_KEYS:
- if key in platform_cfg:
- seeded[key] = platform_cfg[key]
- return seeded or None
-
-
def is_connected(pconfig) -> bool:
extra = getattr(pconfig, "extra", None) or {}
return _credentials_configured(extra)
@@ -187,18 +134,13 @@ def register(ctx) -> None:
label="QQ Bot",
adapter_factory=QQAdapter,
check_fn=check_qq_requirements,
- validate_config=is_connected,
is_connected=is_connected,
required_env=["QQ_APP_ID", "QQ_CLIENT_SECRET"],
- install_hint="aiohttp and httpx are required. Run: hermes pm repair",
+ install_hint="QQBot: aiohttp/httpx missing or QQ_APP_ID/QQ_CLIENT_SECRET not configured",
setup_fn=setup_qqbot,
allowed_users_env="QQ_ALLOWED_USERS",
allow_all_env="QQ_ALLOW_ALL_USERS",
- max_message_length=MAX_MESSAGE_LENGTH,
emoji="🐧",
- platform_hint=_PLATFORM_HINT,
- env_enablement_fn=env_enablement,
- apply_yaml_config_fn=apply_yaml_config,
cron_deliver_env_var="QQBOT_HOME_CHANNEL",
standalone_sender_fn=standalone_send,
)
diff --git a/plugins/platforms/qqbot/send.py b/plugins/platforms/qqbot/send.py
index 5c594fe346b..996107e153c 100644
--- a/plugins/platforms/qqbot/send.py
+++ b/plugins/platforms/qqbot/send.py
@@ -245,9 +245,3 @@ async def send_qqbot(pconfig, chat_id, message, media_files=None, caption=None,
return await _qqbot_send_text_message(client, headers, chat_id, message or "")
except Exception as e:
return _error(f"QQBot send failed: {e}")
-
-
-
-
-# Tests and older call sites use this name.
-_send_qqbot = send_qqbot
diff --git a/tests/plugins/platforms/test_qqbot_plugin.py b/tests/plugins/platforms/test_qqbot_plugin.py
index fb73a47ecce..d2e68890b38 100644
--- a/tests/plugins/platforms/test_qqbot_plugin.py
+++ b/tests/plugins/platforms/test_qqbot_plugin.py
@@ -13,46 +13,38 @@ def _clear_qq(monkeypatch):
monkeypatch.delenv(key, raising=False)
-def test_unconfigured_plugin_does_not_enable(monkeypatch):
+def test_register_shape():
+ """The plugin registers the same identity/env/routing the core table carried."""
+ from gateway.platform_registry import PlatformEntry
+ from plugins.platforms.qqbot import register
+ from plugins.platforms.qqbot.adapter import QQAdapter, check_qq_requirements
+ from plugins.platforms.qqbot.register import setup_qqbot, standalone_send
+
+ captured = {}
+
+ class _Ctx:
+ def register_platform(self, **kwargs):
+ captured.update(kwargs)
+
+ register(_Ctx())
+ entry = PlatformEntry(**captured)
+ assert entry.name == "qqbot" and entry.label == "QQ Bot" and entry.emoji == "🐧"
+ assert entry.adapter_factory is QQAdapter and entry.check_fn is check_qq_requirements
+ assert entry.required_env == ["QQ_APP_ID", "QQ_CLIENT_SECRET"]
+ assert entry.allowed_users_env == "QQ_ALLOWED_USERS" and entry.allow_all_env == "QQ_ALLOW_ALL_USERS"
+ assert entry.cron_deliver_env_var == "QQBOT_HOME_CHANNEL"
+ assert entry.setup_fn is setup_qqbot and entry.standalone_sender_fn is standalone_send
+ # send_message never chunked QQ text before the move; the REST sender truncates itself.
+ assert entry.max_message_length == 0
+
+
+def test_is_connected_needs_both_credentials(monkeypatch):
_clear_qq(monkeypatch)
- from plugins.platforms.qqbot.register import env_enablement
-
- assert env_enablement() is None
-
-
-def test_group_allowlist_and_home_seed(monkeypatch):
- _clear_qq(monkeypatch)
- monkeypatch.setenv("QQ_APP_ID", "app")
- monkeypatch.setenv("QQ_CLIENT_SECRET", "sec")
- monkeypatch.setenv("QQ_GROUP_ALLOWED_USERS", "group-1, group-2")
- monkeypatch.setenv("QQBOT_HOME_CHANNEL", "home-chat")
- monkeypatch.setenv("QQBOT_HOME_CHANNEL_NAME", "Lounge")
- monkeypatch.setenv("QQBOT_HOME_CHANNEL_THREAD_ID", "thread-9")
- monkeypatch.setenv("QQ_HOME_CHANNEL", "ignored")
- from plugins.platforms.qqbot.register import env_enablement
-
- seed = env_enablement()
-
- assert seed["app_id"] == "app"
- assert seed["group_allow_from"] == "group-1, group-2"
- assert seed["home_channel"] == {
- "chat_id": "home-chat", "name": "Lounge", "thread_id": "thread-9",
- }
-
-
-def test_qq_prefixed_home_channel_still_seeds(monkeypatch):
- _clear_qq(monkeypatch)
- monkeypatch.setenv("QQ_APP_ID", "app")
- monkeypatch.setenv("QQ_CLIENT_SECRET", "sec")
- monkeypatch.setenv("QQ_HOME_CHANNEL", "renamed-chat")
- monkeypatch.setenv("QQ_HOME_CHANNEL_THREAD_ID", "thread-2")
- from plugins.platforms.qqbot.register import env_enablement
-
- seed = env_enablement()
+ from gateway.config import PlatformConfig
+ from plugins.platforms.qqbot.register import is_connected
- assert seed["home_channel"] == {
- "chat_id": "renamed-chat", "name": "Home", "thread_id": "thread-2",
- }
+ assert is_connected(PlatformConfig(enabled=True, extra={"app_id": "a"})) is False
+ assert is_connected(PlatformConfig(enabled=True, extra={"app_id": "a", "client_secret": "s"})) is True
def test_qqbot_platform_hint_comes_from_the_builtin_table():