Smart ranked a Volcengine Agent Plan (5 hours 2,000, week 7,000, month
20,000) by its month, the biggest window, so it always stood behind
accounts renewing weekly, and its month could reach a point where it
could no longer be used up before it renewed.
The rule keeps #1778's reasoning: a month holding less than its weeks add
up to is the real cap while the weeks can still carry it. Once what the
biggest window has left is more than the next window (a day or longer,
same unit, counts known) can let through between its own reset and the
biggest one's (Of x time between / Span), what the week leaves at its
reset is lost, and the week ranks the account.
- provider: Allowance.Unreached counts the biggest windows to pass over.
Renewal and Seat.Soon are unchanged for other strategies and plugins.
- routes: Seat.Unreached; Smart compares Soon past it.
- gateway: weighRouted fills it; the trace's Weighed carries `unreached`.
- GUI Routing: renewsBy skips those windows, and a new story line says the
shorter window decides. The Smart header and the group hint say so in
en, zh, zh-TW, ja and de.
- docs: reference.md (How magpie picks an account) and
subsystems/gateway-routing.md.
With the issue's numbers as reported (month 696 h away, 18,372 left),
four weeks carry 28,017, so the order is unchanged. Two weeks before the
month renews, 14,017 < 18,372, and the plan goes first, ahead of the
point where a week's leftover is lost.
Run on mote at this tree (base 2dac9b84e; origin/main bb33142ea touches
none of these files):
- go test -tags nogui ./internal/provider ./internal/routes: ok
- go test of TestMonthOutOfReachRanksByWeek,
TestSmartSpendsAWeekTheMonthCantWait, TestSmartPassesAnUnreachedWindow
and the Smart/Renewal/Weighed tests in provider, routes, gateway: ok
- GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet ./...: ok
- gofmt -l internal/: clean
- node --test routing-key-windows.test.cjs: 52/52 in Chromium and WebKit,
en/zh/ja/de, the new #5639 scene included
Broken by hand:
- Unreached returning 0: TestMonthOutOfReachRanksByWeek ("two weeks to
go", "the last week") and TestSmartSpendsAWeekTheMonthCantWait went red.
- Smart comparing a.Soon, b.Soon whole: TestSmartPassesAnUnreachedWindow
and TestSmartSpendsAWeekTheMonthCantWait went red.
- client.js without the slice and the story line: the #5639 GUI case went
red (Chromium en).
Still running when pushed (the owner's rule not to hold a verified commit
behind the suite): the full internal/gateway package; all routing-*,
panel-routing*, gui-zh-tw/ja/de and i18n GUI files in both engines; and
the full go test ./... -timeout 45m. Any red they show gets its own issue.
Not tried: a real Volcengine Agent Plan account. Ark replies that send
only Percent carry no counts, so the rule can't apply to them. Not
changed: Use before expiry (Pace) still ranks this plan by its month;
filed as #5641.
Reported-by: louisgreen0726
Refs #5639
87 lines
3.5 KiB
Go
87 lines
3.5 KiB
Go
package provider
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// A Volcengine Agent Plan's month (20,000) is ranked by its week (7,000)
|
|
// once the weeks still to come before the month renews can't carry what
|
|
// the month has left: what the week leaves at its reset is lost then
|
|
// (#5639, louisgreen0726's reading on v0.1.3260: 1,628 used of the week
|
|
// and of the month, the week renewing in 23.6 hours, the month in 696).
|
|
// While they can, the month is the real cap (#1778) and ranks it.
|
|
func TestMonthOutOfReachRanksByWeek(t *testing.T) {
|
|
now := time.Now().Truncate(time.Second)
|
|
day, week := 24*time.Hour, 7*24*time.Hour
|
|
weekRenews := now.Add(23*time.Hour + 36*time.Minute)
|
|
// the Agent Plan's GetAFPUsage, its resets in milliseconds
|
|
plan := func(weekUsed, monthUsed float64, month time.Time) Allowance {
|
|
t.Helper()
|
|
ws, _ := volcReadAFP(json.RawMessage(fmt.Sprintf(`{"Tier":"Pro",
|
|
"AFPFiveHour":{"Quota":2000,"Used":0},
|
|
"AFPWeekly":{"Quota":7000,"Used":%v,"ResetTimestamp":%d},
|
|
"AFPMonthly":{"Quota":20000,"Used":%v,"ResetTimestamp":%d}}`,
|
|
weekUsed, weekRenews.UnixMilli(), monthUsed, month.UnixMilli())))
|
|
if len(ws) != 3 {
|
|
t.Fatalf("windows: %+v", ws)
|
|
}
|
|
return allowanceOf(ws, now)
|
|
}
|
|
for _, c := range []struct {
|
|
name string
|
|
a Allowance
|
|
want int
|
|
first time.Time // the renewal Smart ranks it by
|
|
}{
|
|
// the reading as reported: four weeks to go hold 28,017, more
|
|
// than the 18,372 left, so the month still decides
|
|
{"as reported", plan(1628, 1628, now.Add(696*time.Hour)), 0, now.Add(696 * time.Hour)},
|
|
// three weeks to go: 21,017 still carry 18,372
|
|
{"three weeks to go", plan(0, 1628, weekRenews.Add(3*week)), 0, weekRenews.Add(3 * week)},
|
|
// two weeks and a bit to go: 14,017 can't, so what this week
|
|
// leaves is lost at its reset, and the week ranks it
|
|
{"two weeks to go", plan(0, 1628, weekRenews.Add(2*week+24*time.Minute)), 1, weekRenews},
|
|
// the last week: whatever is left past 7,000 is lost anyway,
|
|
// and the week ranks it all the more
|
|
{"the last week", plan(1628, 1628, weekRenews.Add(day)), 1, weekRenews},
|
|
// a month holding less than its weeks add up to, with less left
|
|
// than the weeks to come carry (#1778): the month, as today
|
|
{"month within reach", plan(0, 11000, weekRenews.Add(2*week)), 0, weekRenews.Add(2 * week)},
|
|
} {
|
|
got := c.a.Unreached("doubao-seed-2.0-pro", now)
|
|
if got != c.want {
|
|
t.Errorf("%s: unreached %d, want %d", c.name, got, c.want)
|
|
}
|
|
if r := c.a.Renewal("doubao-seed-2.0-pro", now); len(r) != 3 || !r[got].Equal(c.first) {
|
|
t.Errorf("%s: ranked by %v, want %v", c.name, r, c.first)
|
|
}
|
|
}
|
|
|
|
// nothing else changes: a window alone, windows that tell only a
|
|
// share, and counts in different units are never compared
|
|
month := now.Add(2*week + day)
|
|
for name, a := range map[string]Allowance{
|
|
"one window": {{Used: 10, Resets: month, Span: 30 * day, Amount: 2000, Of: 20000}},
|
|
"shares only": {
|
|
{Used: 10, Resets: month, Span: 30 * day},
|
|
{Used: 0, Resets: weekRenews, Span: week},
|
|
},
|
|
"other units": {
|
|
{Used: 10, Resets: month, Span: 30 * day, Amount: 2000, Of: 20000, Unit: "credits"},
|
|
{Used: 0, Resets: weekRenews, Span: week, Of: 7000, Unit: "USD"},
|
|
},
|
|
// the next window a rate cap: what five hours leave isn't lost
|
|
"five hours under a week": {
|
|
{Used: 10, Resets: now.Add(6 * time.Hour), Span: week, Amount: 700, Of: 7000},
|
|
{Used: 0, Span: 5 * time.Hour, Of: 2000},
|
|
},
|
|
} {
|
|
if got := a.Unreached("m", now); got != 0 {
|
|
t.Errorf("%s: unreached %d", name, got)
|
|
}
|
|
}
|
|
}
|