MCPcopy Create free account
hub / github.com/diillson/chatcli / TestBuiltinMemory_MoreDispatch

Function TestBuiltinMemory_MoreDispatch

cli/plugins/builtin_memory_test.go:28–84  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26}
27
28func TestBuiltinMemory_MoreDispatch(t *testing.T) {
29 fake := &fakeMemAdapter{}
30 SetMemoryAdapter(fake)
31 t.Cleanup(func() { SetMemoryAdapter(nil) })
32
33 p := NewBuiltinMemoryPlugin()
34 ctx := context.Background()
35
36 // recall
37 if _, err := p.Execute(ctx, []string{`{"cmd":"recall","args":{"query":"certs"}}`}); err != nil {
38 t.Fatalf("recall: %v", err)
39 }
40 if fake.lastRecall != "certs" {
41 t.Errorf("recall query not propagated: %q", fake.lastRecall)
42 }
43
44 // profile with the bare (no "fields" wrapper) form
45 if _, err := p.Execute(ctx, []string{`{"cmd":"profile","args":{"role":"SRE"}}`}); err != nil {
46 t.Fatalf("profile bare: %v", err)
47 }
48 if fake.lastProfile["role"] != "SRE" {
49 t.Errorf("bare profile form not parsed: %v", fake.lastProfile)
50 }
51
52 // argv (flag) form instead of JSON envelope
53 if _, err := p.Execute(ctx, []string{"remember", "--content", "argv fact"}); err != nil {
54 t.Fatalf("argv form: %v", err)
55 }
56 if fake.lastRemember[0] != "argv fact" {
57 t.Errorf("argv form not parsed: %v", fake.lastRemember)
58 }
59
60 // graph folded into @memory: neighbors routes the query through to the graph
61 if _, err := p.Execute(ctx, []string{`{"cmd":"neighbors","args":{"query":"auth"}}`}); err != nil {
62 t.Fatalf("neighbors: %v", err)
63 }
64 if fake.lastNeighbors != "auth" {
65 t.Errorf("neighbors query not propagated: %q", fake.lastNeighbors)
66 }
67 // map needs no args
68 if out, err := p.Execute(ctx, []string{`{"cmd":"map"}`}); err != nil || out != "map" {
69 t.Fatalf("map: out=%q err=%v", out, err)
70 }
71 // neighbors without query -> error
72 if _, err := p.Execute(ctx, []string{`{"cmd":"neighbors","args":{}}`}); err == nil {
73 t.Error("expected error for neighbors without query")
74 }
75
76 // unknown cmd -> error
77 if _, err := p.Execute(ctx, []string{`{"cmd":"bogus","args":{}}`}); err == nil {
78 t.Error("expected error for unknown cmd")
79 }
80 // forget without match -> error
81 if _, err := p.Execute(ctx, []string{`{"cmd":"forget","args":{}}`}); err == nil {
82 t.Error("expected error for forget without match")
83 }
84}
85

Callers

nothing calls this directly

Calls 6

ExecuteMethod · 0.95
SetMemoryAdapterFunction · 0.85
NewBuiltinMemoryPluginFunction · 0.85
ErrorfMethod · 0.80
ErrorMethod · 0.65
CleanupMethod · 0.45

Tested by

no test coverage detected