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

Function TestChatsTelemetry

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

Source from the content-addressed store, hash-verified

1552}
1553
1554func TestChatsTelemetry(t *testing.T) {
1555 t.Parallel()
1556
1557 ctx := testutil.Context(t, testutil.WaitMedium)
1558 db, _ := dbtestutil.NewDB(t)
1559
1560 user := dbgen.User(t, db, database.User{})
1561
1562 // Create chat providers (required FK for model configs).
1563 _ = dbgen.ChatProvider(t, db, database.ChatProvider{
1564 Provider: "anthropic",
1565 DisplayName: "Anthropic",
1566 })
1567 _ = dbgen.ChatProvider(t, db, database.ChatProvider{
1568 Provider: "openai",
1569 DisplayName: "OpenAI",
1570 })
1571
1572 // Create a model config.
1573 modelCfg := dbgen.ChatModelConfig(t, db, database.ChatModelConfig{
1574 Provider: "anthropic",
1575 Model: "claude-sonnet-4-20250514",
1576 DisplayName: "Claude Sonnet",
1577 IsDefault: true,
1578 ContextLimit: 200000,
1579 })
1580
1581 // Create a second model config to test full dump.
1582 modelCfg2 := dbgen.ChatModelConfig(t, db, database.ChatModelConfig{
1583 Provider: "openai",
1584 Model: "gpt-4o",
1585 DisplayName: "GPT-4o",
1586 })
1587
1588 // Create a soft-deleted model config — should NOT appear in telemetry.
1589 deletedCfg := dbgen.ChatModelConfig(t, db, database.ChatModelConfig{
1590 Provider: "anthropic",
1591 Model: "claude-deleted",
1592 DisplayName: "Deleted Model",
1593 ContextLimit: 100000,
1594 })
1595 err := db.DeleteChatModelConfigByID(ctx, deletedCfg.ID)
1596 require.NoError(t, err)
1597
1598 // Create a root chat with a workspace.
1599 org, err := db.GetDefaultOrganization(ctx)
1600 require.NoError(t, err)
1601 job := dbgen.ProvisionerJob(t, db, nil, database.ProvisionerJob{
1602 OrganizationID: org.ID,
1603 Type: database.ProvisionerJobTypeTemplateVersionDryRun,
1604 })
1605 tpl := dbgen.Template(t, db, database.Template{
1606 OrganizationID: org.ID,
1607 CreatedBy: user.ID,
1608 })
1609 tv := dbgen.TemplateVersion(t, db, database.TemplateVersion{
1610 OrganizationID: org.ID,
1611 TemplateID: uuid.NullUUID{UUID: tpl.ID, Valid: true},

Callers

nothing calls this directly

Calls 15

ContextFunction · 0.92
NewDBFunction · 0.92
UserFunction · 0.92
ChatProviderFunction · 0.92
ChatModelConfigFunction · 0.92
ProvisionerJobFunction · 0.92
TemplateFunction · 0.92
TemplateVersionFunction · 0.92
WorkspaceFunction · 0.92
WorkspaceBuildFunction · 0.92
ChatFunction · 0.92
NowFunction · 0.92

Tested by

no test coverage detected