From 7867a73a6a3f97eefcddea21191556e83ffb82ad Mon Sep 17 00:00:00 2001 From: Sergey Kozyrenko Date: Wed, 24 Jun 2026 09:49:00 +0700 Subject: [PATCH] test(providers): guard providerRegistry against AllProviderTypes drift A type present in only one of the two hand-maintained lists fails silently: accepted by the API then erroring "unknown provider type" at construction, or rejected 422 despite working. Assert set-equality and canonical names so drift fails in CI instead. Co-Authored-By: Claude Opus 4.8 --- backend/pkg/providers/registry_test.go | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 backend/pkg/providers/registry_test.go diff --git a/backend/pkg/providers/registry_test.go b/backend/pkg/providers/registry_test.go new file mode 100644 index 00000000..205177f1 --- /dev/null +++ b/backend/pkg/providers/registry_test.go @@ -0,0 +1,40 @@ +package providers + +import ( + "testing" + + "pentagi/pkg/providers/provider" + + "github.com/stretchr/testify/assert" +) + +// TestProviderRegistryMatchesAllProviderTypes keeps provider.AllProviderTypes (the +// API whitelist) and providerRegistry (construction wiring) in sync. Drift fails +// silently: a type in only AllProviderTypes is accepted then errors "unknown +// provider type" at construction; a type in only providerRegistry is rejected 422 +// despite working. Keep the sets equal. +func TestProviderRegistryMatchesAllProviderTypes(t *testing.T) { + registryTypes := make(map[provider.ProviderType]struct{}, len(providerRegistry)) + for _, e := range providerRegistry { + if _, dup := registryTypes[e.Type]; dup { + t.Errorf("duplicate providerRegistry entry for %q", e.Type) + } + registryTypes[e.Type] = struct{}{} + assert.Equal(t, provider.ProviderName(e.Type), e.Name, + "registry Name for %q must be the canonical provider name", e.Type) + } + + allTypes := make(map[provider.ProviderType]struct{}, len(provider.AllProviderTypes)) + for _, pt := range provider.AllProviderTypes { + allTypes[pt] = struct{}{} + } + + for pt := range allTypes { + _, ok := registryTypes[pt] + assert.Truef(t, ok, "%q is in AllProviderTypes but missing from providerRegistry", pt) + } + for pt := range registryTypes { + _, ok := allTypes[pt] + assert.Truef(t, ok, "%q is in providerRegistry but missing from AllProviderTypes", pt) + } +}