(t *testing.T)
| 13155 | } |
| 13156 | |
| 13157 | func TestFinalizeStaleChatDebugRows(t *testing.T) { |
| 13158 | t.Parallel() |
| 13159 | |
| 13160 | store, _ := dbtestutil.NewDB(t) |
| 13161 | ctx := testutil.Context(t, testutil.WaitMedium) |
| 13162 | |
| 13163 | org := dbgen.Organization(t, store, database.Organization{}) |
| 13164 | user := dbgen.User(t, store, database.User{}) |
| 13165 | |
| 13166 | providerName := "openai" |
| 13167 | modelName := "debug-model-finalize-" + uuid.NewString() |
| 13168 | |
| 13169 | dbgen.ChatProvider(t, store, database.ChatProvider{ |
| 13170 | Provider: providerName, |
| 13171 | DisplayName: "Debug Provider", |
| 13172 | APIKey: "test-key", |
| 13173 | Enabled: true, |
| 13174 | CentralApiKeyEnabled: true, |
| 13175 | }) |
| 13176 | |
| 13177 | modelCfg, err := insertChatModelConfigForTest(ctx, t, store, database.InsertChatModelConfigParams{ |
| 13178 | Provider: providerName, |
| 13179 | Model: modelName, |
| 13180 | DisplayName: "Debug Model", |
| 13181 | CreatedBy: uuid.NullUUID{UUID: user.ID, Valid: true}, |
| 13182 | UpdatedBy: uuid.NullUUID{UUID: user.ID, Valid: true}, |
| 13183 | Enabled: true, |
| 13184 | IsDefault: true, |
| 13185 | ContextLimit: 128000, |
| 13186 | CompressionThreshold: 80, |
| 13187 | Options: json.RawMessage(`{}`), |
| 13188 | }) |
| 13189 | require.NoError(t, err) |
| 13190 | |
| 13191 | chat, err := store.InsertChat(ctx, database.InsertChatParams{ |
| 13192 | OrganizationID: org.ID, |
| 13193 | Status: database.ChatStatusWaiting, |
| 13194 | ClientType: database.ChatClientTypeUi, |
| 13195 | OwnerID: user.ID, |
| 13196 | LastModelConfigID: modelCfg.ID, |
| 13197 | Title: "chat-finalize-" + uuid.NewString(), |
| 13198 | }) |
| 13199 | require.NoError(t, err) |
| 13200 | |
| 13201 | // staleTime is well before the threshold so rows stamped with it |
| 13202 | // are considered stale. The threshold sits between staleTime and |
| 13203 | // NOW(), letting us create rows that are stale-by-age and rows |
| 13204 | // that are fresh-by-age in the same test. |
| 13205 | staleTime := time.Now().Add(-2 * time.Hour) |
| 13206 | staleThreshold := time.Now().Add(-1 * time.Hour) |
| 13207 | |
| 13208 | // preExistingError is attached to staleStep so we can verify |
| 13209 | // that finalization preserves pre-existing error JSON rather |
| 13210 | // than clearing or overwriting it. |
| 13211 | preExistingError := json.RawMessage(`{"code":"timeout","message":"upstream deadline exceeded"}`) |
| 13212 | |
| 13213 | // --- staleRun: in_progress run with no finished_at --- should be |
| 13214 | // finalized. |
nothing calls this directly
no test coverage detected