(t *testing.T)
| 14268 | } |
| 14269 | |
| 14270 | func TestGetChatMessages_Pagination(t *testing.T) { |
| 14271 | t.Parallel() |
| 14272 | |
| 14273 | // seedChat creates a chat and inserts `count` user messages, returning |
| 14274 | // the chat and the inserted message IDs in the order they were |
| 14275 | // persisted (ascending). Callers use these IDs as cursor values. |
| 14276 | seedChat := func( |
| 14277 | t *testing.T, |
| 14278 | db database.Store, |
| 14279 | ownerID uuid.UUID, |
| 14280 | organizationID uuid.UUID, |
| 14281 | modelConfigID uuid.UUID, |
| 14282 | count int, |
| 14283 | ) (database.Chat, []int64) { |
| 14284 | t.Helper() |
| 14285 | |
| 14286 | chat := dbgen.Chat(t, db, database.Chat{ |
| 14287 | OrganizationID: organizationID, |
| 14288 | OwnerID: ownerID, |
| 14289 | LastModelConfigID: modelConfigID, |
| 14290 | Title: "pagination-test", |
| 14291 | }) |
| 14292 | |
| 14293 | ids := make([]int64, count) |
| 14294 | for i := range count { |
| 14295 | content, err := chatprompt.MarshalParts([]codersdk.ChatMessagePart{ |
| 14296 | codersdk.ChatMessageText(fmt.Sprintf("msg %d", i)), |
| 14297 | }) |
| 14298 | require.NoError(t, err) |
| 14299 | |
| 14300 | message := dbgen.ChatMessage(t, db, database.ChatMessage{ |
| 14301 | ChatID: chat.ID, |
| 14302 | CreatedBy: uuid.NullUUID{UUID: ownerID, Valid: true}, |
| 14303 | ModelConfigID: uuid.NullUUID{UUID: modelConfigID, Valid: true}, |
| 14304 | Role: database.ChatMessageRoleUser, |
| 14305 | Content: content, |
| 14306 | }) |
| 14307 | ids[i] = message.ID |
| 14308 | } |
| 14309 | return chat, ids |
| 14310 | } |
| 14311 | |
| 14312 | seedQueuedMessage := func( |
| 14313 | ctx context.Context, |
| 14314 | t *testing.T, |
| 14315 | db database.Store, |
| 14316 | chatID uuid.UUID, |
| 14317 | ) { |
| 14318 | t.Helper() |
| 14319 | |
| 14320 | content, err := json.Marshal([]codersdk.ChatMessagePart{ |
| 14321 | codersdk.ChatMessageText("queued"), |
| 14322 | }) |
| 14323 | require.NoError(t, err) |
| 14324 | _, err = db.InsertChatQueuedMessage( |
| 14325 | dbauthz.AsSystemRestricted(ctx), |
| 14326 | database.InsertChatQueuedMessageParams{ |
| 14327 | ChatID: chatID, |
nothing calls this directly
no test coverage detected