MCPcopy
hub / github.com/google/ax / TestSQLiteEventLog_AppendAndEvents

Function TestSQLiteEventLog_AppendAndEvents

internal/controller/executor/sqlite_test.go:28–97  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26)
27
28func TestSQLiteEventLog_AppendAndEvents(t *testing.T) {
29 ctx := context.Background()
30 dbPath := filepath.Join(t.TempDir(), "test.db")
31
32 log, err := OpenSQLiteEventLog(dbPath)
33 if err != nil {
34 t.Fatalf("failed to open sqlite event log: %v", err)
35 }
36 defer log.Close()
37
38 // 1. Test Conversation Log
39 cev1 := &proto.ConversationEvent{
40 ConversationId: "conv-1",
41 Seq: 1,
42 ExecId: "task-1",
43 }
44
45 cev2 := &proto.ConversationEvent{
46 ConversationId: "conv-1",
47 Seq: 2,
48 ExecId: "task-2",
49 }
50
51 if _, err := log.Append(ctx, cev1); err != nil {
52 t.Fatalf("failed to append cev1: %v", err)
53 }
54 if _, err := log.Append(ctx, cev2); err != nil {
55 t.Fatalf("failed to append cev2: %v", err)
56 }
57
58 cEvents, err := log.Events(ctx, "conv-1")
59 if err != nil {
60 t.Fatalf("failed to read conversation events: %v", err)
61 }
62
63 if len(cEvents) != 2 {
64 t.Fatalf("expected 2 conversation events, got %d", len(cEvents))
65 }
66
67 if cEvents[0].ExecId != "task-1" || cEvents[1].ExecId != "task-2" {
68 t.Errorf("conversation events mismatch")
69 }
70
71 // 2. Test Execution Log
72 ee1 := &proto.ExecutionEvent{
73 ExecId: "task-1",
74 State: proto.State_STATE_PENDING,
75 Timestamp: timestamppb.Now(),
76 Inputs: []*proto.Message{
77 {Role: "user", Content: &proto.Content{Type: &proto.Content_Text{Text: &proto.TextContent{Text: "hello"}}}},
78 },
79 }
80
81 if err := log.AppendExec(ctx, ee1); err != nil {
82 t.Fatalf("failed to append ee1: %v", err)
83 }
84
85 eEvents, err := log.ExecEvents(ctx, "task-1")

Callers

nothing calls this directly

Calls 6

OpenSQLiteEventLogFunction · 0.85
CloseMethod · 0.65
AppendMethod · 0.65
EventsMethod · 0.65
AppendExecMethod · 0.65
ExecEventsMethod · 0.65

Tested by

no test coverage detected