refactor: remove redundant comments and docstrings (#6527)

* refactor: remove redundant comments and docstrings

* fix(signal): annotate async context manager as a generator
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-30 13:07:03 +08:00
1 parent cb3ba45317
commit a4d2430140
922 files changed
+406 -7738

No files matched your search

@@ -1,9 +1,3 @@
"""Integration tests for the WebSocket channel using WsTestClient.
Complements the unit/lightweight tests in test_websocket_channel.py by covering
multi-client scenarios, edge cases, and realistic usage patterns.
"""
from __future__ import annotations
import asyncio
@@ -55,9 +49,6 @@ def bus() -> MagicMock:
return b
# -- Connection basics ----------------------------------------------------
@pytest.mark.asyncio
async def test_ready_event_fields(bus: MagicMock) -> None:
ch = _ch(bus, 29901)
@@ -99,9 +90,6 @@ async def test_each_connection_unique_chat_id(bus: MagicMock) -> None:
await t
# -- Inbound messages (client -> server) ----------------------------------
@pytest.mark.asyncio
async def test_plain_text(bus: MagicMock) -> None:
ch = _ch(bus, 29904)
@@ -185,9 +173,6 @@ async def test_messages_preserve_order(bus: MagicMock) -> None:
await t
# -- Outbound messages (server -> client) ---------------------------------
@pytest.mark.asyncio
async def test_server_send_message(bus: MagicMock) -> None:
ch = _ch(bus, 29909)
@@ -207,20 +192,17 @@ async def test_server_send_message(bus: MagicMock) -> None:
@pytest.mark.asyncio
async def test_server_send_tags_tool_hint_with_kind(bus: MagicMock) -> None:
"""Tool-hint progress events surface as ``kind: "tool_hint"``."""
ch = _ch(bus, 29919)
t = asyncio.create_task(ch.start())
try:
async with WsTestClient("ws://127.0.0.1:29919/", client_id="h") as c:
ready = await c.recv_ready()
# Plain reply: no "kind" field.
await ch.send(OutboundMessage(
channel="websocket", chat_id=ready.chat_id, content="hi",
))
plain = await c.recv_message()
assert plain.raw.get("kind") is None
# Tool-hint breadcrumb: kind == "tool_hint".
tool_start = {
"phase": "start", "call_id": "call-weather", "name": "weather",
"arguments": {"action": "get"},
@@ -248,7 +230,6 @@ async def test_server_send_tags_tool_hint_with_kind(bus: MagicMock) -> None:
assert result.text == ""
assert result.raw["tool_events"] == [tool_end]
# Generic progress (non-tool-hint) gets the softer "progress" label.
await ch.send(OutboundMessage(
channel="websocket", chat_id=ready.chat_id,
content="thinking…",
@@ -281,9 +262,6 @@ async def test_server_send_with_media_and_reply(bus: MagicMock) -> None:
await t
# -- Streaming ------------------------------------------------------------
@pytest.mark.asyncio
async def test_streaming_deltas_and_end(bus: MagicMock) -> None:
ch = _ch(bus, 29911, streaming=True)
@@ -329,9 +307,6 @@ async def test_interleaved_streams(bus: MagicMock) -> None:
await t
# -- Multi-client ---------------------------------------------------------
@pytest.mark.asyncio
async def test_independent_sessions(bus: MagicMock) -> None:
ch = _ch(bus, 29913)
@@ -410,7 +385,6 @@ async def test_disconnected_client_cleanup(bus: MagicMock) -> None:
try:
async with WsTestClient("ws://127.0.0.1:29914/", client_id="tmp") as c:
chat_id = (await c.recv_ready()).chat_id
# disconnected
await asyncio.sleep(0.1)
await ch.send(OutboundMessage(
channel="websocket", chat_id=chat_id, content="orphan",
@@ -421,9 +395,6 @@ async def test_disconnected_client_cleanup(bus: MagicMock) -> None:
await t
# -- Authentication -------------------------------------------------------
@pytest.mark.asyncio
async def test_static_token_accepted(bus: MagicMock) -> None:
ch = _ch(bus, 29915, token="secret")
@@ -457,24 +428,19 @@ async def test_token_issue_full_flow(bus: MagicMock) -> None:
websocketRequiresToken=True)
t = asyncio.create_task(ch.start())
try:
# no secret -> 401
_, status = await issue_token(port=29917, issue_path="/auth/token")
assert status == 401
# with secret -> token
token = await issue_token_ok(port=29917, issue_path="/auth/token", secret="s")
# no token -> 401
with pytest.raises(websockets.exceptions.InvalidStatus) as exc:
async with WsTestClient("ws://127.0.0.1:29917/ws", client_id="x"):
pass
assert exc.value.response.status_code == 401
# valid token -> ok
async with WsTestClient("ws://127.0.0.1:29917/ws", client_id="ok", token=token) as c:
assert (await c.recv_ready()).client_id == "ok"
# reuse -> 401
with pytest.raises(websockets.exceptions.InvalidStatus) as exc:
async with WsTestClient("ws://127.0.0.1:29917/ws", client_id="r", token=token):
pass
@@ -484,9 +450,6 @@ async def test_token_issue_full_flow(bus: MagicMock) -> None:
await t
# -- Path routing ---------------------------------------------------------
@pytest.mark.asyncio
async def test_custom_path(bus: MagicMock) -> None:
ch = _ch(bus, 29918, path="/my-chat")
@@ -525,9 +488,6 @@ async def test_trailing_slash_normalized(bus: MagicMock) -> None:
await t
# -- Edge cases -----------------------------------------------------------
@pytest.mark.asyncio
async def test_large_message(bus: MagicMock) -> None:
ch = _ch(bus, 29921)