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
9 changes: 7 additions & 2 deletions gateway/platforms/qqbot/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,13 @@ def enforces_own_access_policy(self) -> bool:
# Connection lifecycle
# ------------------------------------------------------------------

async def connect(self) -> bool:
"""Authenticate, obtain gateway URL, and open the WebSocket."""
async def connect(self, *, is_reconnect: bool = False) -> bool:
"""Authenticate, obtain gateway URL, and open the WebSocket.

``is_reconnect`` is accepted for compatibility with the gateway's
common PlatformAdapter.connect() contract. QQBot manages resume vs.
cold identify internally from its stored session state.
"""
if not AIOHTTP_AVAILABLE:
message = "QQ startup failed: aiohttp not installed"
self._set_fatal_error("qq_missing_dependency", message, retryable=True)
Expand Down
14 changes: 14 additions & 0 deletions tests/gateway/test_qqbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,20 @@ def test_connect_uses_redirect_guard_hook(self):
assert kwargs.get("follow_redirects") is True
assert kwargs.get("event_hooks", {}).get("response") == [_ssrf_redirect_guard]

def test_connect_accepts_gateway_reconnect_flag(self):
"""QQBot must match BasePlatformAdapter.connect(is_reconnect=...)."""
from gateway.platforms.qqbot import QQAdapter

adapter = QQAdapter(_make_config(app_id="a", client_secret="b"))
adapter._ensure_token = mock.AsyncMock(side_effect=RuntimeError("stop after client creation"))

# Regression guard: gateway.run calls this exact keyword during cold
# boot and reconnect. QQBot may ignore the flag internally, but it must
# accept it to satisfy the platform adapter contract.
connected = asyncio.run(adapter.connect(is_reconnect=True))

assert connected is False


# ---------------------------------------------------------------------------
# WebSocket proxy handling
Expand Down