shangyuan0818 asked again, and the coordinator agreed: magpie runs the whole time, a reset's expiry is known to the second, and a user who is worried can pick a long lead. So the menu ends with Custom…, and the floor is now what the gateway needs, not 15 or 5 minutes. - settings: CodexResetLeadLeast 5 -> 3; the presets start at 3. The CLI (magpie quota reset-lead) and settings/codex-reset-lead check the same constant. Saved values stay valid: everything from 5 to 1440 still is. - Why 3: since v0.1.3204 the loop wakes at the lead's start (timer, at most 1s late), a try is bounded by the pass's 2 minutes, and a failure in the last 15 minutes is tried again a minute after it began, at once when that has passed. At 3 minutes a try hung to its bound ends at T-0:57 and a retry starts at T-0:56. At 2 minutes a hung try leaves no retry before expiry. - GUI (autoresetown.js): Custom…, the menu's last item, puts a field of minutes where the button was, at the button's size, so the row doesn't rewrap. Enter or leaving it saves. Escape keeps the lead. A number outside 3 to 1440 is shown as an error and not written. A redraw leaves the field alone while it is open. It uses the app menu and no native select. There is one new string, in all five languages. Tests: - TestShortLeadSpentInTime: at the least lead, for four phases, the reset is spent at T-3:00, and after a 2-minute hung try plus a 30s retry it is spent before expiry. - TestQuotaResetLeadCmd: 3m is taken and 2m is refused. - codex-reset-lead.test.cjs: 12 items, picking 3 min, and Custom… in every language at 1100 and 420. Typing 7 and pressing Enter posts 7. Typing 2 is said and not posted. Escape posts nothing, and leaving the field posts 12. Opening the field moves no page. Run on mote at this tree: - go test of the reset-lead, short-lead, reset-loop, expiring and quota-reset tests in provider, cli and settings: ok. - go vet: darwin, linux -tags nogui and windows on provider, settings and cli, plus darwin on gui: ok. - go test ./internal/gui: TestCoreScriptBudget ok with no raise (the field lives in the lazy autoresetown.js). TestMainWindowCorners is red, as in #3949. - GUI codex-reset-lead, codex-auto-reset-settings and i18n-keys in Chromium and WebKit: 49/50. The red is i18n-keys "a plugin's words are its own", filed as #5327, #5332, #5426 and #5482. Before the last comment trims, codex-reset-lead, codex-auto-reset-settings and providers-reset-use passed 86/86. Broken by hand, each red: - Floor at 2: the least-lead hung case goes red (one try, no retry), and so does the CLI (2m taken). - Floor at 5: the CLI refuses 3m. - The GUI range check removed: "2 isn't posted". - Escape saving: "Escape posts nothing". - The field at its own size (76x27) instead of the button's: WebKit ja and de at 1100 move the page 1px. Not tried: a real ChatGPT reset spent at 3 minutes, since none of my accounts has a reset about to expire. The redraw guard has no test of its own, because a click elsewhere blurs the field and saves first. Reported-by: shangyuan0818 (Discord)
46 lines
1.8 KiB
Go
46 lines
1.8 KiB
Go
package cli
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// magpie quota auto-reset lead sets how long before a reset about to
|
|
// expire it is used, says it alone, puts back the default, and refuses a
|
|
// value out of range or not whole minutes, writing nothing then.
|
|
func TestQuotaResetLeadCmd(t *testing.T) {
|
|
groupsHome(t)
|
|
if out, err := runOut(t, "quota", "auto-reset", "lead"); err != nil || !strings.Contains(out, "used 30m before it expires (the default)") {
|
|
t.Fatalf("unset: %q %v", out, err)
|
|
}
|
|
for _, c := range []struct {
|
|
arg string
|
|
want int
|
|
}{{"2h", 120}, {"15m", 15}, {"3m", 3}, {"5m", 5}, {"10m", 10}, {"24h", 1440}, {"90", 90}, {"1h30m", 90}} {
|
|
arg, want := c.arg, c.want
|
|
if out, err := runOut(t, "quota", "auto-reset", "lead", arg); err != nil || settings.Load().CodexResetLead != want {
|
|
t.Fatalf("%s: %q %v, set %d", arg, out, err, settings.Load().CodexResetLead)
|
|
}
|
|
}
|
|
if out, err := runOut(t, "quota", "auto-reset", "lead"); err != nil || !strings.Contains(out, "used 1h30m before it expires") || strings.Contains(out, "default") {
|
|
t.Fatalf("set: %q %v", out, err)
|
|
}
|
|
for _, bad := range []string{"2m", "1m", "25h", "-1h", "30s", "90s", "soon", "--help"} {
|
|
if bad == "--help" {
|
|
if out, err := runOut(t, "quota", "auto-reset", "lead", bad); err != nil || !strings.Contains(out, "usage:") {
|
|
t.Fatalf("--help: %q %v", out, err)
|
|
}
|
|
} else if _, err := runOut(t, "quota", "auto-reset", "lead", bad); err == nil {
|
|
t.Fatalf("%s: taken", bad)
|
|
}
|
|
if got := settings.Load().CodexResetLead; got != 90 {
|
|
t.Fatalf("%s: wrote %d", bad, got)
|
|
}
|
|
}
|
|
if out, err := runOut(t, "quota", "auto-reset", "lead", "default"); err != nil || settings.Load().CodexResetLead != 0 || !strings.Contains(out, "30m") {
|
|
t.Fatalf("default: %q %v", out, err)
|
|
}
|
|
}
|