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

Function TestWorkingMemorySchema

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

TestWorkingMemorySchema 验证 Schema 验证

(t *testing.T)

Source from the content-addressed store, hash-verified

99
100// TestWorkingMemorySchema 验证 Schema 验证
101func TestWorkingMemorySchema(t *testing.T) {
102 ctx := context.Background()
103 backend := backends.NewStateBackend()
104
105 schema := &memory.JSONSchema{
106 Type: "object",
107 Properties: map[string]*memory.JSONSchema{
108 "name": {Type: "string"},
109 "age": {Type: "integer"},
110 },
111 Required: []string{"name"},
112 }
113
114 manager, _ := memory.NewWorkingMemoryManager(&memory.WorkingMemoryConfig{
115 Backend: backend,
116 BasePath: "/working_memory/",
117 Scope: memory.ScopeThread,
118 Schema: schema,
119 })
120
121 threadID := "test-thread"
122 resourceID := "test-resource"
123
124 // 有效的 JSON
125 validJSON := `{"name": "Alice", "age": 30}`
126 err := manager.Update(ctx, threadID, resourceID, validJSON)
127 if err != nil {
128 t.Errorf("valid JSON should be accepted: %v", err)
129 }
130
131 // 无效的 JSON(缺少必需字段)
132 invalidJSON := `{"age": 30}`
133 err = manager.Update(ctx, threadID, resourceID, invalidJSON)
134 if err == nil {
135 t.Error("invalid JSON should be rejected")
136 }
137
138 t.Log("✓ Working Memory Schema 验证通过")
139}

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected