mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-09-01 00:31:51 +03:00
fix(models): synchronize canonical runtime selection
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user