MCPcopy Create free account
hub / github.com/astercloud/aster / TestLineageGraph_GetDerivedMemories

Function TestLineageGraph_GetDerivedMemories

pkg/memory/lineage_test.go:30–107  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28}
29
30func TestLineageGraph_GetDerivedMemories(t *testing.T) {
31 lg := NewLineageGraph()
32
33 // Create a lineage tree:
34 // mem-1
35 // ├─ mem-2
36 // └─ mem-3
37 // └─ mem-4
38
39 lg.TrackMemory("mem-1", &LineageMetadata{
40 ID: "mem-1",
41 SourceIDs: []string{"session-1"},
42 DerivedFromIDs: []string{},
43 CreatedAt: time.Now().Unix(),
44 })
45
46 lg.TrackMemory("mem-2", &LineageMetadata{
47 ID: "mem-2",
48 SourceIDs: []string{"session-1"},
49 DerivedFromIDs: []string{"mem-1"},
50 CreatedAt: time.Now().Unix(),
51 })
52
53 lg.TrackMemory("mem-3", &LineageMetadata{
54 ID: "mem-3",
55 SourceIDs: []string{"session-1"},
56 DerivedFromIDs: []string{"mem-1"},
57 CreatedAt: time.Now().Unix(),
58 })
59
60 lg.TrackMemory("mem-4", &LineageMetadata{
61 ID: "mem-4",
62 SourceIDs: []string{"session-1"},
63 DerivedFromIDs: []string{"mem-3"},
64 CreatedAt: time.Now().Unix(),
65 })
66
67 // Get all derived from mem-1
68 derived := lg.GetDerivedMemories("mem-1")
69
70 // Should include mem-2, mem-3, mem-4
71 if len(derived) != 3 {
72 t.Fatalf("GetDerivedMemories() returned %d memories, want 3", len(derived))
73 }
74
75 // Check all expected IDs are present
76 expectedIDs := map[string]bool{
77 "mem-2": false,
78 "mem-3": false,
79 "mem-4": false,
80 }
81
82 for _, id := range derived {
83 if _, exists := expectedIDs[id]; exists {
84 expectedIDs[id] = true
85 } else {
86 t.Errorf("Unexpected derived memory: %v", id)
87 }

Callers

nothing calls this directly

Calls 3

TrackMemoryMethod · 0.95
GetDerivedMemoriesMethod · 0.95
NewLineageGraphFunction · 0.85

Tested by

no test coverage detected