The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(dingtalk): guard edits when AI Cards are unavailable
KoNit-K61f99d6d3ed3
diff --git a/plugins/platforms/dingtalk/adapter.py b/plugins/platforms/dingtalk/adapter.pyindex a1165ef9cc6..fabfe31f480 100644--- a/plugins/platforms/dingtalk/adapter.py+++ b/plugins/platforms/dingtalk/adapter.py@@ -480,6 +480,8 @@ class DingTalkAdapter(BasePlatformAdapter):async def edit_message(self, chat_id: str, message_id: str, content: str, *, finalize: bool = False) -> SendResult:"""Stream updated content to an AI Card; ``message_id`` is the creating ``send()``'s out_track_id (callers track their own ids so parallel flows on one chat don't interfere)."""+ if not self.SUPPORTS_MESSAGE_EDITING:+ return SendResult(success=False, error="AI Cards are not configured for message editing")token = await self._get_access_token() if message_id else Noneif not token:return SendResult(success=False, error="message_id required" if not message_id else "No access token")diff --git a/tests/gateway/test_dingtalk.py b/tests/gateway/test_dingtalk.pyindex 9b0df151648..129a111f7fc 100644--- a/tests/gateway/test_dingtalk.py+++ b/tests/gateway/test_dingtalk.py@@ -695,6 +695,35 @@ class TestCardLifecycle:)assert "chat-1" in fired+ @pytest.mark.asyncio+ @pytest.mark.parametrize("missing", ["template", "sdk"])+ async def test_edit_message_rejects_when_ai_cards_are_unavailable(self, missing):+ """Edits must not access the card SDK on webhook-only installations."""+ from plugins.platforms.dingtalk.adapter import DingTalkAdapter++ extra = {} if missing == "template" else {"card_template_id": "tmpl-1"}+ adapter = DingTalkAdapter(PlatformConfig(enabled=True, extra=extra))+ card_sdk = None if missing == "sdk" else MagicMock()+ adapter._card_sdk = card_sdk+ adapter._get_access_token = AsyncMock(return_value="token")++ result = await adapter.edit_message("chat-1", "track-1", "heartbeat")++ assert not result.success+ assert result.error == "AI Cards are not configured for message editing"+ adapter._get_access_token.assert_not_awaited()+ if card_sdk is not None:+ assert card_sdk.mock_calls == []++ @pytest.mark.asyncio+ async def test_edit_message_streams_when_ai_cards_are_configured(self, adapter_with_card):+ """Configured cards retain the streaming edit path."""+ result = await adapter_with_card.edit_message("chat-1", "track-1", "heartbeat")++ assert result.success+ assert result.message_id == "track-1"+ adapter_with_card._card_sdk.streaming_update_with_options_async.assert_awaited_once()+# ---------------------------------------------------------------------------# AI Card Tests