The Requests page's Provider filter listed "claude" between named providers. The usage log keeps the id of every provider a call went to, and usageapi named those only from provider.All(). The Claude Code subscription is in that list only while its account is discovered, so after a sign-out, with account discovery off, or for a preset provider removed since, the bare id showed. This happened in the filter, each row's Provider column, the split-by-provider and model-at-provider legends, the Account filter's provider notes, and the summary's model and account subtitles (stateOf had its own copy of the same lookup). - provider.KnownFace(id): the name and icon magpie knows an id by while it isn't set up. It covers the built-in subscriptions' card faces (accountCard: Claude Code, Codex, Copilot, Gemini, Antigravity, moved ones) and then the presets. A custom provider removed since stays its id, since nothing else knows its name. - usageapi.providerFaces: one lookup for LedgerPage and stateOf, in order: the provider set up, "Local session" for session-unknown, then KnownFace, then the id. Run: - TestProvidersNotSetUpAreNamed (new, internal/usageapi). Fails on the old code with 13 errors across the filter, rows, both splits, the Account filter and the summary; passes with the fix. - gofmt -l: clean. go vet for usageapi, provider, gateway, gui on darwin, and usageapi, provider on GOOS=linux and windows: clean. - go test ./internal/usageapi ./internal/usage: ok. - go test ./internal/provider ./internal/gateway ran at load average ~300 with other sessions' suites. Three timing tests went red, and each passes 3/3 alone (-count=3 -run): TestCopilotSecretToolUsername (#1627, commented), TestOTelFastRequestTranscriptDiscovery (#1811), and TestTranslatedStreamKeepsClientAlive (filed as #2169). TestUsageOverGateway and the gateway's TestUsage* pass. - GUI: usage-ledger.test.cjs and usage-ledger-chart.test.cjs in chromium and webkit, 52/52 (playwright 1.62.0). app.js is unchanged, since the page already shows the name the API sends. Not tried: the real GUI with a signed-out Claude account.
79 lines
2.6 KiB
Go
79 lines
2.6 KiB
Go
package usageapi
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
"github.com/yetone/magpie/internal/testenv"
|
|
"github.com/yetone/magpie/internal/usage"
|
|
)
|
|
|
|
func TestMain(m *testing.M) { testenv.Main(m) }
|
|
|
|
// A provider the usage log names but that isn't set up now is still named
|
|
// as magpie knows it (@ByronVon1 on X): the Claude Code subscription,
|
|
// signed out of since, showed as "claude" in the Requests page's Provider
|
|
// filter, between providers named by their names. A preset's removed
|
|
// since is named by the preset; a custom one magpie can't know stays its
|
|
// id. Every place the page names a provider from the log says the same:
|
|
// the filter, each row, the split-by legends, and the summary's models
|
|
// and accounts.
|
|
func TestProvidersNotSetUpAreNamed(t *testing.T) {
|
|
for _, p := range provider.All() {
|
|
if p.ID == "claude" || p.ID == "deepseek" {
|
|
t.Fatalf("the test home has %s set up", p.ID)
|
|
}
|
|
}
|
|
now := time.Now()
|
|
for i, pid := range []string{"claude", "deepseek", "gone-custom"} {
|
|
usage.Append(usage.Record{Time: now.Add(-time.Duration(i+1) * time.Minute), Agent: "claude", Provider: pid, Model: "m-" + pid, Input: 10, Output: 2, ProviderAccount: "me@example.com"})
|
|
}
|
|
want := map[string]string{"claude": "Claude Code", "deepseek": "DeepSeek", "gone-custom": "gone-custom"}
|
|
|
|
l := LedgerPage(usage.All, usage.Filter{}, 0, 100)
|
|
if len(l.Providers) != len(want) {
|
|
t.Fatalf("providers: %+v", l.Providers)
|
|
}
|
|
for _, p := range l.Providers {
|
|
if p.Name != want[p.ID] {
|
|
t.Errorf("the Provider filter names %s %q, want %q", p.ID, p.Name, want[p.ID])
|
|
}
|
|
}
|
|
for _, r := range l.Rows {
|
|
if r.ProviderName != want[r.Provider] {
|
|
t.Errorf("a row names %s %q, want %q", r.Provider, r.ProviderName, want[r.Provider])
|
|
}
|
|
}
|
|
for _, s := range l.By["provider"] {
|
|
if s.Name != want[s.ID] {
|
|
t.Errorf("the split by provider names %s %q, want %q", s.ID, s.Name, want[s.ID])
|
|
}
|
|
}
|
|
for _, s := range l.By["modelAt"] {
|
|
if s.Name == "m-claude · claude" {
|
|
t.Errorf("the split by model at provider names %q", s.Name)
|
|
}
|
|
}
|
|
if len(l.Accounts) != 1 || len(l.Accounts[0].Providers) != 3 {
|
|
t.Errorf("accounts: %+v", l.Accounts)
|
|
}
|
|
for _, a := range l.Accounts {
|
|
for _, n := range a.Providers {
|
|
if n == "claude" || n == "deepseek" {
|
|
t.Errorf("the Account filter names a provider %q", n)
|
|
}
|
|
}
|
|
}
|
|
|
|
s := State(usage.All)
|
|
for _, g := range append(s.Models, s.Accounts...) {
|
|
if g.Sub == "claude" || g.Sub == "deepseek" {
|
|
t.Errorf("the summary names %q's provider %q", g.Name, g.Sub)
|
|
}
|
|
}
|
|
if len(s.Models) != 3 {
|
|
t.Errorf("models: %+v", s.Models)
|
|
}
|
|
}
|