Files
Cyrene_v2/internal/services/backthink/store_test.go
T
AskaEth 3dc1232bc2
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled
docs(comments): 注释中文化 · internal/runtime/model + internal/services/backthink(54 文件,纯替换)
- 只翻注释/文档字符串:`go/scanner` 剥注释后按 token 序列+literal 逐 token 比对,**54/54 文件 SAME**;
  改动文件总行数与 HEAD 漂移 = 0(严格 1:1,无合并/拆行)
- 裁决编号与 design 节号逐字保留(03.4.1/03.4.2/03.4.3/14.4.1/14.4.5/07.4.2-4、design/04 §3.1/§3.2 等);
  `chat_template_kwargs` / `enable_thinking` / `reasoning_effort` / `thinking:{type}` 字段名与形状说明未动
- 存疑译法(已登记):`persona` 在叙事语境用「角色」、标识符语境保留 `persona`(仓库既有模块本身混用);
  `rung`→「级」;`provider` 存在「提供商/提供者」两种落笔(可按需一键统一)
- 复核:build/vet 绿 + 两包测试绿;gofmt 干净;残留英文注释 0 条
- 既有存量(未修,只报告):`model/anthropic_test.go` 612 行 >500;`applyAnthropicEvent` 115 行 >80
2026-10-04 16:27:54 +08:00

87 lines
2.3 KiB
Go

package backthink
import (
"context"
"errors"
"testing"
"time"
)
func TestStore_AppendList(t *testing.T) {
t.Parallel()
s, err := NewStore(context.Background(), newTestDB(t), discardLog())
if err != nil {
t.Fatalf("NewStore: %v", err)
}
base := time.Date(2026, 9, 6, 10, 0, 0, 0, time.UTC)
for i := 0; i < 3; i++ {
id, err := s.Append(context.Background(), Record{
Trigger: "iot.device_update",
At: base.Add(time.Duration(i) * time.Minute),
Conclusion: "nothing to report",
ShouldPush: i%2 == 0,
PushResult: PushResult{Pushed: i == 2, Route: RouteActiveClient, Detail: "ok"},
})
if err != nil {
t.Fatalf("Append %d: %v", i, err)
}
if id != int64(i+1) {
t.Fatalf("Append id = %d, want %d", id, i+1)
}
}
records, err := s.List(context.Background(), 0)
if err != nil {
t.Fatalf("List: %v", err)
}
if len(records) != 3 {
t.Fatalf("len = %d, want 3", len(records))
}
// 最新的在前(按 id 降序)。
if records[0].ID != 3 || records[1].ID != 2 || records[2].ID != 1 {
t.Fatalf("order = %d,%d,%d, want 3,2,1", records[0].ID, records[1].ID, records[2].ID)
}
if !records[0].ShouldPush {
t.Fatalf("records[0].ShouldPush = false, want true")
}
if !records[0].PushResult.Pushed || records[0].PushResult.Route != RouteActiveClient {
t.Fatalf("records[0].PushResult = %+v, want pushed active_client", records[0].PushResult)
}
if !records[0].At.Equal(base.Add(2 * time.Minute)) {
t.Fatalf("records[0].At = %v, want %v", records[0].At, base.Add(2*time.Minute))
}
}
func TestStore_List_Limit(t *testing.T) {
t.Parallel()
s, err := NewStore(context.Background(), newTestDB(t), discardLog())
if err != nil {
t.Fatalf("NewStore: %v", err)
}
for i := 0; i < 5; i++ {
if _, err := s.Append(context.Background(), Record{Trigger: "heartbeat", Conclusion: "x"}); err != nil {
t.Fatalf("Append %d: %v", i, err)
}
}
records, err := s.List(context.Background(), 2)
if err != nil {
t.Fatalf("List: %v", err)
}
if len(records) != 2 {
t.Fatalf("len = %d, want 2", len(records))
}
if records[0].ID != 5 || records[1].ID != 4 {
t.Fatalf("ids = %d,%d, want 5,4", records[0].ID, records[1].ID)
}
}
func TestStore_NewStore_NilDB(t *testing.T) {
t.Parallel()
_, err := NewStore(context.Background(), nil, discardLog())
if !errors.Is(err, ErrNilDB) {
t.Fatalf("err = %v, want ErrNilDB", err)
}
}