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

Function TestWorkingMemoryManager_Scope

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

Source from the content-addressed store, hash-verified

68}
69
70func TestWorkingMemoryManager_Scope(t *testing.T) {
71 ctx := context.Background()
72 backend := backends.NewStateBackend()
73
74 // 测试 thread scope
75 threadManager, err := NewWorkingMemoryManager(&WorkingMemoryConfig{
76 Backend: backend,
77 BasePath: "/working_memory/",
78 Scope: ScopeThread,
79 })
80 if err != nil {
81 t.Fatalf("create thread manager: %v", err)
82 }
83
84 // 测试 resource scope
85 resourceManager, err := NewWorkingMemoryManager(&WorkingMemoryConfig{
86 Backend: backend,
87 BasePath: "/working_memory/",
88 Scope: ScopeResource,
89 })
90 if err != nil {
91 t.Fatalf("create resource manager: %v", err)
92 }
93
94 threadID1 := "thread-1"
95 threadID2 := "thread-2"
96 resourceID := "resource-1"
97
98 // Thread scope: 不同 thread 有独立的 working memory
99 err = threadManager.Update(ctx, threadID1, resourceID, "Thread 1 content")
100 if err != nil {
101 t.Fatalf("update thread 1: %v", err)
102 }
103
104 err = threadManager.Update(ctx, threadID2, resourceID, "Thread 2 content")
105 if err != nil {
106 t.Fatalf("update thread 2: %v", err)
107 }
108
109 content1, _ := threadManager.Get(ctx, threadID1, resourceID)
110 content2, _ := threadManager.Get(ctx, threadID2, resourceID)
111
112 if content1 == content2 {
113 t.Error("thread scope should have separate content for different threads")
114 }
115
116 // Resource scope: 相同 resource 的不同 thread 共享 working memory
117 err = resourceManager.Update(ctx, threadID1, resourceID, "Shared resource content")
118 if err != nil {
119 t.Fatalf("update resource from thread 1: %v", err)
120 }
121
122 contentFromThread1, _ := resourceManager.Get(ctx, threadID1, resourceID)
123 contentFromThread2, _ := resourceManager.Get(ctx, threadID2, resourceID)
124
125 if contentFromThread1 != contentFromThread2 {
126 t.Errorf("resource scope should share content: %q vs %q", contentFromThread1, contentFromThread2)
127 }

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected