TestPluginFactoryStandardOnlyCaps runs the fake plugin as factory (marked
moved, two OAuth accounts A then B, order routing, each capped at 99% with
SetAccountCap as `magpie provider account-cap factory <account> 99` does).
The windows are those Factory's plugin 0.1.38 reports with standard_only
on (limitWindows(l, true)): Standard's 5 hours and 7 days with no model
list, Droid Core's and Extra usage aside. The fake plugin gains
$FAKE_WINDOWS, a file of each account's windows read at each usage
reading, so routing reads them through the host and provider.Allowances,
not a stub.
What it holds, today's behaviour, no code change:
- A's 7 days at 99% (its 5 hours at 40%): A is not sent the request; B
serves fake-1, fake-claude and glm-5.3 (a Droid Core model). The trace
shows a@fake 99/99 left out with its reset. Core windows at 100% on an
account below its Standard caps don't hold it.
- Both capped (A's 5 hours 99%, B's week 100%): 429 rate_limit_error,
"usage cap reached: every account that serves ... - Factory (a@fake) is
at 99% of a usage window, past its 99% cap, until <time>; Factory
(b@fake) ...", advice naming magpie provider account-cap, Retry-After
at the sooner reset (A's 5 hours), nothing sent to the vendor, logged
"every account at its usage cap".
- A read again below its cap serves again; a kept reading still at 99%
whose reset time has passed serves too.
- A conversation on A moves to B when A is capped. Once A is back: auto
affinity with no cache worth keeping goes back to A; with B's cache
(5000 cached tokens) it stays on B; affinity session stays on B. A new
conversation goes to A.
Broken by hand, each red at the step it guards: capHeld returning nil
(A served while capped), allowanceOf keeping aside windows (glm-5.3 went
to B while A's Standard windows were below cap), CapHeld ignoring a
passed reset (429 where A should serve).
Run: go test -tags nogui ./internal/gateway -run
TestPluginFactoryStandardOnlyCaps -count=1 -v, ok; go test -tags nogui
./internal/gateway ./internal/plugin ./internal/provider ./internal/cli
-count=1 -timeout 45m at base ed91aa04e: all four ok (gateway 494s,
plugin 217s, provider 191s, cli 88s); rebased onto ef1a203df and the new
test run again there (below). gofmt -l clean; GOOS=linux go vet -tags
nogui and GOOS=windows go vet of ./internal/gateway clean. No full ./...
suite: tests and testdata only, and another session's full suite was
running.
Sandbox HOME, built binary, fake plugin as factory, two accounts signed in
with magpie plugin login factory (browser opener stubbed on PATH):
magpie provider account-cap factory alice@fake 99 -> "capped at 99% of
each usage window", saved as accountCaps in providers.json; --window
"7 days" 95 and default work; an unknown account and 150 are refused.
Not tried: real Factory accounts, the real plugin's own option toggle in
magpie (its own usage.test.mjs covers the switch), the Anthropic
/v1/messages route's 429 body.