From 3b3de01a54215979d93b4ebcc8f4ef622ca28f41 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 5 Sep 2026 09:02:41 +0800 Subject: [PATCH] fix(notification): skip unsupported DingTalk command registration --- app/modules/dingtalk/__init__.py | 6 ++++++ tests/test_dingtalk.py | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/modules/dingtalk/__init__.py b/app/modules/dingtalk/__init__.py index 85341a791..15ccc41a4 100644 --- a/app/modules/dingtalk/__init__.py +++ b/app/modules/dingtalk/__init__.py @@ -44,6 +44,12 @@ class DingTalkModule(_MessageChannelModuleBase[DingTalk]): """钉钉启用状态由通知渠道配置统一管理。""" return None + def _commands_enabled(self, config: Optional[dict]) -> bool: + """ + 钉钉自定义机器人没有命令注册或删除 API,跳过基类命令处理。 + """ + return False + def post_message(self, message: Message, **kwargs) -> None: """向所有匹配消息范围的钉钉配置发送普通通知。""" for conf in self.get_configs().values(): diff --git a/tests/test_dingtalk.py b/tests/test_dingtalk.py index 491cc6c8c..1043046db 100644 --- a/tests/test_dingtalk.py +++ b/tests/test_dingtalk.py @@ -111,6 +111,19 @@ def test_module_routes_matching_notifications_to_dingtalk_client(monkeypatch) -> client.send_msg.assert_called_once() +def test_module_skips_unsupported_command_registration(monkeypatch) -> None: + """钉钉机器人不支持命令 API 时应跳过基类命令注册流程。""" + module = DingTalkModule() + config = SimpleNamespace(name="家庭群", config={}) + get_instance = Mock() + monkeypatch.setattr(module, "get_configs", lambda: {config.name: config}) + monkeypatch.setattr(module, "get_instance", get_instance) + + module.register_commands({"/version": {"description": "当前版本"}}) + + get_instance.assert_not_called() + + def test_dingtalk_channel_declares_markdown_image_and_link_capabilities() -> None: """能力表应允许通用消息层保留钉钉支持的富文本字段。""" for capability in (