A key that keeps failing doubles its rest from a minute up to 10 minutes, and one rate limited again as soon as its rest is over up to 30; both caps were fixed, so a free key down for hours was asked again every 10 or 30 minutes all the while. `magpie provider rest-cap <id> 4h` (Provider.RestCap, minutes, at most MaxQuotaRest, 8 days) sets where both ladders stop for that provider's keys and accounts (RestCapOr in restAfterMarked's default branch and in rateRest); `default` gives back the gateway's own. A time the vendor names still stands over it. Unset, nothing differs. It is kept by the editor's save, the account copy and normalize. Run: go test -tags nogui ./internal/provider ./internal/gateway ./internal/cli ./internal/gui (temp HOME). Broken by hand: both ladders back on the fixed caps fail TestOwnRestCap (rate-long #6: 30m, want 32m); the GUI keep removed fails TestSaveKeepsQuotaResetAt. Not tried against a real vendor's outage.
46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
package gui
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// #2008: the editor knows nothing of the time of day a provider's daily
|
|
// allowance comes back, set by `magpie provider quota-rest <id> until
|
|
// 08:00`, nor of its rest cap (`magpie provider rest-cap`), so its save
|
|
// keeps both.
|
|
func TestSaveKeepsQuotaResetAt(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("USERPROFILE", home)
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
|
if err := provider.Save(provider.Provider{ID: "reset-test", Name: "Reset", Chat: "https://example.invalid/v1", Key: "k"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := provider.SetQuotaResetAt("reset-test", "00:00+08:00"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := provider.SetRestCap("reset-test", 240); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
mux := http.NewServeMux()
|
|
providerRoutes(mux, nil)
|
|
w := httptest.NewRecorder()
|
|
mux.ServeHTTP(w, httptest.NewRequest("POST", "/api/provider/save", strings.NewReader(`{"id":"reset-test","name":"Reset","chat":"https://example.invalid/v1"}`)))
|
|
if w.Code != 200 {
|
|
t.Fatalf("%d %s", w.Code, w.Body)
|
|
}
|
|
got, err := provider.Find("reset-test")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got.QuotaResetAt != "00:00+08:00" || got.RestCap != 240 || got.Name != "Reset" {
|
|
t.Fatalf("the save dropped the reset time %q or the rest cap %d", got.QuotaResetAt, got.RestCap)
|
|
}
|
|
}
|