TestChatDebugStepCOALESCEPreservation verifies that the COALESCE pattern in UpdateChatDebugStep 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)
| 13840 | // explicitly supplied in the update. If COALESCE were removed from |
| 13841 | // any column, the corresponding field would silently null out. |
| 13842 | func TestChatDebugStepCOALESCEPreservation(t *testing.T) { |
| 13843 | t.Parallel() |
| 13844 | |
| 13845 | store, _ := dbtestutil.NewDB(t) |
| 13846 | ctx := testutil.Context(t, testutil.WaitMedium) |
| 13847 | |
| 13848 | org := dbgen.Organization(t, store, database.Organization{}) |
| 13849 | user := dbgen.User(t, store, database.User{}) |
| 13850 | |
| 13851 | providerName := "openai" |
| 13852 | modelName := "debug-step-coalesce-" + uuid.NewString() |
| 13853 | |
| 13854 | dbgen.ChatProvider(t, store, database.ChatProvider{ |
| 13855 | Provider: providerName, |
| 13856 | DisplayName: "Debug Provider", |
| 13857 | APIKey: "test-key", |
| 13858 | Enabled: true, |
| 13859 | CentralApiKeyEnabled: true, |
| 13860 | }) |
| 13861 | |
| 13862 | modelCfg, err := insertChatModelConfigForTest(ctx, t, store, database.InsertChatModelConfigParams{ |
| 13863 | Provider: providerName, |
| 13864 | Model: modelName, |
| 13865 | DisplayName: "Debug Model", |
| 13866 | CreatedBy: uuid.NullUUID{UUID: user.ID, Valid: true}, |
| 13867 | UpdatedBy: uuid.NullUUID{UUID: user.ID, Valid: true}, |
| 13868 | Enabled: true, |
| 13869 | IsDefault: true, |
| 13870 | ContextLimit: 128000, |
| 13871 | CompressionThreshold: 80, |
| 13872 | Options: json.RawMessage(`{}`), |
| 13873 | }) |
| 13874 | require.NoError(t, err) |
| 13875 | |
| 13876 | chat, err := store.InsertChat(ctx, database.InsertChatParams{ |
| 13877 | OrganizationID: org.ID, |
| 13878 | Status: database.ChatStatusWaiting, |
| 13879 | ClientType: database.ChatClientTypeUi, |
| 13880 | OwnerID: user.ID, |
| 13881 | LastModelConfigID: modelCfg.ID, |
| 13882 | Title: "chat-step-coalesce-" + uuid.NewString(), |
| 13883 | }) |
| 13884 | require.NoError(t, err) |
| 13885 | |
| 13886 | run, err := store.InsertChatDebugRun(ctx, database.InsertChatDebugRunParams{ |
| 13887 | ChatID: chat.ID, |
| 13888 | Kind: "chat_turn", |
| 13889 | Status: "in_progress", |
| 13890 | }) |
| 13891 | require.NoError(t, err) |
| 13892 | |
| 13893 | // Insert a fully-populated step so every nullable field has a value. |
| 13894 | original, err := store.InsertChatDebugStep(ctx, database.InsertChatDebugStepParams{ |
| 13895 | RunID: run.ID, |
| 13896 | ChatID: chat.ID, |
| 13897 | StepNumber: 1, |
| 13898 | Operation: "llm_call", |
| 13899 | Status: "in_progress", |
nothing calls this directly
no test coverage detected