mirror of
https://github.com/snowy-yang/qqbotsdk.git
synced 2026-10-21 10:08:50 +00:00
refactor!: EventQueue 收敛为单向业务事件通道,出站缓冲归 ws 适配器
协议分流后 reply_queue 只剩 WebsocketConnecter 一个使用者(emitter 不再 回流应答、webhook 完全不用),它已不是"连接层与分发层之间的通道",而是 ws 私有的出站缓冲,却仍挂在共享 EventQueue 上——queue.py 的模块注释 "连接层与分发层之间唯一的跨任务通道"对 reply_queue 不再成立。 删除 EventQueue.reply_queue 与 put_reply/get_reply,EventQueue 只承载 业务事件(op=0,单向)。ws 的出站帧改由 WebsocketConnecter 私有 _outbound 队列承载,heartbeat_helper 与协议应答生产者投递、reply_helper 单任务发送——维持 aiohttp ws 单写者不变量,生产者也不会被发送阻塞。 破坏性变更:EventQueue.reply_queue / put_reply / get_reply 不再存在 (这两个方法本就只由 SDK 内部使用,非用户面)。 文档同步 queue.py 注释、ARCHITECTURE(图与心跳/应答路径)、API 的 EventQueue 说明、CHANGELOG;测试 80 全绿,ruff/pyright 干净。
This commit is contained in:
1 parent
7accbd1ead
commit
4d19db24e1
6 files changed
+24
-23
No files matched your search
@@ -4,7 +4,7 @@ import pytest
|
||||
|
||||
from qqbotsdk.emitter import EventEmitter
|
||||
from qqbotsdk.events import Event
|
||||
from qqbotsdk.model import Opcode, payload_of
|
||||
from qqbotsdk.model import Opcode
|
||||
from qqbotsdk.payloads import GroupAtMessage
|
||||
from qqbotsdk.queue import EventQueue
|
||||
from qqbotsdk.session import Session
|
||||
@@ -40,16 +40,16 @@ async def test_handler_exception_is_isolated():
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_protocol_frame_never_reaches_business_handler():
|
||||
"""协议帧改由适配器的协议处理器就近处理,不再经 emitter 回流应答。"""
|
||||
queue = EventQueue()
|
||||
emitter = EventEmitter(queue)
|
||||
"""协议帧不进分发路径:即使注册了同名 handler 也不该被调用。"""
|
||||
emitter = EventEmitter()
|
||||
called: list[object] = []
|
||||
|
||||
@emitter.on(Opcode.HEARTBEAT)
|
||||
async def beat(_):
|
||||
return payload_of(Opcode.HEARTBEAT, 42)
|
||||
async def beat(d):
|
||||
called.append(d)
|
||||
|
||||
await emitter.emit({"op": Opcode.HEARTBEAT, "d": 0})
|
||||
assert queue.reply_queue.empty()
|
||||
assert called == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in new issue
Block a user