Files
magpie/internal/provider/five_hours_alone_test.go
T
yetone a802d98bfc routing: a group in a group is routed by its own routing whatever the outer group's, and an account with five hours and no week is ranked by its five hours (#576: 只有五小时额度的账号在智能/重置前用完下是否合理;嵌套路由组时上层路由是否会干预下层) — a group routed other than In order (Smart, In turn, Least used, Weekly pace, Manual) put every account and key of every group in it into one pool and weighed them together, so A (Smart) holding A-1 and A-2 (each In order) ranked all five of their accounts and keys by Smart and A-1's and A-2's own In order did nothing; only an outer In order let each inner group route itself. planLevel now plans each group in the group by its own routing, whatever the outer's, and weighs it as one beside the outer group's own models' keys, by the first of its own order that isn't resting; where that lands, the inner group is tried whole in its own order, the trace in the same order. As for the five hours: Smart already ranked such an account (Claude Enterprise) by its five hours, the biggest window it has, so ahead of every week renewing later, but a five hours not started (no reset told) counted as a reset not known and went after every week; Allowance.Renewal now has a window not started that says its span renew that long from now, which Smart sorts by (the trace's renews unchanged). Weekly pace took an account with no week as a fresh week with the share used (100/168 per hour), so a week with 80% left and five days to go went ahead of an Enterprise account whose five hours were being lost; it now goes by what its five hours have left per hour until they renew, the whole span when not started, except where the reading may leave a week out — a Claude account only heard of from Claude Code's rate_limit_event, never read whole by /usage (QuotaWindow.partial, claudeUsageEntry.whole) — which keeps the fresh week. The group editor's Smart and Weekly pace hints and the trace's say how an account with five hours and no week is ranked, a hint under Routing says a group among the models keeps its own routing, and the docs (en, zh) say both. TestGroupInGroupKeepsItsOwnRouting (Outer rotating over two In order groups: b c d a without the change, c d a b with it), TestSmartFiveHoursAlone (a five hours not started went after a week in two days), TestFiveHoursAlone, TestClaudeHeardOnlyIsPartial; TestWeeklyPace and TestAllowancePace now pin the five hours alone. settings-groups, group-member-fast, group-found-off, routing-idle-frame pass in WebKit. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass (TestFXInState, TestProvidersAnswerWhileListsComeIn, TestUserPath, TestClaudeSignedOut flaked; the last passes 3/3 alone).
2026-10-02 23:05:15 +08:00

59 lines
2.1 KiB
Go

package provider
import (
"testing"
"time"
)
// An account with the five hours alone (Claude Enterprise) has nothing
// longer to keep for: Pace goes by what its five hours lose at their
// reset, the whole span when not started, and Renewal has a five hours
// not started renewing within five hours — unless the reading may leave
// a week out (a Claude account only heard of as Claude Code answered),
// which goes as a fresh week with the share used, as before (#576).
func TestFiveHoursAlone(t *testing.T) {
now := time.Now()
five := 5 * time.Hour
near := func(a, b float64) bool { return a-b < 1e-9 && b-a < 1e-9 }
a := Allowance{{Used: 20, Resets: now.Add(2 * time.Hour), Span: five}}
if p, due := a.Pace("m", now); !near(p, 40) || !due.Equal(now.Add(2*time.Hour)) {
t.Fatalf("started: %v %v", p, due)
}
idle := Allowance{{Used: 0, Span: five}}
if p, _ := idle.Pace("m", now); !near(p, 20) {
t.Fatalf("not started: %v", p)
}
ws := []QuotaWindow{{Name: "5 hours", Used: 20, ResetsAt: ptr(now.Add(2 * time.Hour)), Span: five, partial: true}}
if p, _ := allowanceOf(ws, now).Pace("m", now); !near(p, 80/(7*24.0)) {
t.Fatalf("partial reading, a fresh week: %v", p)
}
// beside a week, the week decides as ever
both := Allowance{{Used: 0, Span: five}, {Used: 40, Resets: now.Add(60 * time.Hour), Span: 7 * 24 * time.Hour}}
if p, _ := both.Pace("m", now); !near(p, 1) {
t.Fatalf("with a week: %v", p)
}
if r := idle.Renewal("m", now); len(r) != 1 || !r[0].Equal(now.Add(five)) {
t.Fatalf("renewal not started: %v", r)
}
if _, r := idle.For("m", now); len(r) != 1 || !r[0].IsZero() {
t.Fatalf("For still says not known: %v", r)
}
if r := (Allowance{{Used: 3}}).Renewal("m", now); len(r) != 1 || !r[0].IsZero() {
t.Fatalf("no span, not known: %v", r)
}
}
// claudeWindows marks partial what only Claude Code's answers told.
func TestClaudeHeardOnlyIsPartial(t *testing.T) {
e := claudeUsageEntry{ws: []QuotaWindow{{Name: "5 hours", Used: 10, Span: 5 * time.Hour}}}
if ws := e.windows(time.Now()); !ws[0].partial {
t.Fatal("heard only: partial")
}
e.whole = true
if ws := e.windows(time.Now()); ws[0].partial {
t.Fatal("read by /usage: whole")
}
}