Commit Graph
1 Commits
Author SHA1 Message Date
yetone 44732325e7 gateway: test that OpenCode Go's keys take over at its usage limit (MelWoutersgghi on X)
MelWoutersgghi asked for an OpenCode Go provider that holds several
keys and switches between them. That already works: OpenCode Go is a
built-in key provider (presets.go), and every key provider keeps
several keys (Provider.Keys, keys.go). The provider's editor lists
them under Accounts with "Add another key" (renderKeyAccounts), a key
is turned on or off by its dot, and with more than one on, Routing
says how requests spread. Each key's 5-hour, weekly and monthly Go
windows are read on its own (planquota.go, key_allowance.go).

Nothing guarded it with OpenCode Go's own refusal, so this adds
TestOpenCodeGoKeysTakeOverAtUsageLimit: the first key answers the 429
GoUsageLimitError body OpenCode's client records (its composer.spec.ts
fixture), the second key serves the request, a key that is off is
never tried, and the next request goes straight to the second key
while the first rests.

Run: go test -run 'TestOpenCodeGoKeysTakeOverAtUsageLimit|
TestSeveralKeysOnTakeOverFromEachOther' ./internal/gateway, PASS, and
go vet ./internal/gateway, clean, both on Linux (wsl-run; mote refused
SSH six times in a row). gofmt -l clean.
Broken by hand: KeysOn returning only the first key for opencode-go
makes the test red (429, tried k-spent only); restored.
Not tried: a real account with two OpenCode Go keys; the full suite
(test-only change).
2026-11-10 18:00:14 +08:00