(t *testing.T)
| 160 | } |
| 161 | |
| 162 | func TestSQLiteEventLog_DeleteEvents(t *testing.T) { |
| 163 | ctx := context.Background() |
| 164 | dbPath := filepath.Join(t.TempDir(), "test.db") |
| 165 | |
| 166 | log, err := OpenSQLiteEventLog(dbPath) |
| 167 | if err != nil { |
| 168 | t.Fatalf("failed to open sqlite event log: %v", err) |
| 169 | } |
| 170 | defer log.Close() |
| 171 | |
| 172 | // Setup data |
| 173 | cev1 := &proto.ConversationEvent{ConversationId: "conv-1", Seq: 1, ExecId: "task-1"} |
| 174 | cev2 := &proto.ConversationEvent{ConversationId: "conv-1", Seq: 2, ExecId: "task-2"} |
| 175 | cev3 := &proto.ConversationEvent{ConversationId: "conv-2", Seq: 1, ExecId: "task-3"} |
| 176 | |
| 177 | log.Append(ctx, cev1) |
| 178 | log.Append(ctx, cev2) |
| 179 | log.Append(ctx, cev3) |
| 180 | |
| 181 | ee1 := &proto.ExecutionEvent{ExecId: "task-1", State: proto.State_STATE_PENDING} |
| 182 | ee2 := &proto.ExecutionEvent{ExecId: "task-2", State: proto.State_STATE_COMPLETED} |
| 183 | ee3 := &proto.ExecutionEvent{ExecId: "task-3", State: proto.State_STATE_PENDING} |
| 184 | |
| 185 | log.AppendExec(ctx, ee1) |
| 186 | log.AppendExec(ctx, ee2) |
| 187 | log.AppendExec(ctx, ee3) |
| 188 | |
| 189 | // Delete conv-1 |
| 190 | if err := log.DeleteEvents(ctx, "conv-1"); err != nil { |
| 191 | t.Fatalf("failed to delete events: %v", err) |
| 192 | } |
| 193 | |
| 194 | // Verify conversation events |
| 195 | events, err := log.Events(ctx, "conv-1") |
| 196 | if err != nil { |
| 197 | t.Fatalf("failed to read events: %v", err) |
| 198 | } |
| 199 | if len(events) != 0 { |
| 200 | t.Errorf("expected 0 events for conv-1, got %d", len(events)) |
| 201 | } |
| 202 | |
| 203 | events, err = log.Events(ctx, "conv-2") |
| 204 | if err != nil { |
| 205 | t.Fatalf("failed to read events: %v", err) |
| 206 | } |
| 207 | if len(events) != 1 { |
| 208 | t.Errorf("expected 1 event for conv-2, got %d", len(events)) |
| 209 | } |
| 210 | |
| 211 | // Verify execution events |
| 212 | eEvents, err := log.ExecEvents(ctx, "task-1") |
| 213 | if err != nil { |
| 214 | t.Fatalf("failed to read exec events: %v", err) |
| 215 | } |
| 216 | if len(eEvents) != 0 { |
| 217 | t.Errorf("expected 0 exec events for task-1, got %d", len(eEvents)) |
| 218 | } |
| 219 |
nothing calls this directly
no test coverage detected