| 171 | } |
| 172 | |
| 173 | func TestEvents(t *testing.T) { |
| 174 | tmpDir := t.TempDir() |
| 175 | dbPath := filepath.Join(tmpDir, "test.db") |
| 176 | |
| 177 | svc, err := New(dbPath) |
| 178 | if err != nil { |
| 179 | t.Fatalf("New failed: %v", err) |
| 180 | } |
| 181 | defer func() { _ = svc.Close() }() |
| 182 | |
| 183 | ctx := context.Background() |
| 184 | |
| 185 | // Create session |
| 186 | sess, _ := svc.Create(ctx, &session.CreateRequest{ |
| 187 | AppName: "test-app", |
| 188 | UserID: "user-1", |
| 189 | AgentID: "agent-1", |
| 190 | }) |
| 191 | |
| 192 | // Test AppendEvent |
| 193 | t.Run("AppendEvent", func(t *testing.T) { |
| 194 | event := &session.Event{ |
| 195 | InvocationID: "inv-1", |
| 196 | AgentID: "agent-1", |
| 197 | Author: "user", |
| 198 | Content: types.Message{ |
| 199 | Role: types.RoleUser, |
| 200 | Content: "Hello", |
| 201 | }, |
| 202 | Metadata: map[string]any{ |
| 203 | "test": "value", |
| 204 | }, |
| 205 | } |
| 206 | |
| 207 | err := svc.AppendEvent(ctx, sess.ID(), event) |
| 208 | if err != nil { |
| 209 | t.Fatalf("AppendEvent failed: %v", err) |
| 210 | } |
| 211 | |
| 212 | if event.ID == "" { |
| 213 | t.Error("Event ID should be set") |
| 214 | } |
| 215 | }) |
| 216 | |
| 217 | // Test GetEvents |
| 218 | t.Run("GetEvents", func(t *testing.T) { |
| 219 | events, err := svc.GetEvents(ctx, sess.ID(), nil) |
| 220 | if err != nil { |
| 221 | t.Fatalf("GetEvents failed: %v", err) |
| 222 | } |
| 223 | |
| 224 | if len(events) == 0 { |
| 225 | t.Error("Expected at least one event") |
| 226 | } |
| 227 | |
| 228 | if events[0].Content.Content != "Hello" { |
| 229 | t.Errorf("Expected content 'Hello', got %q", events[0].Content.Content) |
| 230 | } |