(t *testing.T)
| 4655 | } |
| 4656 | |
| 4657 | func TestGetChatUserPrompts(t *testing.T) { |
| 4658 | t.Parallel() |
| 4659 | |
| 4660 | insertUserMessage := func( |
| 4661 | t *testing.T, |
| 4662 | ctx context.Context, |
| 4663 | db database.Store, |
| 4664 | chatID uuid.UUID, |
| 4665 | modelConfigID uuid.UUID, |
| 4666 | userID uuid.UUID, |
| 4667 | parts []codersdk.ChatMessagePart, |
| 4668 | visibility database.ChatMessageVisibility, |
| 4669 | deleted bool, |
| 4670 | ) database.ChatMessage { |
| 4671 | t.Helper() |
| 4672 | content, err := chatprompt.MarshalParts(parts) |
| 4673 | require.NoError(t, err) |
| 4674 | msgs, err := db.InsertChatMessages(dbauthz.AsSystemRestricted(ctx), database.InsertChatMessagesParams{ |
| 4675 | ChatID: chatID, |
| 4676 | CreatedBy: []uuid.UUID{userID}, |
| 4677 | ModelConfigID: []uuid.UUID{modelConfigID}, |
| 4678 | Role: []database.ChatMessageRole{database.ChatMessageRoleUser}, |
| 4679 | ContentVersion: []int16{chatprompt.CurrentContentVersion}, |
| 4680 | Content: []string{string(content.RawMessage)}, |
| 4681 | Visibility: []database.ChatMessageVisibility{visibility}, |
| 4682 | InputTokens: []int64{0}, |
| 4683 | OutputTokens: []int64{0}, |
| 4684 | TotalTokens: []int64{0}, |
| 4685 | ReasoningTokens: []int64{0}, |
| 4686 | CacheCreationTokens: []int64{0}, |
| 4687 | CacheReadTokens: []int64{0}, |
| 4688 | ContextLimit: []int64{0}, |
| 4689 | Compressed: []bool{false}, |
| 4690 | TotalCostMicros: []int64{0}, |
| 4691 | RuntimeMs: []int64{0}, |
| 4692 | }) |
| 4693 | require.NoError(t, err) |
| 4694 | require.Len(t, msgs, 1) |
| 4695 | if deleted { |
| 4696 | require.NoError(t, db.SoftDeleteChatMessageByID(dbauthz.AsSystemRestricted(ctx), msgs[0].ID)) |
| 4697 | } |
| 4698 | return msgs[0] |
| 4699 | } |
| 4700 | |
| 4701 | t.Run("NewestFirstFiltering", func(t *testing.T) { |
| 4702 | t.Parallel() |
| 4703 | |
| 4704 | ctx := testutil.Context(t, testutil.WaitLong) |
| 4705 | client, db := newChatClientWithDatabase(t) |
| 4706 | user := coderdtest.CreateFirstUser(t, client.Client) |
| 4707 | modelConfig := createChatModelConfig(t, client) |
| 4708 | |
| 4709 | chat, err := db.InsertChat(dbauthz.AsSystemRestricted(ctx), database.InsertChatParams{ |
| 4710 | OrganizationID: user.OrganizationID, |
| 4711 | Status: database.ChatStatusWaiting, |
| 4712 | ClientType: database.ChatClientTypeUi, |
| 4713 | OwnerID: user.UserID, |
| 4714 | LastModelConfigID: modelConfig.ID, |
nothing calls this directly
no test coverage detected