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

Function TestInMemoryService_GetState

pkg/session/inmemory_test.go:433–541  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

431}
432
433func TestInMemoryService_GetState(t *testing.T) {
434 t.Skip("Skipping: inmemory service implementation has issues with state retrieval")
435 ctx := context.Background()
436
437 t.Run("获取所有状态", func(t *testing.T) {
438 service := NewInMemoryService()
439 sess, _ := service.Create(ctx, &CreateRequest{
440 AppName: "test-app",
441 UserID: "user-1",
442 AgentID: "agent-1",
443 })
444
445 // 添加各种作用域的状态
446 event := &Event{
447 ID: "evt-1",
448 Timestamp: time.Now(),
449 InvocationID: "inv-1",
450 AgentID: "agent-1",
451 Branch: "root",
452 Author: "system",
453 Content: types.Message{
454 Role: types.RoleSystem,
455 Content: "State setup",
456 },
457 Actions: EventActions{
458 StateDelta: map[string]any{
459 "app:version": "1.0.0",
460 "user:language": "zh-CN",
461 "session:page": 1,
462 "temp:cache_key": "temp-value",
463 },
464 },
465 }
466 if err := service.AppendEvent(ctx, sess.ID(), event); err != nil {
467 t.Fatalf("AppendEvent failed: %v", err)
468 }
469
470 // 通过Session接口访问状态
471 retrievedSess, err := service.Get(ctx, &GetRequest{
472 SessionID: sess.ID(),
473 })
474 require.NoError(t, err)
475 state := retrievedSess.State()
476 assert.NotNil(t, state)
477 // 验证状态存在
478 assert.True(t, state.Has("app:version"))
479 assert.True(t, state.Has("user:language"))
480 assert.True(t, state.Has("session:page"))
481 })
482
483 t.Run("按作用域过滤", func(t *testing.T) {
484 service := NewInMemoryService()
485 sess, _ := service.Create(ctx, &CreateRequest{
486 AppName: "test-app",
487 UserID: "user-1",
488 AgentID: "agent-1",
489 })
490

Callers

nothing calls this directly

Calls 9

CreateMethod · 0.95
AppendEventMethod · 0.95
GetMethod · 0.95
NewInMemoryServiceFunction · 0.85
IDMethod · 0.65
StateMethod · 0.65
HasMethod · 0.65
GetMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected