docs(comments): 注释中文化 · internal/runtime/memory(31 文件,纯替换)
- 只翻注释/文档字符串:820 增 / 820 删 严格 1:1;剥掉整行注释与行尾注释尾巴后, 逐文件与 HEAD 比对「代码部分差异 = 0」;裁决/design 编号计数逐项与 HEAD 一致 - 保留可执行 SQL 样例、SQLite 报错原文、pgvector/HNSW/ANN/BLOB 等技术词原文 - 复核:go build 绿 + memory/projectindex/vector 三包测试绿;gofmt 仅剩 2 个既有未格式化文件(改动前即如此,未顺手修)
This commit is contained in:
1 parent
eb1828ee7a
commit
61cf80d5ee
31 files changed
+820
-820
No files matched your search
@@ -14,13 +14,13 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/db"
|
||||
)
|
||||
|
||||
// testLogger returns a logger that writes nowhere, keeping test output clean.
|
||||
// testLogger 返回一个不写任何地方的 logger,保持测试输出干净。
|
||||
func testLogger() *slog.Logger {
|
||||
return slog.New(slog.NewTextHandler(io.Discard, nil))
|
||||
}
|
||||
|
||||
// newTestStore opens an isolated in-memory SQLite DB and builds a Store over it.
|
||||
// Each call owns a private DB, so parallel tests are isolated by construction.
|
||||
// newTestStore 打开一个隔离的内存 SQLite 库并在其上构建 Store。
|
||||
// 每次调用都拥有私有 DB,因此并行测试天生相互隔离。
|
||||
func newTestStore(t *testing.T) *Store {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
@@ -37,7 +37,7 @@ func newTestStore(t *testing.T) *Store {
|
||||
return s
|
||||
}
|
||||
|
||||
// baseProject is a minimal valid project for tests.
|
||||
// baseProject 是测试用的最小合法项目。
|
||||
func baseProject() Project {
|
||||
return Project{ID: "proj.1", Title: "Cyrene", Desc: "陪伴型 AI 助手"}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ func TestStore_PutGetProject_Upsert(t *testing.T) {
|
||||
if err := s.PutProject(ctx, Project{ID: "proj.1", Title: "T1", Desc: "D1", CreatedAt: oldTime}); err != nil {
|
||||
t.Fatalf("PutProject insert: %v", err)
|
||||
}
|
||||
// Upsert preserves the original created_at while updating title/desc.
|
||||
// upsert 保留原始的 created_at,同时更新 title/desc。
|
||||
if err := s.PutProject(ctx, Project{ID: "proj.1", Title: "T2", Desc: "D2", CreatedAt: oldTime.Add(time.Hour)}); err != nil {
|
||||
t.Fatalf("PutProject update: %v", err)
|
||||
}
|
||||
@@ -184,7 +184,7 @@ func TestStore_AddListChapters_正常(t *testing.T) {
|
||||
t.Errorf("AddChapter did not assign timestamps")
|
||||
}
|
||||
|
||||
// A different project must not see these chapters.
|
||||
// 另一个项目必须看不到这些章节。
|
||||
other, err := s.ListChapters(ctx, "proj.other")
|
||||
if err != nil {
|
||||
t.Fatalf("ListChapters(proj.other): %v", err)
|
||||
@@ -397,7 +397,7 @@ func TestStore_Search_SQLInjectionSafe(t *testing.T) {
|
||||
t.Fatalf("AddChapter malicious: %v", err)
|
||||
}
|
||||
|
||||
// A keyword full of SQL metacharacters must not alter behavior or data.
|
||||
// 满是 SQL 元字符的关键词不得改变行为或数据。
|
||||
res, err := s.Search(ctx, maliciousID, "' OR 1=1 --")
|
||||
if err != nil {
|
||||
t.Fatalf("Search malicious keyword: %v", err)
|
||||
@@ -412,7 +412,7 @@ func TestStore_Search_SQLInjectionSafe(t *testing.T) {
|
||||
t.Fatalf("Search benign keyword on malicious id: %v", err)
|
||||
}
|
||||
|
||||
// The malicious id must round-trip intact (proves parameterized lookup).
|
||||
// 恶意的 id 必须原样往返(证明查询是参数化的)。
|
||||
got, err := s.GetProject(ctx, maliciousID)
|
||||
if err != nil {
|
||||
t.Fatalf("GetProject malicious: %v", err)
|
||||
@@ -420,7 +420,7 @@ func TestStore_Search_SQLInjectionSafe(t *testing.T) {
|
||||
if got.ID != maliciousID {
|
||||
t.Errorf("ID = %q, want %q", got.ID, maliciousID)
|
||||
}
|
||||
// And the malicious project must still be queryable, not dropped.
|
||||
// 而恶意的项目必须仍可查询,而不是被丢弃。
|
||||
if _, err := s.GetProject(ctx, "project"); !errors.Is(err, ErrProjectNotFound) {
|
||||
t.Fatalf("project table intact check: err = %v, want ErrProjectNotFound", err)
|
||||
}
|
||||
@@ -490,8 +490,8 @@ func TestStore_Search_MatchInMultipleLines(t *testing.T) {
|
||||
t.Errorf("line numbers = [%d %d %d], want [1 2 4]",
|
||||
hit.Matches[0].LineNumber, hit.Matches[1].LineNumber, hit.Matches[2].LineNumber)
|
||||
}
|
||||
// The keyword was lowercase "ai" but the content holds uppercase "AI",
|
||||
// so the match is case-insensitive while Text preserves the original casing.
|
||||
// 关键词是小写 "ai" 而内容里是大写 "AI",
|
||||
// 因此匹配不区分大小写,而 Text 保留原始大小写。
|
||||
if !strings.Contains(hit.Matches[0].Text, "AI") {
|
||||
t.Errorf("expected case-insensitive match, Text = %q", hit.Matches[0].Text)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user