refactor: WebSocketChannel accepts injected http_handler, update all tests

This commit is contained in:
chengyongru
2026-06-02 17:14:38 +08:00
committed by Xubin Ren
parent 22673c2a27
commit e5eb08e3e5
6 changed files with 160 additions and 104 deletions
@@ -18,8 +18,10 @@ import pytest
from nanobot.channels.websocket import (
WebSocketChannel,
WebSocketConfig,
_extract_data_url_mime,
)
from nanobot.webui.ws_http import GatewayHTTPHandler
def _tiny_png_data_url() -> str:
@@ -41,10 +43,19 @@ def _data_url(mime: str, payload: bytes) -> str:
def _make_channel() -> WebSocketChannel:
bus = MagicMock()
bus.publish_inbound = AsyncMock()
channel = WebSocketChannel(
{"enabled": True, "allowFrom": ["*"], "websocketRequiresToken": False},
bus,
cfg = {"enabled": True, "allowFrom": ["*"], "websocketRequiresToken": False}
parsed = WebSocketConfig.model_validate(cfg)
handler = GatewayHTTPHandler(
config=parsed,
session_manager=None,
static_dist_path=None,
workspace_path=Path.cwd(),
runtime_model_name=None,
runtime_surface="browser",
runtime_capabilities_overrides=None,
bus=bus,
)
channel = WebSocketChannel(cfg, bus, http_handler=handler)
channel._handle_message = AsyncMock() # type: ignore[method-assign]
return channel