fix(WeiXin): resolve polling issues in WeiXin plugin

- Prevent repeated retries on expired sessions in the polling thread
- Stop sending messages to invalid agent sessions to eliminate noise logs and unnecessary requests
This commit is contained in:
xcosmosbox
2026-03-25 02:58:19 +08:00
committed by Xubin Ren
parent 3a9d6ea536
commit 9c872c3458
2 changed files with 67 additions and 2 deletions
+29
View File
@@ -1,4 +1,5 @@
import asyncio
from types import SimpleNamespace
from unittest.mock import AsyncMock
import pytest
@@ -123,6 +124,34 @@ async def test_send_without_context_token_does_not_send_text() -> None:
channel._send_text.assert_not_awaited()
@pytest.mark.asyncio
async def test_send_does_not_send_when_session_is_paused() -> None:
channel, _bus = _make_channel()
channel._client = object()
channel._token = "token"
channel._context_tokens["wx-user"] = "ctx-2"
channel._pause_session(60)
channel._send_text = AsyncMock()
await channel.send(
type("Msg", (), {"chat_id": "wx-user", "content": "pong", "media": [], "metadata": {}})()
)
channel._send_text.assert_not_awaited()
@pytest.mark.asyncio
async def test_poll_once_pauses_session_on_expired_errcode() -> None:
channel, _bus = _make_channel()
channel._client = SimpleNamespace(timeout=None)
channel._token = "token"
channel._api_post = AsyncMock(return_value={"ret": 0, "errcode": -14, "errmsg": "expired"})
await channel._poll_once()
assert channel._session_pause_remaining_s() > 0
@pytest.mark.asyncio
async def test_process_message_skips_bot_messages() -> None:
channel, bus = _make_channel()