refactor(events): unify scoped runtime notifications across clients (#5670)

* refactor(events): unify scoped runtime notifications across clients

* style(tests): sort auto-compaction event imports

* refactor(events): scope connections and remove retry callback plumbing

* docs: remove runtime notification design write-up

* refactor(bus): route operation events through the message bus

* fix(channels): isolate outbound sends by destination

* style(events): group shared notification imports

* refactor(events): converge runtime and hook delivery on MessageBus

* test(events): migrate fixtures to unified message bus
This commit is contained in:
chengyongru authored and GitHub committed 2026-09-06 02:11:19 +08:00
1 parent 3495281282
commit 192e2e90dc
78 files changed
+1620 -1194

No files matched your search

@@ -12,8 +12,10 @@ import pytest
from nanobot.bus.events import OutboundMessage
from nanobot.bus.queue import MessageBus
from nanobot.channels.manager import ChannelManager
from nanobot.channels.websocket import runtime
from nanobot.channels.websocket.runtime import WebSocketChannel, WebSocketConfig
from nanobot.config.schema import Config
from nanobot.webui.gateway_services import build_gateway_services
@@ -104,6 +106,39 @@ async def _wait_for_retire_tasks(channel: WebSocketChannel) -> None:
await asyncio.sleep(0)
@pytest.mark.asyncio
async def test_message_bus_delivers_to_ten_tuis_with_one_blocked_connection() -> None:
channel = _channel()
bus = MessageBus()
config = Config.model_validate({"channels": {"websocket": {"enabled": False}}})
manager = ChannelManager(config, bus)
manager.channels["websocket"] = channel
connections = [_RecordingConnection(block_first_send=i == 0) for i in range(10)]
for i, connection in enumerate(connections):
channel._attach(cast(Any, connection), f"chat-{i}")
dispatcher = asyncio.create_task(manager._dispatch_outbound())
try:
for text in ("first", "last"):
for i in range(10):
await bus.publish_outbound(_message(f"chat-{i}", text))
await asyncio.wait_for(connections[0].send_started.wait(), 2)
for connection in connections[1:]:
assert await _next_text(connection) == "first"
assert await _next_text(connection) == "last"
assert connections[0].sent.empty()
connections[0].release_send.set()
assert await _next_text(connections[0]) == "first"
assert await _next_text(connections[0]) == "last"
finally:
dispatcher.cancel()
await asyncio.gather(dispatcher, return_exceptions=True)
for connection in connections:
await channel._cleanup_connection(cast(Any, connection))
assert not manager._outbound_tasks
assert not manager._outbound_tails
assert not channel._connection_outbound
@pytest.mark.asyncio
async def test_slow_tui_does_not_block_a_different_topic() -> None:
channel = _channel()