返回 DeepSeek-Reasonix
recall_index_test.go
根目录 / internal / memory / recall_index_test.go
1 package memory
2
3 import "testing"
4
5 // The index and the direct store scan must be indistinguishable: same hits,
6 // same shadow, same suppression reasons.
7 func TestSetAutoRecallMatchesStoreScan(t *testing.T) {
8 store := recallTestStore(t)
9 recallTestWrite(t, store.Dir, Memory{
10 ID: "mem-a", Name: "fast-check", Title: "Fast check command",
11 Description: "The canonical fast check", Type: TypeProject, Scope: FactScopeProject,
12 Body: "Run make check-fast before pushing.",
13 })
14 set := &Set{Store: store, recall: BuildRecallIndex(store)}
15 for _, query := range []string{"what is the fast check command", "continue", "总结一下"} {
16 direct := AutoRecall(store, query, RecallOptions{})
17 indexed := set.AutoRecall(query, RecallOptions{})
18 if len(direct.Hits) != len(indexed.Hits) || direct.Suppressed != indexed.Suppressed ||
19 len(direct.ShadowHits) != len(indexed.ShadowHits) {
20 t.Fatalf("index diverged from scan for %q: direct=%+v indexed=%+v", query, direct, indexed)
21 }
22 }
23 if hits := set.AutoRecall("fast check command", RecallOptions{}).Hits; len(hits) != 1 {
24 t.Fatalf("indexed recall should hit: %+v", hits)
25 }
26
27 var nilSet *Set
28 if r := nilSet.AutoRecall("anything relevant", RecallOptions{}); r.Suppressed == "" {
29 t.Fatalf("nil set must suppress, got %+v", r)
30 }
31 }
32
33 // Writes rebuild the snapshot (and with it the index) through memory.Load —
34 // the invalidation contract that keeps Markdown the source of truth.
35 func TestLoadRebuildsIndexAfterWrite(t *testing.T) {
36 root := t.TempDir()
37 user, proj := root+"/user", root+"/project"
38 mustMkdir(t, proj+"/.git")
39 set := Load(Options{CWD: proj, UserDir: user})
40 if r := set.AutoRecall("release branch for hotfixes", RecallOptions{}); len(r.Hits) != 0 {
41 t.Fatalf("empty store recalled: %+v", r)
42 }
43 if _, err := set.Store.Save(Memory{Name: "release-branch", Description: "current release branch",
44 Body: "Hotfixes target the release branch release/1.21."}); err != nil {
45 t.Fatal(err)
46 }
47 reloaded := Load(Options{CWD: proj, UserDir: user})
48 if r := reloaded.AutoRecall("release branch for hotfixes", RecallOptions{}); len(r.Hits) != 1 {
49 t.Fatalf("reloaded index missed the new fact: %+v", r)
50 }
51 }
52
52 lines GO