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

Function TestProcessEvent

pkg/memory/logic/manager_test.go:126–216  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

124}
125
126func TestProcessEvent(t *testing.T) {
127 ctx := context.Background()
128 store := NewInMemoryStore()
129
130 t.Run("with valid matcher", func(t *testing.T) {
131 // 创建测试 Matcher
132 matcher := &testMatcher{
133 supportedTypes: []string{"user_action"},
134 memories: []*LogicMemory{
135 {
136 Namespace: "user:789",
137 Scope: ScopeUser,
138 Type: "behavior",
139 Key: "click_pattern",
140 Value: "fast_clicker",
141 Description: "User clicks quickly",
142 Provenance: &memory.MemoryProvenance{
143 SourceType: memory.SourceUserInput,
144 Confidence: 0.75,
145 },
146 },
147 },
148 }
149
150 manager, err := NewManager(&ManagerConfig{
151 Store: store,
152 Matchers: []PatternMatcher{matcher},
153 })
154 require.NoError(t, err)
155
156 // 处理事件
157 event := Event{
158 Type: "user_action",
159 Source: "user:789",
160 Data: map[string]any{"action": "click"},
161 Timestamp: time.Now(),
162 }
163
164 err = manager.ProcessEvent(ctx, event)
165 require.NoError(t, err)
166
167 // 验证 Memory 已创建
168 retrieved, err := store.Get(ctx, "user:789", "click_pattern")
169 require.NoError(t, err)
170 assert.Equal(t, "fast_clicker", retrieved.Value)
171 assert.Equal(t, "User clicks quickly", retrieved.Description)
172 })
173
174 t.Run("no matchers", func(t *testing.T) {
175 manager, err := NewManager(&ManagerConfig{
176 Store: store,
177 Matchers: nil, // 没有 Matcher
178 })
179 require.NoError(t, err)
180
181 event := Event{
182 Type: "unknown",
183 Source: "user:999",

Callers

nothing calls this directly

Calls 5

ProcessEventMethod · 0.95
GetMethod · 0.95
NewInMemoryStoreFunction · 0.70
NewManagerFunction · 0.70
RunMethod · 0.45

Tested by

no test coverage detected