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

@@ -11,8 +11,8 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/history"
)
// seedFullMessage appends m through the real store and returns the stored message
// (with its generated id), so HTTP tests can address a specific message.
// seedFullMessage 经真实存储追加 m 并返回已存消息
// (含其生成的 id),使 HTTP 测试能定位到具体某条消息。
func seedFullMessage(t *testing.T, st *history.Store, m history.Message) history.Message {
t.Helper()
got, err := st.AppendFull(context.Background(), m)
@@ -22,8 +22,8 @@ func seedFullMessage(t *testing.T, st *history.Store, m history.Message) history
return got
}
// TestHistorySearchMessagesHTTP covers D2: session-scoped ?q= search hits, paging,
// the empty-q fallback, input validation and isolation from another session.
// TestHistorySearchMessagesHTTP 覆盖 D2:会话作用域的 ?q= 搜索命中、分页、
// 空 q 回退、输入校验以及与其他会话的隔离。
func TestHistorySearchMessagesHTTP(t *testing.T) {
t.Parallel()
_, ts, jwt, st := newHistoryEnv(t)
@@ -39,7 +39,7 @@ func TestHistorySearchMessagesHTTP(t *testing.T) {
t.Fatalf("seed %q: %v", m.Content, err)
}
}
// A matching message in another (sub) session must never surface in the main search.
// 另一个(子)会话中的匹配消息绝不得出现在主会话搜索中。
sub, err := st.NewSubSession(ctx, "owner")
if err != nil {
t.Fatalf("new sub: %v", err)
@@ -49,7 +49,7 @@ func TestHistorySearchMessagesHTTP(t *testing.T) {
}
tok := signAny(t, jwt, "acct", auth.RoleOwner)
// Newest-first page of 2 matching hits.
// 最新优先的一页,2 条匹配命中。
resp, body := doReq(t, http.MethodGet, ts.URL+"/api/v1/sessions/"+history.MainSessionID+"/messages?q=天气&limit=2", nil, tok)
if resp.StatusCode != http.StatusOK {
t.Fatalf("search status = %d, want 200 (body=%s)", resp.StatusCode, body)
@@ -63,7 +63,7 @@ func TestHistorySearchMessagesHTTP(t *testing.T) {
t.Fatalf("search leaked session %q", page[0].SessionID)
}
// before cursor pages to the older hits.
// before 游标翻到更旧的命中。
resp, body = doReq(t, http.MethodGet, ts.URL+"/api/v1/sessions/"+history.MainSessionID+"/messages?q=天气&before=3000&limit=2", nil, tok)
if resp.StatusCode != http.StatusOK {
t.Fatalf("search older status = %d, want 200 (body=%s)", resp.StatusCode, body)
@@ -74,7 +74,7 @@ func TestHistorySearchMessagesHTTP(t *testing.T) {
t.Fatalf("search older = %+v, want [2000 1000]", older)
}
// The sub session's search sees only its own hit.
// 子会话的搜索只看到自己的命中。
resp, body = doReq(t, http.MethodGet, ts.URL+"/api/v1/sessions/"+sub+"/messages?q=天气", nil, tok)
if resp.StatusCode != http.StatusOK {
t.Fatalf("sub search status = %d, want 200 (body=%s)", resp.StatusCode, body)
@@ -85,7 +85,7 @@ func TestHistorySearchMessagesHTTP(t *testing.T) {
t.Fatalf("sub search = %+v, want only the sub hit", subHits)
}
// An empty q falls back to plain paging (all messages).
// 空 q 回退到普通分页(全部消息)。
resp, body = doReq(t, http.MethodGet, ts.URL+"/api/v1/sessions/"+history.MainSessionID+"/messages?q=&limit=10", nil, tok)
if resp.StatusCode != http.StatusOK {
t.Fatalf("empty q status = %d, want 200 (body=%s)", resp.StatusCode, body)
@@ -96,7 +96,7 @@ func TestHistorySearchMessagesHTTP(t *testing.T) {
t.Fatalf("empty q = %d messages, want 5", len(all))
}
// q is mutually exclusive with after, and invalid limit still 400.
// q 与 after 互斥,且非法 limit 仍是 400。
resp, body = doReq(t, http.MethodGet, ts.URL+"/api/v1/sessions/"+history.MainSessionID+"/messages?q=天气&after=1000", nil, tok)
if resp.StatusCode != http.StatusBadRequest {
t.Fatalf("q+after status = %d, want 400 (body=%s)", resp.StatusCode, body)
@@ -107,8 +107,8 @@ func TestHistorySearchMessagesHTTP(t *testing.T) {
}
}
// TestHistoryPatchAndDeleteMessageHTTP covers D3: editing and deleting one message,
// the input bounds, 404 and RBAC.
// TestHistoryPatchAndDeleteMessageHTTP 覆盖 D3:编辑与删除单条消息、
// 输入边界、404 与 RBAC。
func TestHistoryPatchAndDeleteMessageHTTP(t *testing.T) {
t.Parallel()
_, ts, jwt, st := newHistoryEnv(t)
@@ -116,7 +116,7 @@ func TestHistoryPatchAndDeleteMessageHTTP(t *testing.T) {
tok := signAny(t, jwt, "acct", auth.RoleOwner)
base := ts.URL + "/api/v1/messages/" + msg.ID
// Edit the content; role/timestamp/session are preserved and echoed back.
// 编辑 content;role/时间戳/会话保持不变并回显。
resp, body := doReq(t, http.MethodPatch, base, map[string]any{"content": "改后的正文"}, tok)
if resp.StatusCode != http.StatusOK {
t.Fatalf("patch status = %d, want 200 (body=%s)", resp.StatusCode, body)
@@ -129,7 +129,7 @@ func TestHistoryPatchAndDeleteMessageHTTP(t *testing.T) {
t.Fatalf("updated = %+v, want content edited with role/ts preserved", updated)
}
// The edit is persisted.
// 该编辑已被持久化。
resp, body = doReq(t, http.MethodGet, ts.URL+"/api/v1/sessions/"+history.MainSessionID+"/messages", nil, tok)
if resp.StatusCode != http.StatusOK {
t.Fatalf("list status = %d, want 200 (body=%s)", resp.StatusCode, body)
@@ -140,7 +140,7 @@ func TestHistoryPatchAndDeleteMessageHTTP(t *testing.T) {
t.Fatalf("listed = %+v, want the edited content", listed)
}
// Invalid edits: empty/whitespace, missing field, over-long, unknown id.
// 非法编辑:空/仅空白、字段缺失、过长、未知 id。
for _, tc := range []struct {
name string
body any
@@ -162,7 +162,7 @@ func TestHistoryPatchAndDeleteMessageHTTP(t *testing.T) {
t.Fatalf("patch unknown status = %d, want 404 (body=%s)", resp.StatusCode, body)
}
// Delete the message, then deleting again is 404.
// 删除该消息,再次删除则是 404。
resp, body = doReq(t, http.MethodDelete, base, nil, tok)
if resp.StatusCode != http.StatusOK {
t.Fatalf("delete status = %d, want 200 (body=%s)", resp.StatusCode, body)
@@ -181,7 +181,7 @@ func TestHistoryPatchAndDeleteMessageHTTP(t *testing.T) {
t.Fatalf("delete again status = %d, want 404 (body=%s)", resp.StatusCode, body)
}
// A viewer cannot edit or delete (owner/admin write).
// viewer 不能编辑或删除(owner/admin 写)。
other := seedFullMessage(t, st, history.Message{SessionID: history.MainSessionID, Role: history.RoleUser, Content: "x", CreatedAt: 2000})
viewer := signAny(t, jwt, "acct", auth.RoleViewer)
for _, method := range []string{http.MethodPatch, http.MethodDelete} {
@@ -192,8 +192,8 @@ func TestHistoryPatchAndDeleteMessageHTTP(t *testing.T) {
}
}
// TestHistoryMessagesNotWiredHTTP asserts the D2/D3 endpoints answer a clear 501 when
// no HistoryStore is injected.
// TestHistoryMessagesNotWiredHTTP 断言未注入 HistoryStore 时 D2/D3 端点
// 返回明确的 501。
func TestHistoryMessagesNotWiredHTTP(t *testing.T) {
t.Parallel()
_, ts, jwt := buildEnv(t, cfgDefault(), Deps{})
@@ -215,8 +215,8 @@ func TestHistoryMessagesNotWiredHTTP(t *testing.T) {
}
}
// TestHistoryPatchSessionPinnedHTTP covers D5: pin/unpin changes GET /sessions order,
// the response echoes only the changed field, and the A4 title PATCH still works.
// TestHistoryPatchSessionPinnedHTTP 覆盖 D5:置顶/取消置顶改变 GET /sessions 顺序,
// 响应只回显被改动的字段,且 A4 的标题 PATCH 仍然可用。
func TestHistoryPatchSessionPinnedHTTP(t *testing.T) {
t.Parallel()
_, ts, jwt, _ := newHistoryEnv(t)
@@ -265,8 +265,8 @@ func TestHistoryPatchSessionPinnedHTTP(t *testing.T) {
assertOrder([]string{history.MainSessionID, first, second})
// Pin the newest sub: it floats above the main session, and the response echoes
// only the pinned field.
// 置顶最新的子会话:它会浮到主会话之上,且响应只回显
// 被置顶的字段。
resp, body := doReq(t, http.MethodPatch, ts.URL+"/api/v1/sessions/"+second, map[string]any{"pinned": true}, tok)
if resp.StatusCode != http.StatusOK {
t.Fatalf("pin status = %d, want 200 (body=%s)", resp.StatusCode, body)
@@ -284,7 +284,7 @@ func TestHistoryPatchSessionPinnedHTTP(t *testing.T) {
}
assertOrder([]string{second, history.MainSessionID, first})
// GET /sessions reports the pin flag.
// GET /sessions 报告置顶标志。
resp, body = doReq(t, http.MethodGet, ts.URL+"/api/v1/sessions", nil, tok)
if resp.StatusCode != http.StatusOK {
t.Fatalf("list status = %d, want 200 (body=%s)", resp.StatusCode, body)
@@ -295,7 +295,7 @@ func TestHistoryPatchSessionPinnedHTTP(t *testing.T) {
t.Fatalf("sessions[0] = %+v, want pinned sub %s", sessions[0], second)
}
// A title PATCH still works and keeps its {id,title} response shape.
// 标题 PATCH 仍然可用,并保持其 {id,title} 响应形状。
resp, body = doReq(t, http.MethodPatch, ts.URL+"/api/v1/sessions/"+second, map[string]any{"title": " 置顶会话 "}, tok)
if resp.StatusCode != http.StatusOK {
t.Fatalf("title patch status = %d, want 200 (body=%s)", resp.StatusCode, body)
@@ -311,14 +311,14 @@ func TestHistoryPatchSessionPinnedHTTP(t *testing.T) {
t.Fatalf("title patch = %+v, want 置顶会话", renamed)
}
// Unpin restores the baseline order.
// 取消置顶恢复基线顺序。
resp, _ = doReq(t, http.MethodPatch, ts.URL+"/api/v1/sessions/"+second, map[string]any{"pinned": false}, tok)
if resp.StatusCode != http.StatusOK {
t.Fatalf("unpin status = %d, want 200", resp.StatusCode)
}
assertOrder([]string{history.MainSessionID, first, second})
// Neither field → 400; unknown id → 404; viewer → 403.
// 两个字段都不给 → 400;未知 id → 404;viewer → 403。
resp, body = doReq(t, http.MethodPatch, ts.URL+"/api/v1/sessions/"+second, map[string]any{}, tok)
if resp.StatusCode != http.StatusBadRequest {
t.Fatalf("empty patch status = %d, want 400 (body=%s)", resp.StatusCode, body)