TestBuildProvidersSkipsBadRows exercises the skip-and-continue path directly: rows whose settings blob is malformed or whose type is not supported by the runtime builder are logged and excluded from the returned snapshot without surfacing a top-level error. The seed path filters most of these out be
(t *testing.T)
| 310 | // filters most of these out before insert, so we bypass it and insert |
| 311 | // rows straight into the database via dbgen. |
| 312 | func TestBuildProvidersSkipsBadRows(t *testing.T) { |
| 313 | t.Parallel() |
| 314 | |
| 315 | t.Run("CorruptSettings", func(t *testing.T) { |
| 316 | t.Parallel() |
| 317 | db, _ := dbtestutil.NewDB(t) |
| 318 | ctx := testutil.Context(t, testutil.WaitShort) |
| 319 | logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}) |
| 320 | |
| 321 | dbgen.AIProvider(t, db, database.AIProvider{ |
| 322 | Type: database.AiProviderTypeAnthropic, |
| 323 | Name: "anthropic-broken", |
| 324 | BaseUrl: "https://api.anthropic.com/", |
| 325 | Settings: sql.NullString{String: "not-json", Valid: true}, |
| 326 | }) |
| 327 | |
| 328 | providers, outcomes, err := BuildProviders(ctx, db, codersdk.AIBridgeConfig{}, logger) |
| 329 | require.NoError(t, err) |
| 330 | assert.Empty(t, providers) |
| 331 | require.Len(t, outcomes, 1) |
| 332 | assert.Equal(t, "anthropic-broken", outcomes[0].Name) |
| 333 | assert.Equal(t, aibridged.ProviderStatusError, outcomes[0].Status) |
| 334 | assert.Error(t, outcomes[0].Err) |
| 335 | }) |
| 336 | |
| 337 | t.Run("EnabledButNoKeys", func(t *testing.T) { |
| 338 | t.Parallel() |
| 339 | db, _ := dbtestutil.NewDB(t) |
| 340 | ctx := testutil.Context(t, testutil.WaitShort) |
| 341 | logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}) |
| 342 | |
| 343 | // Azure routes through the OpenAI-family builder, which rejects |
| 344 | // rows without keys when BYOK is disabled. The row must be |
| 345 | // classified as error and excluded from the snapshot. |
| 346 | dbgen.AIProvider(t, db, database.AIProvider{ |
| 347 | Type: database.AiProviderTypeAzure, |
| 348 | Name: "azure-openai", |
| 349 | BaseUrl: "https://example.openai.azure.com/", |
| 350 | }) |
| 351 | |
| 352 | providers, outcomes, err := BuildProviders(ctx, db, codersdk.AIBridgeConfig{}, logger) |
| 353 | require.NoError(t, err) |
| 354 | assert.Empty(t, providers) |
| 355 | require.Len(t, outcomes, 1) |
| 356 | assert.Equal(t, aibridged.ProviderStatusError, outcomes[0].Status) |
| 357 | }) |
| 358 | |
| 359 | t.Run("BadRowDoesNotBlockGoodRow", func(t *testing.T) { |
| 360 | t.Parallel() |
| 361 | db, _ := dbtestutil.NewDB(t) |
| 362 | ctx := testutil.Context(t, testutil.WaitShort) |
| 363 | logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}) |
| 364 | |
| 365 | dbgen.AIProvider(t, db, database.AIProvider{ |
| 366 | Type: database.AiProviderTypeAnthropic, |
| 367 | Name: "anthropic-broken", |
| 368 | BaseUrl: "https://api.anthropic.com/", |
| 369 | Settings: sql.NullString{String: "{not valid json", Valid: true}, |
nothing calls this directly
no test coverage detected