fix(models): synchronize canonical runtime selection

This commit is contained in:
Xubin Ren
2026-08-16 11:50:56 +08:00
parent 0a6ee1c539
commit 731b8fc2ed
15 changed files with 265 additions and 16 deletions
+32
View File
@@ -10,6 +10,7 @@ from nanobot.bus.runtime_events import (
SessionTurnStarted,
TurnCompleted,
TurnRunStatusChanged,
TurnRuntimeAdmitted,
)
@@ -123,6 +124,37 @@ async def test_runtime_event_publisher_consumes_turn_metadata_on_complete() -> N
assert second.runtime is None
@pytest.mark.asyncio
async def test_runtime_event_publisher_exposes_admitted_runtime() -> None:
bus = RuntimeEventBus()
seen: list[object] = []
publisher = RuntimeEventPublisher(bus)
msg = InboundMessage(
channel="websocket",
sender_id="user",
chat_id="chat-a",
content="hello",
)
runtime = object()
bus.subscribe(seen.append)
await publisher.turn_runtime_admitted(msg, "websocket:chat-a", runtime) # type: ignore[arg-type]
await publisher.turn_completed(
channel="websocket",
chat_id="chat-a",
session_key="websocket:chat-a",
metadata=None,
)
admitted = seen[0]
completed = seen[1]
assert isinstance(admitted, TurnRuntimeAdmitted)
assert admitted.runtime is runtime
assert admitted.context.chat_id == "chat-a"
assert isinstance(completed, TurnCompleted)
assert completed.runtime is runtime
@pytest.mark.asyncio
async def test_runtime_event_publisher_emits_persisted_turn_attributes() -> None:
bus = RuntimeEventBus()