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

Function TestChatDebugRunCOALESCEPreservation

coderd/database/querier_test.go:13728–13836  ·  view source on GitHub ↗

TestChatDebugRunCOALESCEPreservation verifies that the COALESCE pattern in UpdateChatDebugRun preserves every field that was not explicitly supplied in the update. If COALESCE were removed from any column, the corresponding field would silently null out.

(t *testing.T)

Source from the content-addressed store, hash-verified

13726// explicitly supplied in the update. If COALESCE were removed from
13727// any column, the corresponding field would silently null out.
13728func TestChatDebugRunCOALESCEPreservation(t *testing.T) {
13729 t.Parallel()
13730
13731 store, _ := dbtestutil.NewDB(t)
13732 ctx := testutil.Context(t, testutil.WaitMedium)
13733
13734 org := dbgen.Organization(t, store, database.Organization{})
13735 user := dbgen.User(t, store, database.User{})
13736
13737 providerName := "openai"
13738 modelName := "debug-model-coalesce-" + uuid.NewString()
13739
13740 dbgen.ChatProvider(t, store, database.ChatProvider{
13741 Provider: providerName,
13742 DisplayName: "Debug Provider",
13743 APIKey: "test-key",
13744 Enabled: true,
13745 CentralApiKeyEnabled: true,
13746 })
13747
13748 modelCfg, err := insertChatModelConfigForTest(ctx, t, store, database.InsertChatModelConfigParams{
13749 Provider: providerName,
13750 Model: modelName,
13751 DisplayName: "Debug Model",
13752 CreatedBy: uuid.NullUUID{UUID: user.ID, Valid: true},
13753 UpdatedBy: uuid.NullUUID{UUID: user.ID, Valid: true},
13754 Enabled: true,
13755 IsDefault: true,
13756 ContextLimit: 128000,
13757 CompressionThreshold: 80,
13758 Options: json.RawMessage(`{}`),
13759 })
13760 require.NoError(t, err)
13761
13762 chat, err := store.InsertChat(ctx, database.InsertChatParams{
13763 OrganizationID: org.ID,
13764 Status: database.ChatStatusWaiting,
13765 ClientType: database.ChatClientTypeUi,
13766 OwnerID: user.ID,
13767 LastModelConfigID: modelCfg.ID,
13768 Title: "chat-debug-coalesce-" + uuid.NewString(),
13769 })
13770 require.NoError(t, err)
13771
13772 rootChatID := uuid.New()
13773 parentChatID := uuid.New()
13774
13775 // Insert a fully-populated run so every nullable field has a value.
13776 original, err := store.InsertChatDebugRun(ctx, database.InsertChatDebugRunParams{
13777 ChatID: chat.ID,
13778 RootChatID: uuid.NullUUID{UUID: rootChatID, Valid: true},
13779 ParentChatID: uuid.NullUUID{UUID: parentChatID, Valid: true},
13780 ModelConfigID: uuid.NullUUID{UUID: modelCfg.ID, Valid: true},
13781 TriggerMessageID: sql.NullInt64{Int64: 42, Valid: true},
13782 HistoryTipMessageID: sql.NullInt64{Int64: 41, Valid: true},
13783 Kind: "chat_turn",
13784 Status: "in_progress",
13785 Provider: sql.NullString{String: providerName, Valid: true},

Callers

nothing calls this directly

Calls 11

NewDBFunction · 0.92
ContextFunction · 0.92
OrganizationFunction · 0.92
UserFunction · 0.92
ChatProviderFunction · 0.92
InsertChatMethod · 0.65
NewMethod · 0.65
InsertChatDebugRunMethod · 0.65
UpdateChatDebugRunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected