On a provider with several accounts or keys whose models differ (a
magpie-newapi pool, a relay whose keys sit in different groups), "测试模型",
the right-click test and the provider's Test asked the first account or
key. A model that only another account serves failed (grok-4.7: 503 "no
available channel") while real requests were answered, because the
gateway's perKeyEvery passes over accounts and keys the user set not to
serve the model (AccountModels, #474) and accounts whose own list lacks
it. The test path had none of that.
Cause: the choice lived in the gateway only (perKeyEvery and accountsOn
in gateway/fallback.go), so the test had nothing to share. keySeeing
checked the key's list but not AccountModels.
Change:
- internal/provider/route_accounts.go: AccountsOn, AccountsFor and
KeysFor are the routing choice. The code moved there from perKeyEvery
and accountsOn, and the gateway's caps are passed in as a held func.
- gateway/fallback.go: perKeyEvery and accountsOn call it. They behave
as before.
- test.go:
- testOne (the model test and the right-click test) runs as
AccountsFor's first account. A model barred on every account is
not asked; it says so.
- The provider's Test picks key and model together (testWith), then
the account that serves the model (routedTo).
- The log row names the account asked (loggedAs).
- keySeeing and testModel take keys from KeysFor and AccountServes.
- detect.go: detectOne, a sibling, asks each model with keySeeing's key.
Before, it asked the endpoint's first key.
- Not changed: AskSystemOne's decision model still asks the provider's
own account.
Tests (internal/provider/test_account_route_test.go), on a two-account
fake plugin and a relay that answers one key:model:
- TestModelTestAsksTheAccountThatServesIt
- TestModelTestPassesAnAccountWhoseListLacksIt
- TestProviderTestAsksAnAccountThatServesItsModel
- TestModelTestUsesTheKeyServingIt
- TestModelTestBarredModelIsNotAsked
- TestDetectModelsUsesTheKeyServingIt
All six are red on origin/main e932cd258 (test file alone): "Bearer a@fake
/v1/responses" 503, sk-a asked m-b, and so on. All six are green after.
Run on mote:
- go test -count=1 -timeout 45m ./internal/provider ./internal/gateway: ok
on e932cd258. After the rebase onto d9f63dfee: go vet, the whole of
internal/provider, and internal/gateway -run
"Fallback|PerKey|Account|Key|Cap|Spend", all ok.
- go vet, GOOS=linux -tags nogui go vet, GOOS=windows go vet for both
packages; gofmt -l clean.
- node --test with the GUI files that test models (model-test-as,
model-test-one, model-test-stop, model-test-why,
test-models-key-hint): 60/60, Chromium and WebKit. They fake /api, so
they don't reach this change.
Broken by hand:
- `|| true` on Lists in AccountsFor: TestModelTestPassesAnAccountWhoseListLacksIt
and the gateway's TestCodexProviderListsEveryAccountsModels go red.
- The AccountServes case in KeysFor turned off:
TestModelTestUsesTheKeyServingIt goes red. The gateway goes through
the shared code.
Not tried:
- A real newapi pool or a real multi-account sign-in.
- Usage and spend caps are not applied to a test (held is nil).
- The Windows and Linux runs.
- The full suite was started on mote after the push, under suite.lock.
Reported-by: scutken
Co-authored-by: xiejiayu <scut_ken@qq.com>
Co-authored-by: Jackzigen <zigenhan@gmail.com>