provider: a test that WorkBuddy's spent free-token window holds its model only (youjianqiasongshan)

youjianqiasongshan (Discord) has a WorkBuddy Free plan card that shows
积分 500/500, Extra credits 3,406.7/3,750 and Free model tokens 0 of
200,000,000 left. They asked why they can't use the other credits.

The test builds the usage answer workbuddy 0.2.16 gives for that card:
- the plan's credits are used up and set aside (usageOf);
- both credit windows leave the free models out (spareFree, notModels);
- the free model's window is refused, listing deepseek-v4.1-flash and
  -flash-sg (freeWindowOf).
It checks that routing reads this as:
- glm-5.1, kimi-k2.6 and deepseek-v4.1 on Extra credits' share, and
  never used up;
- the two flash ids used up until the window's reset;
- their refusal pooled to the model (Pooled);
- the account not held up and not week-used-up.
The code already does this, so nothing in magpie or the plugin changes.
The gateway rests a "切换其他模型" refusal on that model alone
(otherModels, #1669).

Run at this head (mote): go test -tags nogui ./internal/provider ok, and
gofmt is clean.

Broken by hand: with plugin_usage.go ignoring a window's models list, the
test fails on all three non-free models, on Pooled, on heldUp and on
WeekUsedUp.

Not tried:
- The reporter's real account or usage answer. The fixture is built
  from their card's numbers.
- Whether they turned on "仅免费模型" (Free models only), or pinned
  deepseek-v4.1-flash in their agent. Either one would leave the extra
  credits unused once the free tokens are gone.
This commit is contained in:
yetone
2026-11-03 10:39:41 +08:00
parent db0ca1d2d3
commit a92e85ab20
@@ -0,0 +1,49 @@
package provider
import (
"testing"
"time"
)
// youjianqiasongshan on Discord: a WorkBuddy Free plan card of 积分 500 /
// 500, Extra credits 3,406.7 / 3,750 and Free model tokens refused (0 left
// of 200,000,000), asking why the other credits can't be used. The usage
// answer is shaped as workbuddy 0.2.16 gives it for that card: the plan's
// credits used up and set aside (usageOf), both credit windows not counting
// the free models (spareFree), and the free model's own window refused,
// listing its two ids. Routing reads that as the free model used up and
// every other model on Extra credits, never as the account out.
func TestWorkBuddyFreeTokensSpentLeaveCredits(t *testing.T) {
now := time.Now()
reset := now.Add(20 * time.Hour).UTC().Format(time.RFC3339)
usage := []byte(`{"plan":"Free plan","windows":[
{"name":"Credits","used":100,"display":"500 / 500","amount":500,"limit":500,"unit":"credits","aside":true,"notModels":["deepseek-v4.1-flash","deepseek-v4.1-flash-sg"]},
{"name":"Extra credits","used":90.85,"display":"3,406.7 / 3,750","amount":3406.7,"limit":3750,"unit":"credits","notModels":["deepseek-v4.1-flash","deepseek-v4.1-flash-sg"]},
{"name":"Free model tokens","used":100,"amount":200000000,"limit":200000000,"unit":"tokens","display":"200.0M / 200M","resetsAt":"` + reset + `","span":86400,"models":["deepseek-v4.1-flash","deepseek-v4.1-flash-sg"],"refused":true}]}`)
a := PluginAllowanceForTest(usage, now)
if a == nil {
t.Fatal("no allowance from the usage answer")
}
for _, m := range []string{"glm-5.1", "kimi-k2.6", "deepseek-v4.1"} {
if used, _ := a.For(m, now); used >= 100 {
t.Errorf("%s: %v%% used, want Extra credits' share", m, used)
}
if at := a.Full(m, 100, now); !at.IsZero() {
t.Errorf("%s: used up until %v, want usable", m, at)
}
}
for _, m := range []string{"deepseek-v4.1-flash", "deepseek-v4.1-flash-sg"} {
if at := a.Full(m, 100, now); at.IsZero() {
t.Errorf("%s: not used up, want held to the free window's reset", m)
}
if !a.Pooled(m, 100, now) {
t.Errorf("%s: its refusal stops the account, want only the model", m)
}
}
if stopped, _ := a.heldUp(); stopped {
t.Error("the account is held up as a whole")
}
if a.WeekUsedUp(now) {
t.Error("the free window reads as the account's week used up")
}
}