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

Function TestAIProviderAuditDiff

enterprise/coderd/aibridge_provider_audit_test.go:28–104  ·  view source on GitHub ↗

TestAIProviderAuditDiff exercises the full HTTP -> enterprise auditor -> Postgres write path for AI provider updates. The mock auditor used elsewhere returns an empty diff, so this is the only place that proves changed properties land in the audit_logs row.

(t *testing.T)

Source from the content-addressed store, hash-verified

26// elsewhere returns an empty diff, so this is the only place that
27// proves changed properties land in the audit_logs row.
28func TestAIProviderAuditDiff(t *testing.T) {
29 t.Parallel()
30
31 db, ps := dbtestutil.NewDB(t)
32 auditor := entaudit.NewAuditor(
33 db,
34 entaudit.DefaultFilter,
35 backends.NewPostgres(db, true),
36 )
37
38 ownerClient, _ := coderdenttest.New(t, &coderdenttest.Options{
39 AuditLogging: true,
40 Options: &coderdtest.Options{
41 Database: db,
42 Pubsub: ps,
43 Auditor: auditor,
44 },
45 LicenseOptions: &coderdenttest.LicenseOptions{
46 Features: license.Features{
47 codersdk.FeatureAuditLog: 1,
48 },
49 },
50 })
51
52 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
53 defer cancel()
54
55 //nolint:gocritic // Owner role is the audience for this endpoint.
56 provider, err := ownerClient.CreateAIProvider(ctx, codersdk.CreateAIProviderRequest{
57 Type: codersdk.AIProviderTypeOpenAI,
58 Name: "audit-target",
59 DisplayName: "Audit Target",
60 Enabled: true,
61 BaseURL: "https://api.openai.com/v1",
62 })
63 require.NoError(t, err)
64
65 newDisplay := "Renamed"
66 newURL := "https://api.openai.com/v2"
67 disabled := false
68 _, err = ownerClient.UpdateAIProvider(ctx, provider.Name, codersdk.UpdateAIProviderRequest{
69 DisplayName: &newDisplay,
70 BaseURL: &newURL,
71 Enabled: &disabled,
72 })
73 require.NoError(t, err)
74
75 rows, err := db.GetAuditLogsOffset(
76 dbauthz.AsSystemRestricted(ctx),
77 database.GetAuditLogsOffsetParams{
78 ResourceType: string(database.ResourceTypeAIProvider),
79 LimitOpt: 10,
80 },
81 )
82 require.NoError(t, err)
83 require.Len(t, rows, 2, "expected one create and one update audit row")
84
85 // GetAuditLogsOffset returns entries sorted by time in descending order.

Callers

nothing calls this directly

Calls 11

NewDBFunction · 0.92
NewPostgresFunction · 0.92
NewFunction · 0.92
AsSystemRestrictedFunction · 0.92
CreateAIProviderMethod · 0.80
UpdateAIProviderMethod · 0.65
GetAuditLogsOffsetMethod · 0.65
LenMethod · 0.45
EqualMethod · 0.45
UnmarshalMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected