返回 DeepSeek-Reasonix
index_scope_test.go
根目录 / internal / memory / index_scope_test.go
1 package memory
2
3 import (
4 "strings"
5 "testing"
6 )
7
8 // #7995: the stable index and automatic recall must share one world view. On a
9 // name collision both scopes stay visible with qualified references, and the
10 // shadowed global entry says which project fact overrides it.
11 func TestIndexShowsBothScopesWithOverrideAnnotation(t *testing.T) {
12 store := recallTestStore(t)
13 recallTestWrite(t, store.Dir, Memory{
14 ID: "mem-proj", Name: "deploy-region", Title: "Deploy region",
15 Description: "This project deploys to eu-central-1", Type: TypeProject,
16 Scope: FactScopeProject, Body: "eu-central-1",
17 })
18 recallTestWrite(t, store.GlobalDir, Memory{
19 ID: "mem-glob", Name: "deploy-region", Title: "Deploy region",
20 Description: "Default deploy region", Type: TypeProject,
21 Scope: FactScopeGlobal, Body: "us-east-1",
22 })
23
24 index := store.Index()
25 for _, want := range []string{
26 "(project/deploy-region.md)",
27 "(global/deploy-region.md)",
28 "(overridden by project/deploy-region.md)",
29 } {
30 if !strings.Contains(index, want) {
31 t.Fatalf("index missing %q:\n%s", want, index)
32 }
33 }
34 if strings.Contains(index, "](deploy-region.md)") {
35 t.Fatalf("provider index must never use unqualified references:\n%s", index)
36 }
37 // The project entry (the recall winner) must not carry the annotation.
38 for line := range strings.SplitSeq(index, "\n") {
39 if strings.Contains(line, "(project/deploy-region.md)") && strings.Contains(line, "overridden") {
40 t.Fatalf("winning project entry wrongly annotated: %s", line)
41 }
42 }
43 }
44
44 lines GO