MCPcopy Index your code
hub / github.com/coder/coder / TestPromoteQueuedRejectsArchivedChat

Function TestPromoteQueuedRejectsArchivedChat

coderd/x/chatd/chatd_test.go:9089–9144  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9087}
9088
9089func TestPromoteQueuedRejectsArchivedChat(t *testing.T) {
9090 t.Parallel()
9091
9092 db, ps := dbtestutil.NewDB(t)
9093 replica := newTestServer(t, db, ps, uuid.New())
9094
9095 ctx := testutil.Context(t, testutil.WaitLong)
9096 user, org, model := seedChatDependencies(t, db)
9097
9098 chat, err := replica.CreateChat(ctx, chatd.CreateOptions{
9099 OwnerID: user.ID,
9100 OrganizationID: org.ID,
9101 Title: "promote-archived",
9102 ModelConfigID: model.ID,
9103 InitialUserContent: []codersdk.ChatMessagePart{codersdk.ChatMessageText("hello")},
9104 })
9105 require.NoError(t, err)
9106
9107 // Queue a message by setting the chat to running first.
9108 chat, err = db.UpdateChatStatus(ctx, database.UpdateChatStatusParams{
9109 ID: chat.ID,
9110 Status: database.ChatStatusRunning,
9111 WorkerID: uuid.NullUUID{UUID: uuid.New(), Valid: true},
9112 StartedAt: sql.NullTime{Time: time.Now(), Valid: true},
9113 HeartbeatAt: sql.NullTime{Time: time.Now(), Valid: true},
9114 })
9115 require.NoError(t, err)
9116
9117 queuedResult, err := replica.SendMessage(ctx, chatd.SendMessageOptions{
9118 ChatID: chat.ID,
9119 Content: []codersdk.ChatMessagePart{codersdk.ChatMessageText("queued")},
9120 BusyBehavior: chatd.SendMessageBusyBehaviorQueue,
9121 })
9122 require.NoError(t, err)
9123 require.True(t, queuedResult.Queued)
9124
9125 // Move back to waiting, then archive.
9126 chat, err = db.UpdateChatStatus(ctx, database.UpdateChatStatusParams{
9127 ID: chat.ID,
9128 Status: database.ChatStatusWaiting,
9129 WorkerID: uuid.NullUUID{},
9130 StartedAt: sql.NullTime{},
9131 HeartbeatAt: sql.NullTime{},
9132 })
9133 require.NoError(t, err)
9134
9135 err = replica.ArchiveChat(ctx, chat)
9136 require.NoError(t, err)
9137
9138 _, err = replica.PromoteQueued(ctx, chatd.PromoteQueuedOptions{
9139 ChatID: chat.ID,
9140 QueuedMessageID: queuedResult.QueuedMessage.ID,
9141 CreatedBy: user.ID,
9142 })
9143 require.ErrorIs(t, err, chatd.ErrChatArchived)
9144}
9145
9146// TestPromoteQueuedWhileRequiresAction guards against the

Callers

nothing calls this directly

Calls 11

NewDBFunction · 0.92
ContextFunction · 0.92
ChatMessageTextFunction · 0.92
SendMessageMethod · 0.80
ArchiveChatMethod · 0.80
PromoteQueuedMethod · 0.80
newTestServerFunction · 0.70
seedChatDependenciesFunction · 0.70
NewMethod · 0.65
CreateChatMethod · 0.65
UpdateChatStatusMethod · 0.65

Tested by

no test coverage detected