nolint:paralleltest // It uses LockIDDBPurge.
(t *testing.T)
| 1932 | |
| 1933 | //nolint:paralleltest // It uses LockIDDBPurge. |
| 1934 | func TestPurgeChatDebugRuns(t *testing.T) { |
| 1935 | now := time.Date(2025, 6, 15, 12, 0, 0, 0, time.UTC) |
| 1936 | |
| 1937 | type chatDebugDeps struct { |
| 1938 | user database.User |
| 1939 | org database.Organization |
| 1940 | modelConfig database.ChatModelConfig |
| 1941 | } |
| 1942 | // setupChatDebugDeps creates the user, organization, and chat model config dependencies needed for the chat debug retention test. |
| 1943 | setupChatDebugDeps := func(t *testing.T, db database.Store) chatDebugDeps { |
| 1944 | t.Helper() |
| 1945 | user := dbgen.User(t, db, database.User{}) |
| 1946 | org := dbgen.Organization(t, db, database.Organization{}) |
| 1947 | _ = dbgen.OrganizationMember(t, db, database.OrganizationMember{ |
| 1948 | UserID: user.ID, |
| 1949 | OrganizationID: org.ID, |
| 1950 | }) |
| 1951 | _ = dbgen.ChatProvider(t, db, database.ChatProvider{ |
| 1952 | Provider: "openai", |
| 1953 | DisplayName: "OpenAI", |
| 1954 | }) |
| 1955 | modelConfig := dbgen.ChatModelConfig(t, db, database.ChatModelConfig{ |
| 1956 | Provider: "openai", |
| 1957 | Model: "test-model", |
| 1958 | ContextLimit: 8192, |
| 1959 | }) |
| 1960 | return chatDebugDeps{user: user, org: org, modelConfig: modelConfig} |
| 1961 | } |
| 1962 | createChat := func(ctx context.Context, t *testing.T, db database.Store, rawDB *sql.DB, deps chatDebugDeps, archived bool, updatedAt time.Time) database.Chat { |
| 1963 | t.Helper() |
| 1964 | chat := dbgen.Chat(t, db, database.Chat{ |
| 1965 | OrganizationID: deps.org.ID, |
| 1966 | OwnerID: deps.user.ID, |
| 1967 | LastModelConfigID: deps.modelConfig.ID, |
| 1968 | Title: "debug-retention-test-chat", |
| 1969 | }) |
| 1970 | if archived { |
| 1971 | _, err := db.ArchiveChatByID(ctx, chat.ID) |
| 1972 | require.NoError(t, err) |
| 1973 | } |
| 1974 | _, err := rawDB.ExecContext(ctx, "UPDATE chats SET updated_at = $1 WHERE id = $2", updatedAt, chat.ID) |
| 1975 | require.NoError(t, err) |
| 1976 | return chat |
| 1977 | } |
| 1978 | createDebugRunWithStep := func(ctx context.Context, t *testing.T, db database.Store, chatID uuid.UUID, updatedAt time.Time, finished bool) database.ChatDebugRun { |
| 1979 | t.Helper() |
| 1980 | run, err := db.InsertChatDebugRun(ctx, database.InsertChatDebugRunParams{ |
| 1981 | ChatID: chatID, |
| 1982 | Kind: string(codersdk.ChatDebugRunKindChatTurn), |
| 1983 | Status: string(codersdk.ChatDebugStatusInProgress), |
| 1984 | Provider: sql.NullString{String: "openai", Valid: true}, |
| 1985 | Model: sql.NullString{String: "gpt-4o-mini", Valid: true}, |
| 1986 | StartedAt: sql.NullTime{Time: updatedAt.Add(-time.Minute), Valid: true}, |
| 1987 | UpdatedAt: sql.NullTime{Time: updatedAt, Valid: true}, |
| 1988 | }) |
| 1989 | require.NoError(t, err) |
| 1990 | _, err = db.InsertChatDebugStep(ctx, database.InsertChatDebugStepParams{ |
| 1991 | RunID: run.ID, |
nothing calls this directly
no test coverage detected