Files
ai/controllers/provider_seed_test.go
zeekayandHanzo Dev f47f43085c fix(ai): stop seeding a zen provider row that hijacks the zen family
The seed created admin/zen pointing at do-ai's base
https://inference.do-ai.run/v1. familyProvider reads an admin row of a family's
name as an operator OVERRIDE that wins over deployment config, and the family
paths append their own /v1 (discovery does base+"/v1/models"), so every zen
catalog refresh hit .../v1/v1/models and 404'd. No zen model was listed or
served, and the only symptom was one warning a minute. Sibling enso — the same
serving binary, the same family shape — was never seeded and never broke. That
A/B is the whole diagnosis.

The openrouter seed carries this exact lesson in its own comment and was fixed
by dropping the /v1. zen needs the row GONE rather than repointed: no route
targets it (see modelCountByProvider), so it holds nothing, and merely dropping
the /v1 would aim the family at DigitalOcean's catalog instead of the zen
service that actually serves zen SKUs.

Removing the seed entry alone is not enough. The apply loop self-heals
ProviderUrl on every boot and re-creates a deleted row, so the existing row
would survive every restart and keep hijacking the family — which is also why
this could never have been fixed in the database. pruneStaleZenSeed deletes it,
scoped to the exact stale shape so a row an operator writes on purpose is
untouched.

Guard: seededLLMProviders is hoisted to package scope and asserted from
controllers, whose suite actually runs — object's TestMain exits before m.Run
without a seeded database, so a guard living there would be inert. A seeded
FAMILY row may never carry a trailing /v1.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-04 17:02:15 -07:00

66 lines
2.6 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 (
"strings"
"testing"
"github.com/hanzoai/ai/object"
)
// TestSeededFamilyProvidersDoNotCarryV1 guards the defect that silently took the
// entire zen family off /v1/models.
//
// A model FAMILY appends its own /v1: discovery does base+"/v1/models" and
// pipeToFamily does ProviderUrl+"/v1/"+apiPath. So a seeded row whose
// ProviderUrl ALREADY carries /v1 sends every call to .../v1/v1/... and 404s.
// The direct-relay providers are the exact opposite — nothing appends for them,
// so they MUST carry /v1. That inversion is why this is easy to get wrong twice,
// and why it is asserted here rather than remembered: openrouter hit it and was
// caught, zen hit it and shipped broken for weeks.
//
// The failure is invisible at runtime. The family just serves nothing, and the
// only symptom is a once-a-minute "catalog refresh failed: status 404" warning.
func TestSeededFamilyProvidersDoNotCarryV1(t *testing.T) {
seeded := object.SeededModelProviders()
for _, name := range object.FamilyProviderNames() {
url, isSeeded := seeded[name]
if !isSeeded {
continue
}
if strings.HasSuffix(strings.TrimRight(url, "/"), "/v1") {
t.Errorf("seeded family provider %q has ProviderUrl %q ending in /v1; "+
"the family paths append /v1 themselves, so every call would 404",
name, url)
}
}
}
// TestZenIsNotSeeded pins the decision that zen has NO seed row at all.
//
// zen's address is deployment config (ZEN_URL → the in-cluster zen service),
// exactly like its sibling enso — which was never seeded and never broke. A row
// is read by familyProvider as an operator OVERRIDE and wins over that config,
// so seeding one hijacks the family. Dropping the /v1 would NOT be enough: it
// would merely aim zen at DigitalOcean's catalog instead of the service that
// actually serves zen SKUs.
func TestZenIsNotSeeded(t *testing.T) {
if url, ok := object.SeededModelProviders()["zen"]; ok {
t.Fatalf("zen must not be seeded: its address is ZEN_URL and a seeded row "+
"overrides it (got ProviderUrl %q)", url)
}
}