mirror of
https://github.com/hanzoai/ai.git
synced 2026-11-20 14:13:23 +00:00
/v1/admin/providers listed `openrouter` and offered a toggle that flipped a row
nothing read. Families resolved their address from deployment config alone
(conf.GetConfigString("OPENROUTER_URL")), so enabling one from the console did
nothing and reported success. A control that silently does nothing is worse than
no control — you cannot tell it from a broken upstream.
familyProvider now reads the admin row FIRST and falls back to config as the
bootstrap default: State gates the family, ProviderUrl/ClientSecret address it.
The old reasoning was "a family is not a database row: its address is
configuration, so this repository carries no routing detail". The second half
still holds — a row is runtime data and never lands in the repo — but the first
half is what cost us the admin surface.
The gate and the serving path now read the same thing. baseURL/serviceKey go
through the family's own providerFn, which is what pipeToFamily forwards through;
before, listing read conf directly while serving read the provider, so a family
disabled in the console stayed listed and served.
Also removes the same second-list bug this file already fixed once. Alongside
familyForProviderType's switch there was a second hand-written ladder in
GetModelProviderByName (`if name == "zen"`, `if name == "enso"`) that never named
openrouter — so `openrouter` resolved against the seed row instead of its family.
Both are derived from one list now, and TestFamilyProviderFnsCoverEveryFamily
fails on a third occurrence instead of production.
familyProvider is called during boot and in tests, so it tolerates an absent
store adapter rather than panicking on a nil db.
Co-authored-by: Hanzo Dev <[email protected]>
82 lines
2.9 KiB
Go
82 lines
2.9 KiB
Go
// Copyright 2026 Hanzo AI Inc. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package controllers
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hanzoai/ai/object"
|
|
)
|
|
|
|
// TestFamilyProviderFnsCoverEveryFamily is the guard for the bug that has now
|
|
// been written twice: a family added to modelFamilies but missing from a
|
|
// hand-written name ladder elsewhere. The first time it was
|
|
// familyForProviderType's switch, and OpenRouter's models were listed and served
|
|
// AROUND the funding gate. The second time it was GetModelProviderByName's
|
|
// `if name == "zen"` ladder, and `openrouter` resolved against the seed row
|
|
// instead of its family.
|
|
//
|
|
// Both ladders are now derived from a list. This asserts the two lists agree, so
|
|
// a third occurrence fails here instead of in production.
|
|
func TestFamilyProviderFnsCoverEveryFamily(t *testing.T) {
|
|
known := map[string]bool{}
|
|
for _, n := range object.FamilyProviderNames() {
|
|
known[n] = true
|
|
}
|
|
|
|
for _, f := range modelFamilies {
|
|
if !known[f.name] {
|
|
t.Errorf("family %q is in modelFamilies but not in object.familyProviderFns — "+
|
|
"GetModelProviderByName(%q) will resolve against the DB instead of the family",
|
|
f.name, f.name)
|
|
}
|
|
}
|
|
|
|
// And nothing resolves as a family that is not one.
|
|
names := map[string]bool{}
|
|
for _, f := range modelFamilies {
|
|
names[f.name] = true
|
|
}
|
|
for n := range known {
|
|
if !names[n] {
|
|
t.Errorf("object.familyProviderFns names %q, which is not a modelFamilies entry", n)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestFamilyGateAgreesWithServingPath: whatever address serves a family must be
|
|
// the address that decides whether it is listed. They used to be read from two
|
|
// places — pipeToFamily through providerFn (admin row first), listing through
|
|
// conf directly — so a family disabled in the console stayed listed and served.
|
|
func TestFamilyGateAgreesWithServingPath(t *testing.T) {
|
|
for _, f := range modelFamilies {
|
|
if f.providerFn == nil {
|
|
t.Errorf("family %q has no providerFn: its gate and its serving path cannot agree", f.name)
|
|
continue
|
|
}
|
|
prov := f.providerFn()
|
|
if prov == nil {
|
|
if f.enabled() {
|
|
t.Errorf("family %q reports enabled but resolves no provider — it would be listed and unservable", f.name)
|
|
}
|
|
continue
|
|
}
|
|
if !f.enabled() {
|
|
t.Errorf("family %q resolves a provider (%s) but reports disabled — it would be servable and unlisted",
|
|
f.name, prov.ProviderUrl)
|
|
}
|
|
}
|
|
}
|