wowbbs (and shamen_xiaohong) keep check-in free accounts in one group:
WorkBuddy CN x2, MiniMax Code, TraeCode CN and Qoder CN. They asked that
the group spend the free quota that lapses soonest first, go on to the next
when one is used up or has lapsed, and use a paid account only when no free
quota is left.
This adds `expiring` (provider.FreeExpiring, routes.FreeExpiring). It is a
group's only, picked in the Routing page's group menu, with
`magpie group set <g> routing=expiring` or in the TUI. Nothing changes for a
group or provider that doesn't pick it. A provider keeps refusing it, as it
refuses `cheap`.
- routes: Seat.FreePlan and Strategy.ByPlan. FreeExpiring has three tiers:
- free seats (Free, a model at no cost, or FreePlan) by Expires, the
earliest of the window renewals and Lapse, to the hour; an unknown
expiry goes last and ties keep their listed order;
- then the paid seats, as Smart orders them;
- then the spent and resting seats, by when they come back.
- provider.FreePlan reads an account's plan word: free, trial, 免费, 试用,
体验, 體驗.
- gateway: weighRouted fills FreePlan when the strategy asks. The trace's
Weighed rows gain `expires`, so the Routing page's story can say "its free
quota is lost soonest, in 1d 2h". There are also lines for "a free one with
no expiry told" and "no free quota left, so the paid one".
- GUI: an option in the group menu, the mode line, the story lines, and
i18n in zh, zh-TW, ja and de. app.js only adds `expiring` to ROTATION,
paid for by a shorter comment beside it, so the core is 11 bytes smaller
than at its base.
- docs: gateway-routing.md (order of keys and accounts) and
plugin-runtime.md (Seat and Strategies).
Plugins whose usage doesn't say when their free quota lapses got issues
rather than edits:
- magpie-community/plugins#718: Trae sums its packs; the soonest end comes
from any pack, spent or past, and there is no runsOutAt.
- magpie-community/plugins#719: Qoder's plan is the raw userType
personal_standard, which doesn't read as free, and its add-on, shared and
dedicated pools have no expiry.
WorkBuddy (Free plan, resetsAt and runsOutAt) and MiniMax (Free, runsOutAt
on credits) already report what this needs.
Run, all on mote via mote-run at this tree (base 0ee424e3e):
- gofmt -l internal plugins: empty. go build ./....
- go vet of routes, gateway, provider, cli and tui; the same with
GOOS=linux -tags nogui and with GOOS=windows.
- go test ./internal/routes ./plugins/rotation ./internal/tui: ok.
- provider -run TestFreePlan|Group|Routing: ok.
- cli -run Routing|Group: ok.
- gateway -run TestGroupSpendsFreeQuota|Wallet|Free|Cheapest|Routing|Weigh: ok.
- internal/gui -run Budget|Size: TestCoreScriptBudget is red, already red
at the base (1,534,154 > 1,533,802, #5139). This change takes the core
down 11 bytes and doesn't raise the budget.
- GUI, node --test in chromium and webkit, en, zh, zh-TW, ja and de, wide
and 420px:
- routing-free-expiring (new), routing-group-strategy, routing-cheapest-first,
i18n-keys, builtins, group-member-free and provider-count-free: 176 of
176 pass;
- every routing-*.test.cjs: 2,478 of 2,520 pass. The 42 reds are in ten
files (routing-rule-remove, rule-drag, rules-line, rule-models,
row-swap, steady, order-unknown, steps-cap, story-shrinks and
keys-fold). Run alone at this tree they give 27 reds, and at the base
0ee424e3e 25, the same tests. They are filed as #5088, #4585, #3096,
#3789, #3799, #4627, #4628 and #4629.
Again after rebasing on origin/main 0e804be29: gofmt; vet of routes,
gateway and provider; the same Go tests: ok. routing-free-expiring,
routing-group-strategy and i18n-keys: 62 of 62 pass. The core is 1,534,034
here, against main's 1,534,045.
Red on the old code: TestGroupSpendsFreeQuotaSoonestToExpireFirst at
0ee424e3e gives "pro,wb1,wb2,mm,qoder" where it wants
"mm,wb2,qoder,wb1,pro".
Broken by hand: with FreePlan never set, the gateway test gives
"pro,mm,wb2,qoder,wb1" (red). routing-free-expiring.test.cjs reads strings
that exist only with this change. routing-group-strategy's two menu counts
(11) went red with the new option, and they now count 12.
Not tried: no real account of any vendor. WorkBuddy, MiniMax, Trae and
Qoder check-in accounts were not routed live. The order was tested on
fabricated allowances shaped as their plugins report them. The full
`go test ./...` runs after the push.
17 lines
596 B
Go
17 lines
596 B
Go
package provider
|
|
|
|
import "testing"
|
|
|
|
// FreePlan reads a plan as its vendor or plugin names it: WorkBuddy's
|
|
// "Free plan", MiniMax's and Trae's "Free", a trial, a Chinese name.
|
|
func TestFreePlan(t *testing.T) {
|
|
for plan, want := range map[string]bool{
|
|
"Free plan": true, "Free": true, "free": true, "Pro (free trial)": true, "Trial": true, "免费版": true, "试用": true,
|
|
"Pro": false, "Credits": false, "M Plan Plus": false, "TokenPlanMax-年度会员": false, "": false,
|
|
} {
|
|
if got := FreePlan(plan); got != want {
|
|
t.Errorf("FreePlan(%q) = %v, want %v", plan, got, want)
|
|
}
|
|
}
|
|
}
|