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

Function TestWorkingMemoryManager_Schema

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

Source from the content-addressed store, hash-verified

217}
218
219func TestWorkingMemoryManager_Schema(t *testing.T) {
220 ctx := context.Background()
221 backend := backends.NewStateBackend()
222
223 // 创建带 Schema 的管理器
224 schema := &JSONSchema{
225 Type: "object",
226 Properties: map[string]*JSONSchema{
227 "name": {Type: "string"},
228 "age": {Type: "integer"},
229 },
230 Required: []string{"name"},
231 }
232
233 manager, err := NewWorkingMemoryManager(&WorkingMemoryConfig{
234 Backend: backend,
235 BasePath: "/working_memory/",
236 Scope: ScopeThread,
237 Schema: schema,
238 })
239 if err != nil {
240 t.Fatalf("create manager: %v", err)
241 }
242
243 threadID := "test-thread"
244 resourceID := "test-resource"
245
246 // 有效的 JSON
247 validJSON := `{"name": "Alice", "age": 30}`
248 err = manager.Update(ctx, threadID, resourceID, validJSON)
249 if err != nil {
250 t.Errorf("valid JSON should be accepted: %v", err)
251 }
252
253 // 缺少必需字段
254 invalidJSON := `{"age": 30}`
255 err = manager.Update(ctx, threadID, resourceID, invalidJSON)
256 if err == nil {
257 t.Error("invalid JSON (missing required field) should be rejected")
258 }
259
260 // 无效的 JSON 格式
261 notJSON := "This is not JSON"
262 err = manager.Update(ctx, threadID, resourceID, notJSON)
263 if err == nil {
264 t.Error("non-JSON content should be rejected when schema is configured")
265 }
266}
267
268func TestWorkingMemoryManager_Delete(t *testing.T) {
269 ctx := context.Background()

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected