(t *testing.T)
| 2616 | } |
| 2617 | |
| 2618 | func TestPromoteQueuedMessageUsesQueuedModelConfigID(t *testing.T) { |
| 2619 | t.Parallel() |
| 2620 | |
| 2621 | db, ps := dbtestutil.NewDB(t) |
| 2622 | replica := newTestServer(t, db, ps, uuid.New()) |
| 2623 | |
| 2624 | ctx := testutil.Context(t, testutil.WaitLong) |
| 2625 | user, org, modelConfigA := seedChatDependencies(t, db) |
| 2626 | modelConfigB := insertChatModelConfigWithCallConfig( |
| 2627 | t, |
| 2628 | db, |
| 2629 | user.ID, |
| 2630 | "openai", |
| 2631 | "gpt-4o-mini-promote-"+uuid.NewString(), |
| 2632 | codersdk.ChatModelCallConfig{}, |
| 2633 | ) |
| 2634 | |
| 2635 | chat := dbgen.Chat(t, db, database.Chat{ |
| 2636 | OrganizationID: org.ID, |
| 2637 | OwnerID: user.ID, |
| 2638 | LastModelConfigID: modelConfigA.ID, |
| 2639 | Title: "promote queued uses stored model", |
| 2640 | }) |
| 2641 | |
| 2642 | queuedContent, err := json.Marshal([]codersdk.ChatMessagePart{codersdk.ChatMessageText("queued with model b")}) |
| 2643 | require.NoError(t, err) |
| 2644 | queuedMessage, err := db.InsertChatQueuedMessage(ctx, database.InsertChatQueuedMessageParams{ |
| 2645 | ChatID: chat.ID, |
| 2646 | Content: queuedContent, |
| 2647 | ModelConfigID: uuid.NullUUID{ |
| 2648 | UUID: modelConfigB.ID, |
| 2649 | Valid: true, |
| 2650 | }, |
| 2651 | }) |
| 2652 | require.NoError(t, err) |
| 2653 | |
| 2654 | result, err := replica.PromoteQueued(ctx, chatd.PromoteQueuedOptions{ |
| 2655 | ChatID: chat.ID, |
| 2656 | QueuedMessageID: queuedMessage.ID, |
| 2657 | CreatedBy: user.ID, |
| 2658 | }) |
| 2659 | require.NoError(t, err) |
| 2660 | require.True(t, result.PromotedMessage.ModelConfigID.Valid) |
| 2661 | require.Equal(t, modelConfigB.ID, result.PromotedMessage.ModelConfigID.UUID) |
| 2662 | |
| 2663 | storedChat, err := db.GetChatByID(ctx, chat.ID) |
| 2664 | require.NoError(t, err) |
| 2665 | require.Equal(t, modelConfigB.ID, storedChat.LastModelConfigID) |
| 2666 | // The processor can pick up the pending chat immediately after |
| 2667 | // promotion, so this test only requires that promotion moved it out of |
| 2668 | // waiting and preserved the queued model configuration. |
| 2669 | require.Contains(t, []database.ChatStatus{ |
| 2670 | database.ChatStatusPending, |
| 2671 | database.ChatStatusRunning, |
| 2672 | }, storedChat.Status) |
| 2673 | } |
| 2674 | |
| 2675 | func TestPromoteQueuedMessageReloadsChatWhenModelConfigChangesDuringPending(t *testing.T) { |
nothing calls this directly
no test coverage detected