onkashiko on X: with Currency set to By provider, the menu bar panel still showed every cost in one currency; providers and models were not each in their own. drawLedColumns and drawLedRank (shared by the tray panel and the window's Requests tab) formatted every value with no provider, so fmtCost fell back to the Totals in currency. - usageapi.Ledger echoes the provider a page is filtered to (`provider`, omitempty). - app.js: ledProv(l, split, id) names the provider of a value: the ledger's filter, the row's provider (provider split), the provider part of a modelAt id, or for a model split the provider(s) that served it when they all share a currency. ledFormat/ledFormatLong take it, so the rank's values and sub-lines, the tooltip's rows and the axis (when one provider is picked) are in that provider's currency. Sums (the panel total, the tooltip total, a model served in two currencies) stay in the Totals in currency. - page.js: the Requests head and the cost head use the filter's provider; the heatmap tip too. Other fmtCost calls are sums or sessions with no provider and are unchanged. - core script budget +491 (1,269,040 -> 1,269,531): drawLedColumns and drawLedRank are drawn by the panel, so there is no lazy page to move this to; packed to the shortest form. - docs/subsystems/gui-shell.md says how By provider reaches the panel. Run: - At 065fb6a8b (rebased on7d5475769), mote: gofmt clean; TestCoreScriptBudget and TestLedgerSaysItsOneProvider ok; panel-currency-provider.test.cjs 20/20 (chromium + webkit x en, zh, zh-TW, ja, de; panel 440/320px, window 1100/420px, no sideways scroll, no page errors). - At ff3ab573d (same change on90932ed1f), mica, under suite.lock: go vet darwin, linux nogui, windows ok; builds for all three ok; go test -tags nogui -count=1 -timeout 45m ./... : 99 packages ok, exit 0. mote: go test usageapi, gui, usage ok. - GUI suite, the 155 files the change can reach, mote: 2581 tests, 105 failures in 13 files; the same 13 files give 104 at90932ed1f. The one extra is tray-cell-click webkit en, flaky on both trees run alone (head green twice, base red once). Filed: grip-inset, key-balance-card, panel-fold, tray-cell-click, usage-* (#6293, #6294, #6295, #6499, #6003, #5872, #6414, #5869, #5796, #5215, #4790); panel-shortcut's 20 reds newly filed as #6606. Broken by hand: - panel-currency-provider on the old assets (MAGPIE_ASSETS): 20/20 red, with the reporter's symptom (DeepSeek $1.00, SiliconFlow $0.500 under By provider). - TestLedgerSaysItsOneProvider red with `out.Provider = f.Provider` removed. Not tried: the real app's tray panel with real yuan and dollar providers.
50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
package usageapi
|
|
|
|
import (
|
|
"encoding/json"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/usage"
|
|
)
|
|
|
|
// TestLedgerSaysItsOneProvider: a page filtered to one provider says which,
|
|
// so with the currency "by provider" its total and chart are shown in what
|
|
// that provider sells in (onkashiko on X); a page of every provider says
|
|
// none, and its sums go in the "Totals in" currency.
|
|
func TestLedgerSaysItsOneProvider(t *testing.T) {
|
|
h := t.TempDir()
|
|
t.Setenv("HOME", h)
|
|
t.Setenv("USERPROFILE", h)
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
|
|
now := time.Now()
|
|
usage.Append(usage.Record{Time: now.Add(-2 * time.Minute), Agent: "codex", Provider: "deepseek", Model: "deepseek/deepseek-v4", Status: 200, Input: 10, Output: 2})
|
|
usage.Append(usage.Record{Time: now.Add(-time.Minute), Agent: "codex", Provider: "openai", Model: "openai/gpt-5", Status: 200, Input: 10, Output: 2})
|
|
|
|
one := LedgerPage(usage.All, usage.Filter{Provider: "deepseek"}, 0, 100)
|
|
if one.Provider != "deepseek" || one.Calls != 1 {
|
|
t.Fatalf("filtered page: provider %q calls %d, want deepseek, 1", one.Provider, one.Calls)
|
|
}
|
|
if top := topLevel(t, one); top["provider"] != "deepseek" {
|
|
t.Fatalf("the page reads provider %v, want deepseek", top["provider"])
|
|
}
|
|
all := LedgerPage(usage.All, usage.Filter{}, 0, 100)
|
|
if _, ok := topLevel(t, all)["provider"]; ok || all.Provider != "" {
|
|
t.Fatalf("the whole page names a provider %q", all.Provider)
|
|
}
|
|
}
|
|
|
|
func topLevel(t *testing.T, l Ledger) map[string]any {
|
|
t.Helper()
|
|
b, err := json.Marshal(l)
|
|
var m map[string]any
|
|
if err == nil {
|
|
err = json.Unmarshal(b, &m)
|
|
}
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return m
|
|
}
|