返回 DeepSeek-Reasonix
usecapability_memory_description_test.go
根目录 / internal / agent / usecapability_memory_description_test.go
1 package agent
2
3 import (
4 "context"
5 "encoding/json"
6 "fmt"
7 "strings"
8 "testing"
9
10 "reasonix/internal/memory"
11 "reasonix/internal/tool"
12 )
13
14 func TestUseCapabilityMemoryDescriptionNamesRoutableTools(t *testing.T) {
15 reg := tool.NewRegistry()
16 store := memory.Store{Dir: t.TempDir()}
17 for _, tl := range []tool.Tool{
18 memory.NewRecallTool(store),
19 memory.NewRememberTool(store),
20 memory.NewForgetTool(store),
21 } {
22 reg.Add(tl)
23 }
24 proxy := NewUseCapabilityTool(context.Background(), nil, nil, reg, nil, nil, nil)
25 description := proxy.Description()
26 if strings.Contains(description, "memory:recall") {
27 t.Fatal("description must not advertise the unregistered memory:recall route")
28 }
29 for _, contract := range []string{
30 "description+body required",
31 `activation="relevant" on create`,
32 "omit activation on update",
33 `"pinned" only if user asks`,
34 "memory:forget(name)",
35 "tool:memory(operation=search|read|list)",
36 } {
37 if !strings.Contains(description, contract) {
38 t.Errorf("description does not document %q", contract)
39 }
40 }
41
42 for id, wantTarget := range map[string]string{
43 "memory:remember": "remember",
44 "memory:forget": "forget",
45 "tool:memory": "memory",
46 } {
47 t.Run(id, func(t *testing.T) {
48 if !strings.Contains(description, id) {
49 t.Fatalf("description does not advertise %q", id)
50 }
51 call := json.RawMessage(fmt.Sprintf(`{"action":"call","capability_id":%q,"arguments":{}}`, id))
52 resolved, err := proxy.ResolveCall(context.Background(), call)
53 if err != nil {
54 t.Fatalf("ResolveCall(%q): %v", id, err)
55 }
56 if resolved.Target == nil || resolved.TargetName != wantTarget {
57 t.Fatalf("ResolveCall(%q) target = %q, want %q", id, resolved.TargetName, wantTarget)
58 }
59 })
60 }
61 }
62
62 lines GO