refactor: subscribe to runtime event types

This commit is contained in:
chengyongru authored and Xubin Ren committed 2026-06-01 23:00:53 +08:00
1 parent 2f0e638bd1
commit 81370565e0
3 files changed
+96 -24

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
import pytest
from nanobot.bus.runtime_events import (
RuntimeEventBus,
RuntimeEventContext,
RuntimeModelChanged,
TurnRunStatusChanged,
)
@pytest.mark.asyncio
async def test_runtime_event_bus_filters_by_event_type() -> None:
bus = RuntimeEventBus()
seen: list[str] = []
async def handle_run_status(event: TurnRunStatusChanged) -> None:
seen.append(event.status)
bus.subscribe(handle_run_status, TurnRunStatusChanged)
await bus.publish(RuntimeModelChanged(model="m", model_preset=None))
await bus.publish(
TurnRunStatusChanged(
context=RuntimeEventContext(
channel="cli",
chat_id="direct",
session_key="cli:direct",
),
status="running",
)
)
assert seen == ["running"]
@pytest.mark.asyncio
async def test_runtime_event_bus_keeps_catch_all_subscription() -> None:
bus = RuntimeEventBus()
seen: list[str] = []
def handle_any(event) -> None:
seen.append(type(event).__name__)
bus.subscribe(handle_any)
await bus.publish(RuntimeModelChanged(model="m", model_preset=None))
assert seen == ["RuntimeModelChanged"]