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

Function TestChatDiffStatusSummaryTelemetry

coderd/telemetry/telemetry_test.go:1892–2000  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1890}
1891
1892func TestChatDiffStatusSummaryTelemetry(t *testing.T) {
1893 t.Parallel()
1894
1895 ctx := testutil.Context(t, testutil.WaitMedium)
1896 db, _ := dbtestutil.NewDB(t)
1897
1898 // Verify zero counts when no chat_diff_statuses exist.
1899 _, emptySnapshot := collectSnapshot(ctx, t, db, nil)
1900 require.NotNil(t, emptySnapshot.ChatDiffStatusSummary)
1901 assert.Equal(t, int64(0), emptySnapshot.ChatDiffStatusSummary.Total)
1902 assert.Equal(t, int64(0), emptySnapshot.ChatDiffStatusSummary.Open)
1903 assert.Equal(t, int64(0), emptySnapshot.ChatDiffStatusSummary.Merged)
1904 assert.Equal(t, int64(0), emptySnapshot.ChatDiffStatusSummary.Closed)
1905
1906 // Set up minimal FK chain: provider -> model config -> chat.
1907 user := dbgen.User(t, db, database.User{})
1908 org, err := db.GetDefaultOrganization(ctx)
1909 require.NoError(t, err)
1910
1911 _ = dbgen.ChatProvider(t, db, database.ChatProvider{
1912 Provider: "anthropic",
1913 DisplayName: "Anthropic",
1914 })
1915
1916 modelCfg := dbgen.ChatModelConfig(t, db, database.ChatModelConfig{
1917 Provider: "anthropic",
1918 Model: "claude-sonnet-4-20250514",
1919 DisplayName: "Claude Sonnet",
1920 IsDefault: true,
1921 ContextLimit: 200000,
1922 })
1923
1924 // Helper to create a chat and upsert its diff status.
1925 insertChatWithDiffStatus := func(prURL, state string) uuid.UUID {
1926 t.Helper()
1927 chat := dbgen.Chat(t, db, database.Chat{
1928 OrganizationID: org.ID,
1929 OwnerID: user.ID,
1930 LastModelConfigID: modelCfg.ID,
1931 Title: "Chat " + state,
1932 Status: database.ChatStatusCompleted,
1933 })
1934 now := dbtime.Now()
1935 _, chatErr := db.UpsertChatDiffStatus(ctx, database.UpsertChatDiffStatusParams{
1936 ChatID: chat.ID,
1937 Url: sql.NullString{String: prURL, Valid: prURL != ""},
1938 PullRequestState: sql.NullString{String: state, Valid: true},
1939 RefreshedAt: now,
1940 StaleAt: now,
1941 })
1942 require.NoError(t, chatErr)
1943 return chat.ID
1944 }
1945
1946 // Insert: 1 merged, 1 open, 1 closed (each with unique URLs).
1947 // For pull/1, first insert an older chat with stale "open" state,
1948 // then a newer chat with refreshed "merged" state. The dedup
1949 // query orders by cds.updated_at DESC, so "merged" should win.

Callers

nothing calls this directly

Calls 12

ContextFunction · 0.92
NewDBFunction · 0.92
UserFunction · 0.92
ChatProviderFunction · 0.92
ChatModelConfigFunction · 0.92
ChatFunction · 0.92
NowFunction · 0.92
collectSnapshotFunction · 0.85
HelperMethod · 0.65
UpsertChatDiffStatusMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected