docs(gateway): WS 帧门相关 11 个文件的注释改中文(只改注释,代码零字节改动)
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

主人 2026-10-03 拍板「注释一律中文」。本次先把本会话动过的文件就地翻;
不做全仓一次性翻译,存量按包分批排期(见 工作小结.md 待办)。

范围:ws_frame_scope.go / ws_frame_scope_test.go / broadcast.go / ws_hub_turn.go /
ws_hub_message_event.go / session_read.go / server.go / ws_hub_stream_scope_test.go /
history_write_broadcast_test.go / mood_test.go / extra_test.go
含中文的整行注释 18 → 382。

校验(判据 = "只改注释、零代码字节改动"):
- `git diff -U0 | 排除 +++/--- | 排除注释行/空行/行尾注释` → 为空
- 独立实现:两侧剥掉注释后逐行比对代码文本 → 11/11 文件全等,不一致数 0
- 行尾注释 7 行逐条列出,代码列与原文逐字节相同(gofmt 未要求重排)
- gofmt -l 干净;全树 go build/vet 绿;go test ./... = 58 包 ok / 0 FAIL;
  linux/amd64 + darwin/arm64 交叉编译绿
语义未删减:部分折行英文长句合并为更少行,故整行注释数 438 → 399。
This commit is contained in:
AskaEth committed 2026-10-03 22:07:56 +08:00
1 parent 770a83c3fb
commit fe1ff33115
11 files changed
+392 -431

No files matched your search

@@ -13,8 +13,8 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/model"
)
// scopeStreamAdapter is a model.Adapter that emits two text deltas so a test can
// drive the real loop and observe the framed events it produces.
// scopeStreamAdapter 是一个 model.Adapter,发出两个文本增量,使测试
// 能驱动真实 loop 并观察它产出的成帧事件。
type scopeStreamAdapter struct{}
func (scopeStreamAdapter) Name() string { return "scope-test" }
@@ -31,10 +31,10 @@ func (scopeStreamAdapter) ChatStream(_ context.Context, _ model.Request, on func
return model.Response{Content: "Hel lo"}, nil
}
// newScopedStreamHub wires a hub to a real loop whose OnStream closure mirrors
// cmd/cyrene's streamChunk (publish the whole StreamEvent value to ws.stream), so
// a test exercises the production path OnStream → bus → relay → frame. It returns
// the hub and a registered fake connection.
// newScopedStreamHub 把 hub 接到真实 loop,其 OnStream 闭包与
// cmd/cyrene 的 streamChunk 一致(把整个 StreamEvent 值发布到
// ws.stream),因此测试走的是生产路径 OnStream → bus → relay → frame。
// 它返回 hub 与一个已注册的假连接。
func newScopedStreamHub(t *testing.T) (*hub, *wsConn) {
t.Helper()
b := bus.New()
@@ -58,10 +58,9 @@ func newScopedStreamHub(t *testing.T) (*hub, *wsConn) {
return hb, c
}
// readDeltas scans the connection's frames until want message.delta frames have
// arrived. The deltas reach the conn asynchronously through the bus while
// runTurn's own stream_end is sent straight to the conn, so a test cannot assume
// an order.
// readDeltas 扫描连接的帧,直到 want 个 message.delta 帧到达。增量经
// bus 异步到达该连接,而 runTurn 自己的 stream_end 是直接发给连接
// 的,因此测试不能假定顺序。
func readDeltas(t *testing.T, c *wsConn, want int) []wsEvent {
t.Helper()
var deltas []wsEvent
@@ -83,11 +82,11 @@ func readDeltas(t *testing.T, c *wsConn, want int) []wsEvent {
return deltas
}
// TestStreamFramesCarrySessionScope is the end-to-end lock for A1: a turn driven
// through the hub's runTurn must surface message.delta frames that carry the
// session and the turn id, so a client can route them to the active session. It
// runs the real loop instead of calling broadcastStream directly, which also
// proves the bus carries the new fields untouched — no publisher change needed.
// TestStreamFramesCarrySessionScope 是 A1 的端到端锁定:经 hub 的
// runTurn 驱动的一轮必须发出携带会话与轮次 id 的 message.delta 帧,
// 使客户端能把它们路由到活跃会话。它跑真实 loop 而不是直接调用
// broadcastStream,这同时证明 bus 原样携带了新字段 —— 无需改动
// 发布方。
func TestStreamFramesCarrySessionScope(t *testing.T) {
t.Parallel()
hb, c := newScopedStreamHub(t)
@@ -116,10 +115,9 @@ func TestStreamFramesCarrySessionScope(t *testing.T) {
}
}
// TestStreamFramesTurnScopeChangesPerTurn covers the orchestrated resume shape: a
// pending turn drained after the first one completes is a second runTurn call, so
// it must take a fresh turnId. Without that, deltas from the resumed turn would
// be indistinguishable from the previous turn's.
// TestStreamFramesTurnScopeChangesPerTurn 覆盖编排下的续跑形态:在
// 首轮完成之后被排空的待处理轮次是第二次 runTurn 调用,因此它必须
// 取新的 turnId。否则续跑轮次的增量与上一轮的将无法区分。
func TestStreamFramesTurnScopeChangesPerTurn(t *testing.T) {
t.Parallel()
hb, c := newScopedStreamHub(t)