docs(comments): 注释中文化 · internal/runtime/history(15 文件,纯替换)
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

- 只翻注释/文档字符串:剥离注释后代码行逐字节不变(机械校验只剩 4 条行尾注释的翻译,代码前缀全等)
- 交叉引用(design/16 §4.6、D4/B3、0010 迁移文件名)逐字保留
- 保留未译技术词:DDL/rowid/LIKE/LEFT JOIN/DTO/rune/WS/actor 及全部标识符与表名
- 顺带副作用:store.go、session_persona_test.go 由注释文字改变而变得 gofmt 干净(未运行 gofmt -w)
This commit is contained in:
AskaEth committed 2026-10-04 12:28:48 +08:00
1 parent b0fbb8bc0d
commit 09fba77f87
15 files changed
+430 -516

No files matched your search

+17 -18
View File
@@ -6,7 +6,7 @@ import (
"testing"
)
// seedMessages appends msgs and returns them with their store-assigned ids.
// seedMessages 追加 msgs 并返回它们(带存储分配的 id)。
func seedMessages(t *testing.T, st *Store, msgs ...Message) []Message {
t.Helper()
out := make([]Message, 0, len(msgs))
@@ -31,7 +31,7 @@ func TestSearchSessionScopedNewestFirstAndPaged(t *testing.T) {
Message{SessionID: MainSessionID, Role: RoleUser, Content: "hit four", CreatedAt: 4000},
)
// Newest-first page of two hits; the non-matching message is skipped.
// 最新优先、两条命中的一页;不匹配的消息被跳过。
page, err := st.Search(ctx, MainSessionID, "hit", 0, 2)
if err != nil {
t.Fatalf("search: %v", err)
@@ -40,7 +40,7 @@ func TestSearchSessionScopedNewestFirstAndPaged(t *testing.T) {
t.Fatalf("page = %+v, want [4000 3000]", page)
}
// before cursor walks to the older hits.
// before 游标走到更旧的命中。
older, err := st.Search(ctx, MainSessionID, "hit", 3000, 2)
if err != nil {
t.Fatalf("search older: %v", err)
@@ -49,7 +49,7 @@ func TestSearchSessionScopedNewestFirstAndPaged(t *testing.T) {
t.Fatalf("older = %+v, want [2000 1000]", older)
}
// An empty query yields an empty (non-nil) slice, not the whole session.
// 空查询得到空(非 nil)切片,而不是整个会话。
empty, err := st.Search(ctx, MainSessionID, "", 0, 10)
if err != nil {
t.Fatalf("search empty: %v", err)
@@ -69,7 +69,7 @@ func TestSearchCaseInsensitiveAndLiteralWildcards(t *testing.T) {
Message{SessionID: MainSessionID, Role: RoleUser, Content: "under_score", CreatedAt: 3000},
)
// ASCII case-insensitive LIKE.
// ASCII 大小写不敏感的 LIKE。
got, err := st.Search(ctx, MainSessionID, "hello", 0, 10)
if err != nil {
t.Fatalf("search hello: %v", err)
@@ -78,7 +78,7 @@ func TestSearchCaseInsensitiveAndLiteralWildcards(t *testing.T) {
t.Fatalf("hello = %+v, want [Hello World]", got)
}
// A literal % must not act as a wildcard (else it would match every row).
// 字面 % 不得充当通配符(否则它会匹配每一行)。
pct, err := st.Search(ctx, MainSessionID, "100%", 0, 10)
if err != nil {
t.Fatalf("search 100%%: %v", err)
@@ -87,7 +87,7 @@ func TestSearchCaseInsensitiveAndLiteralWildcards(t *testing.T) {
t.Fatalf("100%% = %+v, want [100%% done]", pct)
}
// A literal _ must match only the underscore, not any single character.
// 字面 _ 只能匹配下划线,不能匹配任意单字符。
us, err := st.Search(ctx, MainSessionID, "under_", 0, 10)
if err != nil {
t.Fatalf("search under_: %v", err)
@@ -97,9 +97,8 @@ func TestSearchCaseInsensitiveAndLiteralWildcards(t *testing.T) {
}
}
// TestSearchNeverCrossesSessionBoundary is the red-line guard: a search is scoped to
// one session, so an isolated group/stranger session's content can never surface in
// the main session's results (or vice versa).
// TestSearchNeverCrossesSessionBoundary 是红线守卫:搜索限定在单个会话内,因此
// 隔离的群聊/陌生人会话内容绝不浮现在主会话的结果里(反之亦然)。
func TestSearchNeverCrossesSessionBoundary(t *testing.T) {
t.Parallel()
st := newStore(t)
@@ -144,7 +143,7 @@ func TestUpdateMessageContentOnly(t *testing.T) {
t.Fatalf("updated = %+v, want content=after with role/ts/session preserved", got)
}
// The edit is persisted, not just echoed.
// 编辑要落盘,不能只是回显。
listed, err := st.List(ctx, MainSessionID, 0, 10, "")
if err != nil {
t.Fatalf("list: %v", err)
@@ -153,7 +152,7 @@ func TestUpdateMessageContentOnly(t *testing.T) {
t.Fatalf("listed = %+v, want content=after", listed)
}
// An unknown id returns the sentinel.
// 未知 id 返回哨兵错误。
if _, err := st.UpdateMessage(ctx, "missing", "x"); !errors.Is(err, ErrMessageNotFound) {
t.Fatalf("update missing err = %v, want ErrMessageNotFound", err)
}
@@ -196,10 +195,10 @@ func TestSetPinnedOrdersSessions(t *testing.T) {
t.Fatalf("new sub 2: %v", err)
}
// Baseline: main first, subs oldest-first.
// 基线:主会话在前,子会话最旧优先。
assertSessionOrder(t, st, []string{MainSessionID, first, second})
// Pinning the newest sub floats it above the main session.
// 置顶最新的子会话会把它浮到主会话之上。
if err := st.SetPinned(ctx, second, true); err != nil {
t.Fatalf("pin: %v", err)
}
@@ -208,19 +207,19 @@ func TestSetPinnedOrdersSessions(t *testing.T) {
t.Fatalf("pinned session meta = %+v, want Pinned=true", metas[0])
}
// Unpinning restores the baseline order.
// 取消置顶恢复基线顺序。
if err := st.SetPinned(ctx, second, false); err != nil {
t.Fatalf("unpin: %v", err)
}
assertSessionOrder(t, st, []string{MainSessionID, first, second})
// An unknown session id is a not-found error.
// 未知会话 id 是 not-found 错误。
if err := st.SetPinned(ctx, "web:missing", true); !errors.Is(err, ErrSessionNotFound) {
t.Fatalf("pin missing err = %v, want ErrSessionNotFound", err)
}
}
// listMetas returns ListSessions output for order/pin assertions.
// listMetas 返回 ListSessions 的结果,用于顺序/置顶断言。
func listMetas(t *testing.T, st *Store) []SessionMeta {
t.Helper()
metas, err := st.ListSessions(context.Background())
@@ -230,7 +229,7 @@ func listMetas(t *testing.T, st *Store) []SessionMeta {
return metas
}
// assertSessionOrder fails unless ListSessions returns exactly ids in order.
// assertSessionOrder 在 ListSessions 没有严格按 ids 的顺序返回时使测试失败。
func assertSessionOrder(t *testing.T, st *Store, ids []string) {
t.Helper()
metas := listMetas(t, st)