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

Function TestEventFiltering

pkg/session/sqlite/store_test.go:405–461  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

403}
404
405func TestEventFiltering(t *testing.T) {
406 tmpDir := t.TempDir()
407 dbPath := filepath.Join(tmpDir, "filter.db")
408 ctx := context.Background()
409
410 svc, _ := New(dbPath)
411 defer func() { _ = svc.Close() }()
412
413 sess, _ := svc.Create(ctx, &session.CreateRequest{
414 AppName: "test-app",
415 UserID: "user-1",
416 AgentID: "agent-1",
417 })
418
419 // Add events with different properties
420 _ = svc.AppendEvent(ctx, sess.ID(), &session.Event{
421 AgentID: "agent-1",
422 Author: "user",
423 Content: types.Message{Role: types.RoleUser, Content: "msg1"},
424 })
425 time.Sleep(10 * time.Millisecond)
426 _ = svc.AppendEvent(ctx, sess.ID(), &session.Event{
427 AgentID: "agent-2",
428 Author: "assistant",
429 Content: types.Message{Role: types.RoleAssistant, Content: "msg2"},
430 })
431
432 // Filter by agent
433 t.Run("FilterByAgent", func(t *testing.T) {
434 events, _ := svc.GetEvents(ctx, sess.ID(), &session.EventFilter{
435 AgentID: "agent-1",
436 })
437 if len(events) != 1 {
438 t.Errorf("Expected 1 event, got %d", len(events))
439 }
440 })
441
442 // Filter by author
443 t.Run("FilterByAuthor", func(t *testing.T) {
444 events, _ := svc.GetEvents(ctx, sess.ID(), &session.EventFilter{
445 Author: "user",
446 })
447 if len(events) != 1 {
448 t.Errorf("Expected 1 event, got %d", len(events))
449 }
450 })
451
452 // Filter with limit
453 t.Run("FilterWithLimit", func(t *testing.T) {
454 events, _ := svc.GetEvents(ctx, sess.ID(), &session.EventFilter{
455 Limit: 1,
456 })
457 if len(events) != 1 {
458 t.Errorf("Expected 1 event, got %d", len(events))
459 }
460 })
461}
462

Callers

nothing calls this directly

Calls 8

NewFunction · 0.70
CloseMethod · 0.65
CreateMethod · 0.65
AppendEventMethod · 0.65
IDMethod · 0.65
GetEventsMethod · 0.65
JoinMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected