motui9535 (Discord #feedback, v0.1.2909, screenshot): of three Team accounts the preferred one showed 7 days 17% and 7 days · Fable 30% and no 5-hour window; the two others showed all three. Anthropic leaves a window out (null) while it hasn't started (claudeWindowsExpected says as much for the warm-up), so Claude Code's /usage has no "Current session" line for an account nobody used in the last five hours, and the card took the missing line as no window at all. The aggregate's 5 hours (100%) then averaged only the two other accounts. A whole /usage reading (claudeWindows, the one place the active and the saved accounts' readings are kept) now gets the 5-hour window it leaves out as not started: 0% used, no reset, first, as Claude Code orders them (claudeKindOrder, taken out of NoteClaudeLimits). A header heard later replaces it as before. Only the 5-hour window: a reading that tells any window tells the week. parseClaudeUsage is unchanged (TestClaudeUsageWeeklyOnly still holds that the parser makes none up); TestClaudeSwitchWeeklyOnly's card now has the unstarted 5-hour window. Run (mote, at this tree): - go test ./internal/provider: ok (132.9s) - go test -run 'Claude|Usage|Quota' ./internal/gateway ./internal/cli ./internal/gui: ok - go vet ./internal/provider on darwin, linux (-tags nogui), windows; gofmt -l clean Broken by hand: without the claudeWithUnstarted call, TestClaudeUnstartedSessionShownUnused is red: windows ["7 days" "7 days · Fable"], motui's shape. Not tried: a real Claude account's /usage with an unstarted session (the null comes from claudeWindowsExpected's note and the screenshot); no GUI test, the cards draw every window /api/usage/quotas gives and the change is in what it gives; Windows/Linux runs.
62 lines
2.1 KiB
Go
62 lines
2.1 KiB
Go
package provider
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// motui9535 (Discord, v0.1.2909, a screenshot): of three Team accounts the
|
|
// preferred one showed its week and its Fable week and no 5-hour window,
|
|
// the two others all three. Anthropic leaves a window out (null) while it
|
|
// hasn't started, so /usage has no "Current session" line for an account
|
|
// not used in the last five hours; every Claude account has one all the
|
|
// same (claudeWindowsExpected). The card shows it unused, first, as the
|
|
// others order it, not missing; and a header heard later still replaces it.
|
|
func TestClaudeUnstartedSessionShownUnused(t *testing.T) {
|
|
reset := time.Now().UTC().Add(72*time.Hour).Format("Jan 2 at 3pm") + " (UTC)"
|
|
text := "Current week (all models): 17% used · resets " + reset + "\nCurrent week (Fable): 30% used · resets " + reset + "\n"
|
|
_, card := claudeUsageCards(t, text, nil)
|
|
q := card()
|
|
if q.Error != "" {
|
|
t.Fatalf("reading: %+v", q)
|
|
}
|
|
var names []string
|
|
for _, w := range q.Windows {
|
|
names = append(names, w.Name)
|
|
}
|
|
if strings.Join(names, ", ") != "5 hours, 7 days, 7 days · Fable" {
|
|
t.Fatalf("windows %q, want the 5-hour one first and the two weeks: %+v", names, q.Windows)
|
|
}
|
|
five := q.Windows[0]
|
|
if five.Used != 0 || five.ResetsAt != nil || five.Span != 5*time.Hour || five.Model != "" {
|
|
t.Fatalf("the 5-hour window not started: %+v", five)
|
|
}
|
|
if q.Windows[1].Used != 17 || q.Windows[2].Used != 30 {
|
|
t.Fatalf("the weeks as read: %+v", q.Windows)
|
|
}
|
|
|
|
// the account used: Claude Code's header names the 5-hour window, and
|
|
// it stands in place of the unused one
|
|
NoteClaudeLimits("a@example.com", []ClaudeLimit{{Kind: "five_hour", Used: .12, ResetsAt: time.Now().Add(4 * time.Hour).Unix()}})
|
|
lastQuotas.Lock()
|
|
lastQuotas.m, lastQuotas.loaded = nil, false
|
|
lastQuotas.Unlock()
|
|
loginUsageCache.Lock()
|
|
loginUsageCache.m = nil
|
|
loginUsageCache.Unlock()
|
|
q = card()
|
|
n := 0
|
|
for _, w := range q.Windows {
|
|
if w.Name == "5 hours" {
|
|
n++
|
|
if w.Used != 12 || w.ResetsAt == nil {
|
|
t.Fatalf("the heard 5-hour window: %+v", w)
|
|
}
|
|
}
|
|
}
|
|
if n != 1 || q.Windows[0].Name != "5 hours" {
|
|
t.Fatalf("one 5-hour window, first: %+v", q.Windows)
|
|
}
|
|
}
|