Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gateway/platforms/weixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ async def _process_message(self, message: Dict[str, Any]) -> None:
# Secondary content-fingerprint dedup: upstream re-sends identical text under new message_ids.
item_list = message.get("item_list") or []
text = _extract_text(item_list)
if text and self._dedup.is_duplicate(f"content:{sender_id}:{hashlib.md5(text.encode()).hexdigest()}"):
if text and not text.startswith("/") and self._dedup.is_duplicate(f"content:{sender_id}:{hashlib.md5(text.encode()).hexdigest()}"):
logger.debug("[%s] Content-dedup: skipping duplicate message from %s", self.name, sender_id)
return
chat_type, effective_chat_id = _guess_chat_type(message, self._account_id)
Expand Down
35 changes: 35 additions & 0 deletions tests/gateway/test_weixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,41 @@ async def _drive():
event = adapter.handle_message.await_args[0][0]
assert event.text == "hello world"

def test_slash_commands_bypass_content_dedup(self):
"""Slash commands with different message IDs bypass content dedup."""
adapter = _make_adapter()
adapter._poll_session = object()
adapter.handle_message = AsyncMock()
adapter._text_batch_delay_seconds = 0.05
adapter._text_batch_split_delay_seconds = 0.05
base_msg = {
"from_user_id": "wxid_user1",
"item_list": [{"type": 1, "text_item": {"text": "/approve"}}],
}
async def _drive():
await adapter._process_message({**base_msg, "message_id": "msg-1"})
await adapter._process_message({**base_msg, "message_id": "msg-2"})
await asyncio.sleep(0.2)
asyncio.run(_drive())
assert adapter.handle_message.await_count == 2
texts = [call.args[0].text for call in adapter.handle_message.await_args_list]
assert texts == ["/approve", "/approve"]

def test_slash_command_msg_id_dedup_still_applies(self):
"""Message ID dedup still applies to slash commands."""
adapter = _make_adapter()
adapter._poll_session = object()
adapter.handle_message = AsyncMock()
base_msg = {
"from_user_id": "wxid_user1",
"item_list": [{"type": 1, "text_item": {"text": "/approve"}}],
}
async def _drive():
await adapter._process_message({**base_msg, "message_id": "same-id"})
await adapter._process_message({**base_msg, "message_id": "same-id"})
asyncio.run(_drive())
assert adapter.handle_message.await_count == 1


class TestWeixinTextDebounce:
"""Text-debounce batching for rapid multi-message bursts (issue #35301).
Expand Down