Reported: Zhenbao TONG moved a provider on the Providers page, and the
tray panel's Allowances tab kept the old order.
Changed: provider.InProviderOrder(qs) (internal/provider/quotas.go) sorts
a copy of the quota cards, stably, by the provider's place in All().
Providers it doesn't know go last. Used by /api/quotas's two routes
(internal/gui/usage.go) and the TUI (internal/tui/pages.go). The app.js
comment says the order now comes from the server.
Test: TestQuotaCardsInProviderOrder (quotas_order_test.go). Broken by
hand:
- InProviderOrder as the identity: "as added: [a/a1 remote:x/r c/c1
b/pro a/a2 c/$1]".
- sorting without the clone: "Quotas' list was sorted in place".
Not covered: the /api/quotas wiring has no test beyond the function's
unit test.
Run, go1.26.8 darwin/arm64, sandbox HOME, private GOCACHE:
At this stack on origin/main df6bd3efe (head 48522d851):
gofmt -l: nothing
go vet ./... (darwin), GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./...: ok
set -o pipefail; go test -timeout 45m ./...: ok, EXIT=0
(68 ok, 19 with no test files; agent 528s, gateway 628s,
library 482s)
GUI, playwright 1.62.0, chromium and webkit, concurrency 3: the
171 files near this change (routing*, panel-routing*,
window-mask, privacy*, usage*, quota*, providers*): 2217 tests,
2183 pass, 34 fail. Every red is also red alone on origin/main:
quota-count-wrap and quota-name-translated (#2228),
usage-agents-hide (#2276), usage-checkin (#3091), usage-fold
(#2163), usage-ledger (#3104, red since df6bd3efe, green at its
parent). window-mask: 20 of 20.
At this stack on origin/main c922225f1 (head 91baa7adb), before
df6bd3efe's routing trace change:
set -o pipefail; go test -timeout 45m ./...: ok, EXIT=0
(66 ok, 20 with no test files)
the whole GUI suite (823 files, both engines, concurrency 3):
11589 tests, 11554 pass, 35 fail. The 9 files red were run again
alone at --test-concurrency=1 on the head and on origin/main
a8ecf4020. The same 7 files were red on both: the five issues
above plus s3-sync (#2448) and library-row-remove (#3099).
nav-sub-unroll (#1950) and plugin-updates (#3103) were red only
under the full run. codex-predictions (#2624) was 20 of 20.
48 lines
1.8 KiB
Go
48 lines
1.8 KiB
Go
package provider
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
// Zhenbao TONG on Discord: the providers moved on the window's Providers
|
|
// page, and the tray panel's Allowances tab kept its own order. The cards
|
|
// come in the providers' order now, each provider's as they came, and a
|
|
// card of no provider here (a remote magpie's) after them.
|
|
func TestQuotaCardsInProviderOrder(t *testing.T) {
|
|
t.Setenv("HOME", t.TempDir())
|
|
t.Setenv("USERPROFILE", t.TempDir())
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
|
for _, id := range []string{"a", "b", "c"} {
|
|
if err := Save(Provider{ID: id, Name: id, Key: "sk-" + id, Chat: "https://" + id + ".example.com/v1", Models: []string{"m"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
// as Quotas has them: subscriptions, then plans, then balances
|
|
qs := []SubscriptionQuota{
|
|
{Provider: "a", User: "a1"}, {Provider: "remote:x", User: "r"}, {Provider: "c", User: "c1"},
|
|
{Provider: "b", Plan: "pro"}, {Provider: "a", User: "a2"}, {Provider: "c", Balance: "$1"},
|
|
}
|
|
cards := func(qs []SubscriptionQuota) []string {
|
|
var out []string
|
|
for _, q := range qs {
|
|
out = append(out, q.Provider+"/"+q.User+q.Plan+q.Balance)
|
|
}
|
|
return out
|
|
}
|
|
if got, want := cards(InProviderOrder(qs)), []string{"a/a1", "a/a2", "b/pro", "c/c1", "c/$1", "remote:x/r"}; !slices.Equal(got, want) {
|
|
t.Fatalf("as added: %v, want %v", got, want)
|
|
}
|
|
if err := SetOrder([]string{"c", "a", "b"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got, want := cards(InProviderOrder(qs)), []string{"c/c1", "c/$1", "a/a1", "a/a2", "b/pro", "remote:x/r"}; !slices.Equal(got, want) {
|
|
t.Fatalf("after SetOrder(c, a, b): %v, want %v", got, want)
|
|
}
|
|
// the cache's own array is left as it was
|
|
if qs[0].User != "a1" || qs[1].User != "r" {
|
|
t.Fatalf("Quotas' list was sorted in place: %v", cards(qs))
|
|
}
|
|
}
|