mirror of
https://github.com/Twigpine/zero.git
synced 2026-11-11 23:40:28 -10:00
normalizeProviders resolved every configured provider and aborted the entire config load if any one failed (e.g. a profile whose catalogID preset this build doesn't ship). That bricked the whole app even when the ACTIVE provider was valid: a clean clone + a real user config with one unknown-catalog provider exited with 'unknown provider "x"' and never started. Now a single unresolvable NON-active provider is dropped (the rest, including the active one, load normally); only the ACTIVE provider failing remains fatal. Tests cover both paths.
30 lines
1.3 KiB
Go
30 lines
1.3 KiB
Go
package config
|
|
|
|
import "testing"
|
|
|
|
// A single unresolvable, NON-active provider (e.g. one whose catalogID preset this
|
|
// build doesn't ship) must not crash resolution — it's dropped, the rest survive.
|
|
func TestNormalizeProvidersSkipsUnresolvableNonActive(t *testing.T) {
|
|
good := ProviderProfile{Name: "good", ProviderKind: ProviderKindOpenAICompatible, BaseURL: "https://api.example.com/v1", Model: "m"}
|
|
bad := ProviderProfile{Name: "badcat", CatalogID: "definitely-not-a-real-catalog-xyz", Model: "m"}
|
|
|
|
got, active, err := normalizeProviders([]ProviderProfile{good, bad}, "good")
|
|
if err != nil {
|
|
t.Fatalf("a bad NON-active provider must not fail resolution, got: %v", err)
|
|
}
|
|
if active.Name != "good" {
|
|
t.Fatalf("active = %q, want good", active.Name)
|
|
}
|
|
if len(got) != 1 || got[0].Name != "good" {
|
|
t.Fatalf("the unresolvable provider should be dropped, got %#v", got)
|
|
}
|
|
}
|
|
|
|
// But an unresolvable ACTIVE provider IS fatal — the run can't proceed without it.
|
|
func TestNormalizeProvidersFatalWhenActiveUnresolvable(t *testing.T) {
|
|
bad := ProviderProfile{Name: "badcat", CatalogID: "definitely-not-a-real-catalog-xyz", Model: "m"}
|
|
if _, _, err := normalizeProviders([]ProviderProfile{bad}, "badcat"); err == nil {
|
|
t.Fatal("an unresolvable ACTIVE provider must be a fatal error")
|
|
}
|
|
}
|