ChatGPT's image generation has a quota apart from the 5-hour and weekly windows. Neither /wham/usage (additional_rate_limits is null) nor the reply headers (x-codex-primary-*, x-codex-secondary-*) tell it, so no remaining count exists to show. Each Codex account's card (Usage page, magpie quota --json, /v1/magpie/quotas, /v1/magpie/quotas/cards) now has an "Image generation" row (provider.WithImageLane, Lane "images", Text and Aside so routing, holds, history, tray and statusline never see it): "Used up" with the reset time while the image model rests on that account after a refusal (the #2244 drawing-lane rest, whose time is the refusal's resets_at), and "Unknown" otherwise. Never a share or a count. Shown in en, zh, zh-TW, ja, de. app.js: a Text row's display now goes through t(), a same-length change, as the core script budget has 1 byte of room. Run (on mote): go test -count=1 -run 'TestWithImageLane|TestCodexImageRow' ./internal/provider ./internal/gateway ok; codex-image-row.test.cjs in chromium and webkit at 900 and 390px in all five languages ok; TestCoreScriptBudget ok; go vet darwin, windows, linux nogui on provider and gateway ok; gofmt clean; 158 GUI files matching i18n/quota/usage/balance names in both engines (result in the follow-up). Broken by hand: the GUI test is red with app.js's display line put back to the old form; the Go row tests are red with imageRestOf returning false. Not tried: a real ChatGPT account hitting its image quota (the row is driven by a faked refusal's rest); the generated-image count the issue also asks for is not built.
59 lines
2.5 KiB
Go
59 lines
2.5 KiB
Go
package gateway
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// #6160: a ChatGPT account's image allowance shows on its card as the time
|
|
// the refusal that rested it said, and as unknown before any refusal; the
|
|
// chat windows around it are as they were.
|
|
func TestCodexImageRowIsTheRefusalsResetTime(t *testing.T) {
|
|
user := "Image.Lane@example.com"
|
|
c := candidate{p: provider.Provider{ID: "codex", Account: &provider.Account{Agent: "codex", User: user}}, model: codexDrawer}
|
|
t.Cleanup(func() { clearRest(c.restID()) })
|
|
card := func() provider.SubscriptionQuota {
|
|
in := []provider.SubscriptionQuota{{Provider: "codex", User: user, Windows: []provider.QuotaWindow{{Name: "5 hours", Used: 40}, {Name: "7 days", Used: 10}}}}
|
|
out := provider.WithImageLane(in, time.Now())
|
|
if len(in[0].Windows) != 2 {
|
|
t.Fatalf("the cached card was written to: %d windows", len(in[0].Windows))
|
|
}
|
|
return out[0]
|
|
}
|
|
row := func(q provider.SubscriptionQuota) provider.QuotaWindow {
|
|
if len(q.Windows) != 3 || q.Windows[0].Name != "5 hours" || q.Windows[1].Name != "7 days" {
|
|
t.Fatalf("windows = %+v", q.Windows)
|
|
}
|
|
return q.Windows[2]
|
|
}
|
|
w := row(card())
|
|
if w.Lane != provider.ImageLane || !w.Text || !w.Aside || w.ResetsAt != nil || w.Used != 0 || w.Display != "Unknown" {
|
|
t.Fatalf("before any refusal the row = %+v, want unknown with no time", w)
|
|
}
|
|
at := time.Now().Add(3 * time.Hour).Truncate(time.Second)
|
|
body := []byte(`{"error":{"type":"usage_limit_reached","resets_at":` + itoa(int(at.Unix())) + `}}`)
|
|
restDrawer(c, http.StatusTooManyRequests, string(body))
|
|
w = row(card())
|
|
if w.ResetsAt == nil || w.ResetsAt.Sub(at).Abs() > 2*time.Second || w.Display != "Used up" || w.Used != 0 || !w.Text {
|
|
t.Fatalf("after the refusal the row = %+v, want used up until %v and no share", w, at)
|
|
}
|
|
// another account's refusal is not this one's
|
|
other := candidate{p: provider.Provider{ID: "codex", Account: &provider.Account{Agent: "codex", User: "other@example.com"}}, model: codexDrawer}
|
|
t.Cleanup(func() { clearRest(other.restID()) })
|
|
restDrawer(other, http.StatusTooManyRequests, string(body))
|
|
clearRest(c.restID())
|
|
if w = row(card()); w.ResetsAt != nil {
|
|
t.Fatalf("a rest lifted still shows a time: %+v", w)
|
|
}
|
|
// a chat model's rest on the account is not the image allowance
|
|
chat := candidate{p: c.p, model: "gpt-5"}
|
|
t.Cleanup(func() { clearRest(chat.restID()) })
|
|
restDrawer(chat, http.StatusTooManyRequests, string(body))
|
|
if w = row(card()); w.ResetsAt != nil {
|
|
t.Fatalf("a chat model's rest shows as the image row: %+v", w)
|
|
}
|
|
}
|