feat(server): 暴露 /api/sessions/{sid}/ws 进度流端点(+websockets 依赖)

This commit is contained in:
lhl
2026-08-29 11:55:45 +08:00
parent 8493bea589
commit 61611b6b8a
4 changed files with 45 additions and 1 deletions
+24
View File
@@ -0,0 +1,24 @@
import threading
from fastapi.testclient import TestClient
from genesis.server.app import create_app
from genesis.server.hub import hub
from genesis.server.store import SessionStore
def _client(tmp_path):
return TestClient(create_app(
store=SessionStore(db_path=str(tmp_path / "s.db")),
data_root=str(tmp_path / "data"), engine="fake"))
def test_ws_streams_progress(tmp_path):
c = _client(tmp_path)
def trigger():
hub.emit("ws-s1", {"type": "progress", "step": "gen", "status": "ok", "detail": "生成中"})
with c.websocket_connect("/api/sessions/ws-s1/ws") as ws:
threading.Thread(target=trigger).start()
data = ws.receive_json()
assert data["type"] == "progress"
assert data["step"] == "gen"