docs(gateway): gateway 剩余文件注释改中文(逐行 1:1,代码零字节改动)
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

主人 2026-10-03 拍板「注释一律中文」;gateway 至此整包注释中文化完成(本会话共 3 批:
已推库 16 个文件 + 本批剩余文件)。
校验:机械校验(非注释改动行)= 空;剥注释后代码文本逐行比对全等(不一致文件数 0);
全树 go test ./... 58 包 ok / 0 FAIL;交叉编译绿。
This commit is contained in:
AskaEth committed 2026-10-03 22:28:25 +08:00
1 parent 91e8d7a029
commit 074ffc4ebf
73 files changed
+2529 -2529

No files matched your search

+19 -19
View File
@@ -23,7 +23,7 @@ import (
const testSecret = "0123456789abcdef0123456789abcdef"
// stubRunner is a Chatter whose Run returns a fixed result.
// stubRunner 是一个 Chatter,其 Run 返回固定结果。
type stubRunner struct {
res *loop.Result
err error
@@ -33,7 +33,7 @@ func (s *stubRunner) Run(ctx context.Context, sessionID string, messages []model
return s.res, s.err
}
// stubTool is a minimal sdk.Tool for capability-registry tests.
// stubTool 是供能力注册表测试用的最小 sdk.Tool。
type stubTool struct{}
func (stubTool) Name() string { return "echo" }
@@ -41,7 +41,7 @@ func (stubTool) Description() string { return "ec
func (stubTool) Parameters() (map[string]any, error) { return nil, nil }
func (stubTool) Execute(ctx context.Context, args any) (any, error) { return args, nil }
// testEnv bundles everything a test needs.
// testEnv 打包了测试所需的一切。
type testEnv struct {
srv *Server
ts *httptest.Server
@@ -50,8 +50,8 @@ type testEnv struct {
caps *capreg.Registry
}
// newEnv builds a Server backed by a real JWT service and in-process bus, plus a
// httptest server. runner may be nil (chat returns 500).
// newEnv 构建一个 Server,后端是真实 JWT 服务与进程内 bus,
// 外加一个 httptest 服务器。runner 可为 nil(chat 返回 500)。
func newEnv(t *testing.T, runner Chatter, withCaps bool) *testEnv {
t.Helper()
jwt := auth.New(config.AuthConfig{JWTSecret: testSecret})
@@ -87,7 +87,7 @@ func (e *testEnv) token(t *testing.T, role auth.Role) string {
return tok
}
// doReq performs an HTTP request and returns the response plus the raw body.
// doReq 执行一次 HTTP 请求并返回响应与原始响应体。
func doReq(t *testing.T, method, url string, body any, token string) (*http.Response, []byte) {
t.Helper()
var rd io.Reader
@@ -118,7 +118,7 @@ func doReq(t *testing.T, method, url string, body any, token string) (*http.Resp
return resp, bodyBytes
}
// decodeBody decodes a response body into a generic map.
// decodeBody 把响应体解码进一个通用 map。
func decodeBody(t *testing.T, b []byte) map[string]json.RawMessage {
t.Helper()
var m map[string]json.RawMessage
@@ -128,7 +128,7 @@ func decodeBody(t *testing.T, b []byte) map[string]json.RawMessage {
return m
}
// numOrZero returns the numeric value of a JSON number in the data envelope.
// numOrZero 返回 data 信封中某个 JSON 数字的数值。
func wantErrorShape(t *testing.T, b []byte) {
t.Helper()
env := decodeBody(t, b)
@@ -291,9 +291,9 @@ func TestRBACForbiddenAndUnauthorized(t *testing.T) {
{name: "chat no token", url: "/api/v1/chat", token: "", want: http.StatusUnauthorized},
{name: "chat viewer", url: "/api/v1/chat", token: viewer, want: http.StatusForbidden},
{name: "admin no token", url: "/api/v1/admin/plugins", token: "", want: http.StatusUnauthorized},
// A viewer reads the monitoring surface (/admin/plugins) but not the
// restricted reads (/admin/memories) — gateway/rbac_viewer_test.go
// enumerates both sets route by route.
// viewer 可以读监控表面(/admin/plugins),但不能读
// 受限读(/admin/memories)—— gateway/rbac_viewer_test.go
// 逐路由枚举了这两个集合。
{name: "admin plugin viewer ok", url: "/api/v1/admin/plugins", token: viewer, want: http.StatusOK},
{name: "admin memories viewer forbidden", url: "/api/v1/admin/memories", token: viewer, want: http.StatusForbidden},
{name: "admin owner ok", url: "/api/v1/admin/plugins", token: owner, want: http.StatusOK},
@@ -330,13 +330,13 @@ func TestAdminSetPolicyAndAudit(t *testing.T) {
t.Fatalf("policy data = %s, want allowInGroup true", data)
}
// Unknown capability → 404.
// 未知能力 → 404。
resp2, _ := doReq(t, http.MethodPost, env.ts.URL+"/api/v1/admin/plugins/policy", map[string]any{"name": "nope"}, owner)
if resp2.StatusCode != http.StatusNotFound {
t.Fatalf("status = %d, want 404", resp2.StatusCode)
}
// Viewer is forbidden from the write.
// viewer 被禁止执行该写操作。
viewer := env.token(t, auth.RoleViewer)
resp3, _ := doReq(t, http.MethodPost, env.ts.URL+"/api/v1/admin/plugins/policy", map[string]any{"name": "echo"}, viewer)
if resp3.StatusCode != http.StatusForbidden {
@@ -370,8 +370,8 @@ func TestWSUpgradeAndBroadcast(t *testing.T) {
defer conn.Close()
_ = conn.SetReadDeadline(time.Now().Add(3 * time.Second))
// Round-trip a mode_switch first: the relay re-broadcasts it, which
// guarantees the connection is registered before we trigger a broadcast.
// 先往返一次 mode_switch:中继会重新广播它,这
// 保证连接在我们触发广播前已注册。
if err := conn.WriteJSON(wsInbound{Type: "mode_switch", Data: json.RawMessage(`{"mode":"chat"}`)}); err != nil {
t.Fatalf("write mode_switch: %v", err)
}
@@ -379,7 +379,7 @@ func TestWSUpgradeAndBroadcast(t *testing.T) {
t.Fatalf("first frame type = %q, want mode_switch (frame=%+v)", got.Type, got)
}
// Publish an outbound event; the relay must forward it to the client.
// 发布一个下行事件;中继必须把它转发给客户端。
if err := env.bus.Publish(context.Background(), "ws.thinking", map[string]any{"text": "hmm"}); err != nil {
t.Fatalf("publish: %v", err)
}
@@ -390,7 +390,7 @@ func TestWSUpgradeAndBroadcast(t *testing.T) {
func TestWsEventSessionIDField(t *testing.T) {
t.Parallel()
// When set, sessionId is marshalled so the client can filter by session.
// 设置时 sessionId 会被序列化,使客户端能按会话过滤。
set, err := json.Marshal(wsEvent{Type: "stream_end", SessionID: "web", Data: map[string]any{"stopReason": "stop"}})
if err != nil {
t.Fatalf("marshal set: %v", err)
@@ -398,7 +398,7 @@ func TestWsEventSessionIDField(t *testing.T) {
if !strings.Contains(string(set), `"sessionId":"web"`) {
t.Fatalf("set frame = %s, want sessionId web", set)
}
// When empty, omitempty drops it so existing clients/tests see no change.
// 为空时 omitempty 会丢弃它,因此既有客户端/测试看不到变化。
unset, err := json.Marshal(wsEvent{Type: "stream_end", Data: map[string]any{"stopReason": "stop"}})
if err != nil {
t.Fatalf("marshal unset: %v", err)
@@ -415,7 +415,7 @@ func TestWsEventSessionIDField(t *testing.T) {
}
}
// readWS reads one text frame and decodes it into a wsEvent.
// readWS 读取一个文本帧并解码进 wsEvent。
func readWS(t *testing.T, conn *websocket.Conn) wsEvent {
t.Helper()
_, msg, err := conn.ReadMessage()