Files
DeepTutor/tests/api/test_unified_ws_workspace_binding.py
Bingxi Zhao (Frank) da856ad670 release: v1.6.9
Ship folder-based workspaces and data migration, daily practice, redesigned
provider and model settings, and streaming conversation improvements.
Synchronize README translations and document the archive/permanent-delete
upgrade behavior in assets/releases/ver1-6-9.md.

Reduce initial JavaScript by deduplicating English resources and loading
animation features after hydration. Keep the existing route size budgets.
Update regression fixtures and browser audits for scoped URLs and the new
settings and learning interfaces.
2026-09-21 02:30:40 +08:00

76 lines
2.3 KiB
Python

"""The WebSocket boundary must preserve omission separately from explicit null."""
import json
from types import SimpleNamespace
from fastapi import WebSocketDisconnect
import pytest
from deeptutor.api.routers.unified_ws import unified_websocket
@pytest.mark.asyncio
@pytest.mark.parametrize("binding", [{}, {"workspace_id": None}, {"workspace_id": "ws_test"}])
async def test_start_turn_preserves_workspace_and_parent_field_presence(monkeypatch, binding):
captured = []
async def authenticate(_ws):
return None
class Turns:
async def start_turn(self, payload):
captured.append(payload)
return {"id": "chat"}, {"id": "turn"}
async def subscribe_turn(self, *_args, **_kwargs):
if False:
yield None
class Socket:
app = SimpleNamespace(
state=SimpleNamespace(application_container=SimpleNamespace(turns=Turns()))
)
def __init__(self):
self.incoming = iter(
[
{
"protocol_version": "2.0",
"type": "start_turn",
"content": "continue",
"session_id": "chat",
**binding,
},
{
"protocol_version": "2.0",
"type": "start_turn",
"content": "edit root",
"session_id": "chat",
"parent_message_id": None,
**binding,
},
]
)
async def accept(self):
pass
async def receive_text(self):
try:
return json.dumps(next(self.incoming))
except StopIteration:
raise WebSocketDisconnect()
async def send_text(self, _text):
pass
monkeypatch.setattr("deeptutor.api.routers.auth.ws_require_auth", authenticate)
await unified_websocket(Socket())
assert len(captured) == 2
for payload in captured:
assert ("workspace_id" in payload) == ("workspace_id" in binding)
if binding:
assert payload["workspace_id"] == binding["workspace_id"]
assert "parent_message_id" not in captured[0]
assert captured[1]["parent_message_id"] is None