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

Function TestWorkingMemoryManager_Basic

pkg/memory/working_test.go:12–68  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestWorkingMemoryManager_Basic(t *testing.T) {
13 ctx := context.Background()
14 backend := backends.NewStateBackend()
15
16 // 创建 Working Memory 管理器(thread scope)
17 manager, err := NewWorkingMemoryManager(&WorkingMemoryConfig{
18 Backend: backend,
19 BasePath: "/working_memory/",
20 Scope: ScopeThread,
21 })
22 if err != nil {
23 t.Fatalf("create manager: %v", err)
24 }
25
26 threadID := "test-thread-1"
27 resourceID := "test-resource-1"
28
29 // 初始状态应该为空
30 content, err := manager.Get(ctx, threadID, resourceID)
31 if err != nil {
32 t.Fatalf("get initial: %v", err)
33 }
34 if content != "" {
35 t.Errorf("expected empty content, got: %s", content)
36 }
37
38 // 更新 Working Memory
39 testContent := "# User Profile\n\nName: Alice\nPreferences: concise code reviews"
40 err = manager.Update(ctx, threadID, resourceID, testContent)
41 if err != nil {
42 t.Fatalf("update: %v", err)
43 }
44
45 // 读取更新后的内容
46 content, err = manager.Get(ctx, threadID, resourceID)
47 if err != nil {
48 t.Fatalf("get after update: %v", err)
49 }
50 if content != testContent {
51 t.Errorf("expected %q, got %q", testContent, content)
52 }
53
54 // 再次更新(覆盖)
55 newContent := "# Updated Profile\n\nName: Alice Smith\nRole: Engineer"
56 err = manager.Update(ctx, threadID, resourceID, newContent)
57 if err != nil {
58 t.Fatalf("update again: %v", err)
59 }
60
61 content, err = manager.Get(ctx, threadID, resourceID)
62 if err != nil {
63 t.Fatalf("get after second update: %v", err)
64 }
65 if content != newContent {
66 t.Errorf("expected %q, got %q", newContent, content)
67 }
68}
69

Callers

nothing calls this directly

Calls 4

GetMethod · 0.95
UpdateMethod · 0.95
NewStateBackendFunction · 0.92
NewWorkingMemoryManagerFunction · 0.85

Tested by

no test coverage detected