mirror of
https://github.com/hanzoai/ai.git
synced 2026-11-21 02:05:26 +00:00
Adding OpenRouter to modelFamilies made its 338 prepaid models discoverable, listable and routable. Resolving a request to its family was a separate hand-written switch naming only Zen and Enso, and that switch was not updated. Every dispatch site guards on the result being non-nil, so OpenRouter requests fell through to the generic relay -- carrying the provider credential, and going around pipeToFamily, which is where the funding gate runs. Listed, served, and ungated, on a real-cash balance. Nothing was exposed in production: the seeded provider row is disabled, so the request failed before reaching an upstream. But that row is documented as the switch that enables the feature, and flipping it would have opened the hole rather than completing the work. The lookup now derives from modelFamilies, so a family that exists is a family that resolves and a new one cannot silently skip the gate. The provider Type moves onto the family as data, next to the name and prefix it belongs with. The test asserts the DISPATCH over every registered family rather than the predicate for a fixed set, because a test that asserted the predicate is what let this through.
61 lines
2.5 KiB
Go
61 lines
2.5 KiB
Go
package controllers
|
|
|
|
import "testing"
|
|
|
|
// EVERY family must be reachable through familyForProviderType, because that resolution is
|
|
// what routes a request through pipeToFamily — the one choke point where the funding gate
|
|
// runs. A family the dispatch cannot resolve is not merely unrouted: every call site guards
|
|
// on `if fam := familyForProviderType(...); fam != nil`, so a nil sends the request down
|
|
// the generic relay instead, WITH the provider credential and WITHOUT the gate.
|
|
//
|
|
// OpenRouter shipped in exactly that state. It was present in modelFamilies, so all 338 of
|
|
// its prepaid models were discovered, listed and routable, while a hand-written switch that
|
|
// named only Zen and Enso quietly excluded it from the gated path.
|
|
//
|
|
// This asserts the property over modelFamilies rather than over a fixed list, so a family
|
|
// added later is covered the day it is added.
|
|
func TestEveryFamilyResolvesToItsGatedPath(t *testing.T) {
|
|
if len(modelFamilies) == 0 {
|
|
t.Fatal("no families registered")
|
|
}
|
|
for _, f := range modelFamilies {
|
|
if f.provider == "" {
|
|
t.Errorf("family %q declares no provider Type, so no request can ever resolve to it", f.name)
|
|
continue
|
|
}
|
|
got := familyForProviderType(f.provider)
|
|
if got == nil {
|
|
t.Errorf("family %q (provider %q) does not resolve — its requests bypass pipeToFamily and the funding gate",
|
|
f.name, f.provider)
|
|
continue
|
|
}
|
|
if got != f {
|
|
t.Errorf("provider %q resolved to family %q, want %q", f.provider, got.name, f.name)
|
|
}
|
|
}
|
|
// A provider Type no family claims must resolve to nil, not to some default family.
|
|
if got := familyForProviderType("NotAFamily"); got != nil {
|
|
t.Errorf("unknown provider Type resolved to %q, want nil", got.name)
|
|
}
|
|
}
|
|
|
|
// The prepaid families must carry the paid floor on every discovered model. OpenRouter is
|
|
// resale on a real-cash balance, so a free or trial caller must never reach one.
|
|
func TestOpenRouterModelsCarryThePaidFloor(t *testing.T) {
|
|
saved := openrouterFam.byID
|
|
t.Cleanup(func() { openrouterFam.byID = saved })
|
|
openrouterFam.byID = map[string]zenModel{
|
|
"anthropic/claude-opus-4.8": {ID: "anthropic/claude-opus-4.8", MinTier: "paid", Funding: "prepaid"},
|
|
}
|
|
m, ok := openrouterFam.lookup("anthropic/claude-opus-4.8")
|
|
if !ok {
|
|
t.Fatal("discovered model not found")
|
|
}
|
|
if m.Funding != "prepaid" {
|
|
t.Errorf("funding = %q, want prepaid — OpenRouter spends real cash", m.Funding)
|
|
}
|
|
if m.minTier() != "paid" {
|
|
t.Errorf("min_tier = %q, want paid", m.minTier())
|
|
}
|
|
}
|