Repository navigation
Expand file tree
/
Copy pathmulti_concept_routing_test.go
More file actions
112 lines (109 loc) · 4.02 KB
/
Copy pathmulti_concept_routing_test.go
File metadata and controls
112 lines (109 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package knowledge_test
import (
"context"
"fmt"
"testing"
"github.com/Agent-Field/codeaf/internal/knowledge"
)
func TestKnowledgeNewEvidenceUpdatesConceptsAcrossCatalogWindows(t *testing.T) {
v := knowledge.Open(t.TempDir())
if err := v.StartBuild(); err != nil {
t.Fatal(err)
}
updatedTitles := []string{}
withKnowledgeModel(t, func(p map[string]any) map[string]any {
if messages, ok := p["messages"].([]any); ok {
claims := []any{}
for _, raw := range messages {
s := raw.(map[string]any)
claims = append(claims, map[string]any{"local_id": s["id"], "text": s["text"], "scope": "Cedar", "topic": s["id"], "kind": "fact", "evidence": []any{map[string]any{"source": s["id"], "quote": s["text"]}}})
}
return map[string]any{"claims": claims}
}
if proposal, ok := p["proposed_subjects"]; ok {
return map[string]any{"subjects": proposal}
}
if catalog, ok := p["catalog"].([]any); ok {
existing, _ := p["existing_subjects"].([]any)
if len(existing) > 128 {
t.Errorf("existing concept catalog exceeds 128 entries: %d", len(existing))
}
if catalog[0].(map[string]any)["title"] == "shared-evidence" && len(existing) > 0 {
subject := existing[0].(map[string]any)
updatedTitles = append(updatedTitles, subject["title"].(string))
assignment := map[string]any{"existing_subject_id": subject["id"], "title": subject["title"], "scope": subject["scope"], "notes": []any{catalog[0].(map[string]any)["id"]}}
// Repeated assignments must not duplicate citations or pages.
return map[string]any{"subjects": []any{assignment, assignment}}
}
subjects := []any{}
for _, raw := range catalog {
note := raw.(map[string]any)
subjects = append(subjects, map[string]any{"title": "Concept " + note["title"].(string), "scope": "Cedar", "notes": []any{note["id"]}})
}
return map[string]any{"subjects": subjects}
}
if p["remaining_steps"] != nil {
return map[string]any{"action": "write", "sections": []any{}, "gaps": []any{}}
}
return map[string]any{"sections": []any{}, "questions": []any{}, "conflicts": []any{}}
})
for i := 0; i < 129; i++ {
if err := v.Capture(knowledge.Source{ID: fmt.Sprintf("source-%03d", i), Session: "history", Role: "user", TS: "2026-10-25T12:00:00Z", Text: fmt.Sprintf("Cedar mechanism %d has independent durable evidence.", i)}); err != nil {
t.Fatal(err)
}
}
for i := 0; i < 3; i++ {
if err := v.Flush(context.Background(), "fixture", true); err != nil {
t.Fatal(err)
}
}
before, err := v.Snapshot()
if err != nil {
t.Fatal(err)
}
original := map[string]string{}
for _, page := range before.Pages {
if page.Kind == "subject" {
original[page.Title] = page.ID
}
}
if len(original) != 129 {
t.Fatalf("expected 129 original concepts, got %d", len(original))
}
if err := v.Capture(knowledge.Source{ID: "shared-evidence", Session: "new-chat", Role: "user", TS: "2026-10-26T12:00:00Z", Text: "Cedar mechanisms share an additional operating constraint."}); err != nil {
t.Fatal(err)
}
if err := v.Flush(context.Background(), "fixture", true); err != nil {
t.Fatal(err)
}
if len(updatedTitles) != 2 || original[updatedTitles[0]] == original[updatedTitles[1]] {
t.Fatalf("shared evidence must reach distinct concepts in both catalog windows, got %v", updatedTitles)
}
for _, title := range updatedTitles {
id := original[title]
page, err := v.Read(id)
if err != nil || id == "" || page.Title != title || len(page.Evidence) != 2 {
t.Fatalf("concept must retain its identity and both source citations: id=%s evidence=%d err=%v", id, len(page.Evidence), err)
}
shared := false
for _, evidence := range page.Evidence {
shared = shared || evidence.Source == "shared-evidence"
}
if !shared {
t.Fatalf("concept %s lost the shared source citation", id)
}
}
after, err := v.Snapshot()
if err != nil {
t.Fatal(err)
}
count := 0
for _, page := range after.Pages {
if page.Kind == "subject" {
count++
}
}
if count != len(original) {
t.Fatalf("shared evidence created an extra concept: %d -> %d", len(original), count)
}
}