docs(gateway): gateway 剩余文件注释改中文(逐行 1:1,代码零字节改动)
主人 2026-10-03 拍板「注释一律中文」;gateway 至此整包注释中文化完成(本会话共 3 批: 已推库 16 个文件 + 本批剩余文件)。 校验:机械校验(非注释改动行)= 空;剥注释后代码文本逐行比对全等(不一致文件数 0); 全树 go test ./... 58 包 ok / 0 FAIL;交叉编译绿。
This commit is contained in:
1 parent
91e8d7a029
commit
074ffc4ebf
73 files changed
+2529
-2529
No files matched your search
@@ -14,15 +14,15 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/trace"
|
||||
)
|
||||
|
||||
// These tests cover the only leg of the design/19 flow chain that had no test:
|
||||
// the producer's bus event → hub relay → outbound WS frame. The loop side is
|
||||
// pinned by internal/runtime/loop/flow_test.go; this pins the gateway relay AND
|
||||
// the wire field names the frontend's parseGraph reads, so a rename on either side
|
||||
// fails here instead of silently blanking the 全链路流程 page.
|
||||
// 这些测试覆盖 design/19 流程链中此前唯一没有测试的一段:
|
||||
// 生产者的 bus 事件 → hub 中继 → 下行 WS 帧。loop 一侧由
|
||||
// internal/runtime/loop/flow_test.go 钉住;这里钉住网关中继以及
|
||||
// 前端 parseGraph 所读的线上字段名,因此任一侧改名都会
|
||||
// 在这里失败,而不是静默让全链路流程页面变空。
|
||||
|
||||
// TestFlowGraphUpdateRelayedToWS publishes a real trace.RunGraph snapshot on the
|
||||
// producer subject (ws.graph_update) and asserts the client receives a
|
||||
// `graph_update` frame carrying the snapshot unchanged.
|
||||
// TestFlowGraphUpdateRelayedToWS 在生产主题(ws.graph_update)上
|
||||
// 发布真实的 trace.RunGraph 快照,并断言客户端收到一个
|
||||
// 原样携带该快照的 `graph_update` 帧。
|
||||
func TestFlowGraphUpdateRelayedToWS(t *testing.T) {
|
||||
env := newEnv(t, nil, false)
|
||||
tok := env.token(t, auth.RoleOwner)
|
||||
@@ -35,8 +35,8 @@ func TestFlowGraphUpdateRelayedToWS(t *testing.T) {
|
||||
defer conn.Close()
|
||||
_ = conn.SetReadDeadline(time.Now().Add(3 * time.Second))
|
||||
|
||||
// Round-trip a mode_switch first so the connection is registered before the
|
||||
// publish (same guard as TestWSUpgradeAndBroadcast).
|
||||
// 先往返一次 mode_switch,使连接在发布前已注册
|
||||
// (与 TestWSUpgradeAndBroadcast 相同的保护)。
|
||||
if err := conn.WriteJSON(wsInbound{Type: "mode_switch", Data: json.RawMessage(`{"mode":"chat"}`)}); err != nil {
|
||||
t.Fatalf("write mode_switch: %v", err)
|
||||
}
|
||||
@@ -61,7 +61,7 @@ func TestFlowGraphUpdateRelayedToWS(t *testing.T) {
|
||||
t.Fatalf("frame type = %q, want graph_update (frame=%s)", frame.Type, raw)
|
||||
}
|
||||
|
||||
// The relayed payload must be the snapshot verbatim — same JSON, not re-shaped.
|
||||
// 中继的载荷必须是快照原文 —— 同样的 JSON,未被重塑。
|
||||
want, err := json.Marshal(snap)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal snapshot: %v", err)
|
||||
@@ -71,10 +71,10 @@ func TestFlowGraphUpdateRelayedToWS(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestFlowGraphUpdateWireFields pins the JSON key names on every level of the
|
||||
// snapshot against the fields the frontend reader (parseGraph in lib/wsParse.ts)
|
||||
// requires. It is deliberately an exact key-set comparison: adding, renaming or
|
||||
// dropping a field the frontend reads must fail here.
|
||||
// TestFlowGraphUpdateWireFields 把快照每一层的 JSON 键名钉到
|
||||
// 前端读取器(lib/wsParse.ts 中的 parseGraph)所需的字段上。
|
||||
// 它刻意做精确键集比较:新增、改名或丢弃
|
||||
// 前端所读的字段必须在这里失败。
|
||||
func TestFlowGraphUpdateWireFields(t *testing.T) {
|
||||
raw, err := json.Marshal(sampleFlowSnapshot())
|
||||
if err != nil {
|
||||
@@ -93,7 +93,7 @@ func TestFlowGraphUpdateWireFields(t *testing.T) {
|
||||
assertGraphMeta(t, raw)
|
||||
}
|
||||
|
||||
// assertGraphKeys pins the top-level FlowGraph keys read by parseGraph/Flow.tsx.
|
||||
// assertGraphKeys 钉住 parseGraph/Flow.tsx 所读的 FlowGraph 顶层键。
|
||||
func assertGraphKeys(t *testing.T, graph map[string]json.RawMessage) {
|
||||
t.Helper()
|
||||
want := []string{"id", "nodes", "edges", "sessionId", "startedAt", "endedAt"}
|
||||
@@ -102,9 +102,9 @@ func assertGraphKeys(t *testing.T, graph map[string]json.RawMessage) {
|
||||
}
|
||||
}
|
||||
|
||||
// assertNodeKeys checks every emitted node key is one the frontend reads, that each
|
||||
// node carries the always-read id/label, and that the node holding props+log has
|
||||
// the complete set (which pins the omitempty tags too).
|
||||
// assertNodeKeys 检查每个发出的节点键都是前端会读的、每个
|
||||
// 节点都携带始终读取的 id/label,以及持有 props+log 的节点具备
|
||||
// 完整的键集(这也钉住了 omitempty 标签)。
|
||||
func assertNodeKeys(t *testing.T, nodes []map[string]json.RawMessage) {
|
||||
t.Helper()
|
||||
want := []string{"id", "label", "kind", "status", "startedAt", "endedAt", "props", "log"}
|
||||
@@ -131,7 +131,7 @@ func assertNodeKeys(t *testing.T, nodes []map[string]json.RawMessage) {
|
||||
}
|
||||
}
|
||||
|
||||
// assertEdgeKeys pins the FlowEdge shape (parseGraph reads from/to).
|
||||
// assertEdgeKeys 钉住 FlowEdge 形状(parseGraph 读取 from/to)。
|
||||
func assertEdgeKeys(t *testing.T, edges []map[string]json.RawMessage) {
|
||||
t.Helper()
|
||||
if len(edges) == 0 {
|
||||
@@ -144,7 +144,7 @@ func assertEdgeKeys(t *testing.T, edges []map[string]json.RawMessage) {
|
||||
}
|
||||
}
|
||||
|
||||
// assertLogKeys pins a node's log entry shape (parseGraph reads time/type/props).
|
||||
// assertLogKeys 钉住节点的 log 条目形状(parseGraph 读取 time/type/props)。
|
||||
func assertLogKeys(t *testing.T, nodes []map[string]json.RawMessage) {
|
||||
t.Helper()
|
||||
var logged []map[string]json.RawMessage
|
||||
@@ -167,8 +167,8 @@ func assertLogKeys(t *testing.T, nodes []map[string]json.RawMessage) {
|
||||
}
|
||||
}
|
||||
|
||||
// assertGraphMeta pins the envelope values the frontend renders (graph id/session
|
||||
// pair) and that timestamps arrive as RFC3339Nano (what Date.parse expects).
|
||||
// assertGraphMeta 钉住前端渲染的信封值(graph id/session
|
||||
// 对),以及时间戳以 RFC3339Nano 抵达(Date.parse 所期望的格式)。
|
||||
func assertGraphMeta(t *testing.T, raw []byte) {
|
||||
t.Helper()
|
||||
var meta struct {
|
||||
@@ -187,9 +187,9 @@ func assertGraphMeta(t *testing.T, raw []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
// sampleFlowSnapshot builds a real producer-side snapshot (trace.RunGraph, the same
|
||||
// type the loop's FlowPublisher publishes) whose every optional wire field is
|
||||
// populated, so the key-set assertions above are meaningful.
|
||||
// sampleFlowSnapshot 构建真实的生产者侧快照(trace.RunGraph,与
|
||||
// loop 的 FlowPublisher 发布的类型相同),其每个可选线上字段
|
||||
// 都被填充,使上面的键集断言有意义。
|
||||
func sampleFlowSnapshot() *trace.FlowGraph {
|
||||
base := time.Date(2026, 10, 3, 21, 0, 0, 0, time.UTC)
|
||||
g := trace.NewRunGraph("web")
|
||||
@@ -222,7 +222,7 @@ func sampleFlowSnapshot() *trace.FlowGraph {
|
||||
return g.Snapshot()
|
||||
}
|
||||
|
||||
// decodeObjects decodes a raw JSON array of objects, failing on a malformed shape.
|
||||
// decodeObjects 解码原始 JSON 对象数组,形状畸形时失败。
|
||||
func decodeObjects(t *testing.T, raw json.RawMessage, what string) []map[string]json.RawMessage {
|
||||
t.Helper()
|
||||
var out []map[string]json.RawMessage
|
||||
@@ -235,7 +235,7 @@ func decodeObjects(t *testing.T, raw json.RawMessage, what string) []map[string]
|
||||
return out
|
||||
}
|
||||
|
||||
// readRawWS reads one text frame and returns its raw bytes.
|
||||
// readRawWS 读取一个文本帧并返回其原始字节。
|
||||
func readRawWS(t *testing.T, conn *websocket.Conn) []byte {
|
||||
t.Helper()
|
||||
_, msg, err := conn.ReadMessage()
|
||||
@@ -245,7 +245,7 @@ func readRawWS(t *testing.T, conn *websocket.Conn) []byte {
|
||||
return msg
|
||||
}
|
||||
|
||||
// sortedKeys returns the object's JSON keys in sorted order.
|
||||
// sortedKeys 按排序后的顺序返回该对象的 JSON 键。
|
||||
func sortedKeys(obj map[string]json.RawMessage) []string {
|
||||
out := make([]string, 0, len(obj))
|
||||
for k := range obj {
|
||||
@@ -255,7 +255,7 @@ func sortedKeys(obj map[string]json.RawMessage) []string {
|
||||
return out
|
||||
}
|
||||
|
||||
// equalKeys reports whether got has exactly the members of want (both sorted).
|
||||
// equalKeys 报告 got 是否恰好拥有 want 的全部成员(二者均已排序)。
|
||||
func equalKeys(got []string, want []string) bool {
|
||||
want = append([]string(nil), want...)
|
||||
sort.Strings(want)
|
||||
@@ -270,7 +270,7 @@ func equalKeys(got []string, want []string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// containsKey reports whether the (sorted) key list holds k.
|
||||
// containsKey 报告(已排序的)键列表中是否含有 k。
|
||||
func containsKey(keys []string, k string) bool {
|
||||
for _, key := range keys {
|
||||
if key == k {
|
||||
|
||||
Reference in new issue
Block a user