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

Function TestGetChatMessagesForPromptByChatID

coderd/database/querier_test.go:11093–11308  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11091}
11092
11093func TestGetChatMessagesForPromptByChatID(t *testing.T) {
11094 t.Parallel()
11095
11096 // This test exercises a complex CTE query for prompt
11097 // reconstruction after compaction. It requires Postgres.
11098 db, _ := dbtestutil.NewDB(t)
11099 ctx := context.Background()
11100
11101 // Helper: create a chat model config (required FK for chats).
11102 user := dbgen.User(t, db, database.User{})
11103 org := dbgen.Organization(t, db, database.Organization{})
11104 dbgen.OrganizationMember(t, db, database.OrganizationMember{UserID: user.ID, OrganizationID: org.ID})
11105
11106 // An AI provider row is required as a FK for model configs.
11107 provider := dbgen.AIProvider(t, db, database.AIProvider{
11108 Type: database.AiProviderTypeOpenai,
11109 Name: "test-" + uuid.NewString(),
11110 DisplayName: sql.NullString{String: "OpenAI", Valid: true},
11111 Enabled: true,
11112 })
11113 dbgen.AIProviderKey(t, db, database.AIProviderKey{
11114 ProviderID: provider.ID,
11115 APIKey: "test-key",
11116 })
11117
11118 modelCfg, err := insertChatModelConfigForTest(ctx, t, db, database.InsertChatModelConfigParams{
11119 Provider: "openai",
11120 AIProviderID: uuid.NullUUID{UUID: provider.ID, Valid: true},
11121 Model: "test-model",
11122 DisplayName: "Test Model",
11123 CreatedBy: uuid.NullUUID{UUID: user.ID, Valid: true},
11124 UpdatedBy: uuid.NullUUID{UUID: user.ID, Valid: true},
11125 Enabled: true,
11126 IsDefault: true,
11127 ContextLimit: 128000,
11128 CompressionThreshold: 80,
11129 Options: json.RawMessage(`{}`),
11130 })
11131 require.NoError(t, err)
11132
11133 newChat := func(t *testing.T) database.Chat {
11134 t.Helper()
11135 chat, err := db.InsertChat(ctx, database.InsertChatParams{
11136 OrganizationID: org.ID,
11137 Status: database.ChatStatusWaiting,
11138 ClientType: database.ChatClientTypeUi,
11139 OwnerID: user.ID,
11140 LastModelConfigID: modelCfg.ID,
11141 Title: "test-chat-" + uuid.NewString(),
11142 })
11143 require.NoError(t, err)
11144 return chat
11145 }
11146
11147 insertMsg := func(
11148 t *testing.T,
11149 chatID uuid.UUID,
11150 role database.ChatMessageRole,

Callers

nothing calls this directly

Calls 14

NewDBFunction · 0.92
UserFunction · 0.92
OrganizationFunction · 0.92
OrganizationMemberFunction · 0.92
AIProviderFunction · 0.92
AIProviderKeyFunction · 0.92
HelperMethod · 0.65
InsertChatMethod · 0.65
InsertChatMessagesMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected