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

+37 -37
View File
@@ -14,9 +14,9 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/services/backthink"
)
// stubAuditFeed is an AuditStore over scripted records (already newest first),
// so the feed tests control millisecond timestamps exactly — the in-memory
// fallback store only keeps second precision.
// stubAuditFeed 是一个基于脚本化记录的 AuditStore(已按最新优先),
// 使 feed 测试能精确控制毫秒时间戳 —— 内存
// 回退存储只保留秒级精度。
type stubAuditFeed struct {
records []AuditRecord
err error
@@ -34,7 +34,7 @@ func (s *stubAuditFeed) List(_ context.Context, limit int) ([]AuditRecord, error
return append([]AuditRecord(nil), s.records[:limit]...), nil
}
// stubBackthinkFeed is a BackthinkStore over scripted records (newest first).
// stubBackthinkFeed 是一个基于脚本化记录的 BackthinkStore(最新优先)。
type stubBackthinkFeed struct {
records []backthink.Record
err error
@@ -50,15 +50,15 @@ func (s *stubBackthinkFeed) List(_ context.Context, limit int) ([]backthink.Reco
return append([]backthink.Record(nil), s.records[:limit]...), nil
}
// notificationMS renders epoch milliseconds as the RFC3339 timestamp an audit
// record carries.
// notificationMS 把 epoch 毫秒渲染成审计
// 记录所携带的 RFC3339 时间戳。
func notificationMS(ms int64) string {
return time.UnixMilli(ms).UTC().Format(time.RFC3339Nano)
}
// notificationFeedFixture scripts both sources: channel + system + audit rows in
// the audit trail and one delivered / one undelivered / one non-push backthink
// record.
// notificationFeedFixture 脚本化两个来源:审计链中的
// channel + system + audit 行,以及一条已投递 / 一条未投递 / 一条非推送的
// 后台思考记录。
func notificationFeedFixture() (*stubAuditFeed, *stubBackthinkFeed) {
audit := &stubAuditFeed{records: []AuditRecord{
{ID: 5, Who: "owner:owner", What: "channel.open", When: notificationMS(3000), Result: "ok"},
@@ -76,7 +76,7 @@ func notificationFeedFixture() (*stubAuditFeed, *stubBackthinkFeed) {
return audit, bt
}
// listNotifications calls the endpoint and decodes the feed.
// listNotifications 调用该端点并解码 feed。
func listNotifications(t *testing.T, ts *httptest.Server, tok, query string) (int, []AdminNotification, []byte) {
t.Helper()
resp, body := doReq(t, http.MethodGet, ts.URL+"/api/v1/admin/notifications"+query, nil, tok)
@@ -90,10 +90,10 @@ func listNotifications(t *testing.T, ts *httptest.Server, tok, query string) (in
return resp.StatusCode, out, body
}
// TestAdminListNotifications_MergesAuditAndBackthink proves the feed is the two
// existing sources merged newest-first with source-namespaced ids, the audit
// family classification, and that a backthink record which decided not to push is
// not an event.
// TestAdminListNotifications_MergesAuditAndBackthink 证明 feed 是两个
// 既有来源按最新优先合并、id 带来源命名空间、审计
// 族分类正确,以及决定不推送的后台思考记录
// 不是事件。
func TestAdminListNotifications_MergesAuditAndBackthink(t *testing.T) {
t.Parallel()
audit, bt := notificationFeedFixture()
@@ -134,8 +134,8 @@ func TestAdminListNotifications_MergesAuditAndBackthink(t *testing.T) {
t.Fatalf("backthink title = %q, want the delivery state", got.Title)
}
}
// The undelivered push is older and its conclusion is long: both the body cap
// and the "未送达" label must show.
// 未投递的推送更旧且其结论很长:body 上限
// 与「未送达」标签都必须体现。
for _, it := range items {
if it.ID == "backthink:6" {
if !strings.Contains(it.Title, "未送达") {
@@ -146,7 +146,7 @@ func TestAdminListNotifications_MergesAuditAndBackthink(t *testing.T) {
}
}
}
// A thinking record that decided not to push never becomes a notification.
// 决定不推送的思考记录绝不成为通知。
for _, it := range items {
if it.ID == "backthink:7" {
t.Fatalf("non-push backthink record leaked into the feed: %+v", it)
@@ -154,9 +154,9 @@ func TestAdminListNotifications_MergesAuditAndBackthink(t *testing.T) {
}
}
// TestAdminListNotifications_TypeFilter proves `?type=` selects one family and
// that a family without any source data answers an empty feed (never a fabricated
// row).
// TestAdminListNotifications_TypeFilter 证明 `?type=` 选中一个族,
// 且没有任何来源数据的族返回空 feed(绝不编造
// 一行)。
func TestAdminListNotifications_TypeFilter(t *testing.T) {
t.Parallel()
audit, bt := notificationFeedFixture()
@@ -187,7 +187,7 @@ func TestAdminListNotifications_TypeFilter(t *testing.T) {
}
}
// An empty source (no backthink service injected) yields an empty family.
// 空来源(未注入后台思考服务)得到空族。
_, auditOnly, jwtOnly := buildEnv(t, nil, Deps{AuditStore: audit})
tokAudit := signAny(t, jwtOnly, "acct", auth.RoleOwner)
status, items, body := listNotifications(t, auditOnly, tokAudit, "?type=backthink")
@@ -196,9 +196,9 @@ func TestAdminListNotifications_TypeFilter(t *testing.T) {
}
}
// TestAdminListNotifications_BeforeCursorPagination proves the `before` cursor:
// pages walk older, the cursor item itself is included (the sources resolve to
// milliseconds and the client dedupes by id), and `limit` caps a page.
// TestAdminListNotifications_BeforeCursorPagination 证明 `before` 游标:
// 翻页向更旧走,游标条目本身被包含(来源解析到
// 毫秒,客户端按 id 去重),且 `limit` 限定一页。
func TestAdminListNotifications_BeforeCursorPagination(t *testing.T) {
t.Parallel()
audit, bt := notificationFeedFixture()
@@ -229,16 +229,16 @@ func TestAdminListNotifications_BeforeCursorPagination(t *testing.T) {
t.Fatalf("page3 = %+v, want [backthink:8 audit:3]", page3)
}
// A cursor older than every item ends the walk with an empty page.
// 比所有条目都旧的游标以空页结束翻页。
status, tail, body := listNotifications(t, ts, tok, "?before=1")
if status != http.StatusOK || len(tail) != 0 {
t.Fatalf("tail = %+v / status %d, want empty / 200 (body=%s)", tail, status, body)
}
}
// TestAdminListNotifications_NoSourcesNoFabrication proves the honest empty feed:
// with neither source injected the endpoint returns an empty array, not invented
// notices.
// TestAdminListNotifications_NoSourcesNoFabrication 证明诚实的空 feed:
// 两个来源都未注入时端点返回空数组,而不是编造
// 通知。
func TestAdminListNotifications_NoSourcesNoFabrication(t *testing.T) {
t.Parallel()
_, ts, jwt := buildEnv(t, nil, Deps{})
@@ -256,9 +256,9 @@ func TestAdminListNotifications_NoSourcesNoFabrication(t *testing.T) {
}
}
// TestAdminListNotifications_Errors proves the endpoint fails loudly: an unknown
// family is a 400 and a failing source is a 500 (never a silently shortened
// feed). A viewer reads the feed (read-only monitoring tier).
// TestAdminListNotifications_Errors 证明该端点响亮地失败:未知
// 族是 400,来源失败是 500(绝不是静默变短的
// feed)。viewer 可以读该 feed(只读监控层)。
func TestAdminListNotifications_Errors(t *testing.T) {
t.Parallel()
audit, bt := notificationFeedFixture()
@@ -283,10 +283,10 @@ func TestAdminListNotifications_Errors(t *testing.T) {
}
}
// TestNotificationAuditAt_ParsesBothStoreFormats locks the timestamp contract with
// the two real audit stores: SQLiteAuditStore writes RFC3339Nano, the in-memory
// fallback writes RFC3339, and an unparseable value degrades to 0 (oldest) rather
// than being dropped or faked.
// TestNotificationAuditAt_ParsesBothStoreFormats 用两个真实审计存储锁定
// 时间戳契约:SQLiteAuditStore 写 RFC3339Nano,内存
// 回退写 RFC3339,无法解析的值退化到 0(最旧),而不是
// 被丢弃或伪造。
func TestNotificationAuditAt_ParsesBothStoreFormats(t *testing.T) {
t.Parallel()
base := time.Date(2026, 9, 30, 10, 0, 0, 123456000, time.UTC)
@@ -307,8 +307,8 @@ func TestNotificationAuditAt_ParsesBothStoreFormats(t *testing.T) {
}
}
// TestNotificationQueryParsing locks the query knobs: the limit defaults to 50 and
// clamps at 200, and an absent or malformed `before` means "from newest".
// TestNotificationQueryParsing 锁定查询旋钮:limit 默认 50,
// 上限 200,且 `before` 缺失或畸形意味着「从最新开始」。
func TestNotificationQueryParsing(t *testing.T) {
t.Parallel()
limitCases := []struct {