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

Function TestWorkingMemoryScope

examples/memory-working/verify_test.go:50–98  ·  view source on GitHub ↗

TestWorkingMemoryScope 验证作用域隔离

(t *testing.T)

Source from the content-addressed store, hash-verified

48
49// TestWorkingMemoryScope 验证作用域隔离
50func TestWorkingMemoryScope(t *testing.T) {
51 ctx := context.Background()
52 backend := backends.NewStateBackend()
53
54 threadManager, _ := memory.NewWorkingMemoryManager(&memory.WorkingMemoryConfig{
55 Backend: backend,
56 BasePath: "/working_memory/",
57 Scope: memory.ScopeThread,
58 })
59
60 resourceManager, _ := memory.NewWorkingMemoryManager(&memory.WorkingMemoryConfig{
61 Backend: backend,
62 BasePath: "/working_memory/",
63 Scope: memory.ScopeResource,
64 })
65
66 thread1 := "thread-1"
67 thread2 := "thread-2"
68 resource := "resource-1"
69
70 // Thread scope - 不同 thread 应该隔离
71 if err := threadManager.Update(ctx, thread1, resource, "Thread 1 content"); err != nil {
72 t.Fatalf("Failed to update thread1: %v", err)
73 }
74 if err := threadManager.Update(ctx, thread2, resource, "Thread 2 content"); err != nil {
75 t.Fatalf("Failed to update thread2: %v", err)
76 }
77
78 content1, _ := threadManager.Get(ctx, thread1, resource)
79 content2, _ := threadManager.Get(ctx, thread2, resource)
80
81 if content1 == content2 {
82 t.Error("thread scope should isolate different threads")
83 }
84
85 // Resource scope - 相同 resource 应该共享
86 if err := resourceManager.Update(ctx, thread1, resource, "Shared content"); err != nil {
87 t.Fatalf("Failed to update resource: %v", err)
88 }
89
90 contentFromThread1, _ := resourceManager.Get(ctx, thread1, resource)
91 contentFromThread2, _ := resourceManager.Get(ctx, thread2, resource)
92
93 if contentFromThread1 != contentFromThread2 {
94 t.Error("resource scope should share content across threads")
95 }
96
97 t.Log("✓ Working Memory 作用域隔离验证通过")
98}
99
100// TestWorkingMemorySchema 验证 Schema 验证
101func TestWorkingMemorySchema(t *testing.T) {

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected