Files
magpie/internal/gateway/model_tier_test.go
T
yetone a5e805f574 Codex: Ultrafast beside Fast in a group member, and a Fast/Ultrafast setting per model (kdajenks on X)
kdajenks (magpie 0.1.3739, Codex on ChatGPT Pro) could set Fast only from a
routing group's member row and had no Ultrafast there, and no way to set the
speed in the model's own settings. Ultrafast exists: Codex's catalog lists
the `ultrafast` service tier, the code already sent it for agent picks and
Codex's service-tier row, and the live account's service_tiers hold it.

- Group member: the button steps Standard speed, Fast, Ultrafast (where an
  account offers it, `ultraOK`), back to Standard. `Group.Ultra` is a subset of
  `Fast`, kept through rename, fold, share, gone-filter and the CLI
  (`magpie group ... ultra=`). The gateway marks the candidate `ultra`.
- Per model: `settings.ModelTiers` ("<provider>/<model>" to priority or
  ultrafast), `provider.SetModelTier` (refused where CanFast/CanUltra say no),
  `ModelPref.Tier` in Model settings (Standard speed / Fast / Ultrafast, in
  modellimits.js), and `magpie model tier <provider/model> [fast|ultrafast|usual]`.
  The gateway sends it on a direct pick for an agent with no fast pick of its
  own, through fastPick, so an account without Ultrafast gets priority. A group
  member goes as the group says.
- Docs: gateway-routing, providers-accounts, reference.

Run (mica, at the rebased head over a6d84e13a):
- gofmt -l clean; go vet darwin, linux nogui, windows clean.
- go test internal/provider, internal/settings ok; internal/gui and
  internal/cli ran: the one red of mine (TestSettingsSaveKeepsWhatItDoesNotSend
  wanting ModelTiers) is fixed in this commit; the others are not mine and
  red on a clean origin/main: TestEveryRouteHasACommandOrIsNamed (#6202),
  TestPanelHiddenByWailsMarksPageOutOfSight (#6203, not checked on main).
- internal/gateway ok (984s).
- GUI, chromium and webkit: new model-speed.test.cjs (30, five languages, 1200
  and 420px), plus model-*, group-*, fast-*, i18n-*, text-size,
  codex-service-tier, panel-*, routing-group*, routing-save* files. Red and not
  mine, same on a clean origin/main worktree: fast-pick and fast-ultra (#6201),
  group-editor-selected (#5049).
- New tests TestModelTierSentToEveryAgent, TestGroupMemberUltrafast,
  TestCleanModelTier, TestSaveGroupUltra.

Broken by hand: removing the gateway's model-tier branch and the candidate
`ultra` copies turned both gateway tests red; turning off the Ultrafast choice
in Model settings turned 20 of 30 GUI tests red; reverting the member button to
two states turned 10 of 30 red.

Not tried: a real ChatGPT account sending Ultrafast through the new setting;
the agent picker's bolt does not show a model-level default; Windows and Linux
GUI runs.
2026-11-12 01:56:26 +08:00

96 lines
3.3 KiB
Go

package gateway
import (
"net/http"
"net/url"
"strings"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// kdajenks on X: the speed given to a model in its Model settings is sent
// on every agent's requests for it that have no fast pick of their own,
// Ultrafast first to the account that offers it and priority to one that
// doesn't; a group's member is sent as the group says.
func TestModelTierSentToEveryAgent(t *testing.T) {
proOut := false
tried := tierAccounts(t, &proOut, nil)
to, _ := url.Parse(provider.CodexBase)
provider.CodexBase = "https://chatgpt.com/backend-api/codex"
s := New()
s.client = &http.Client{Transport: roundTripFunc(func(r *http.Request) (*http.Response, error) {
r.URL.Scheme, r.URL.Host = to.Scheme, to.Host
return http.DefaultTransport.RoundTrip(r)
})}
send := func(agent string) string {
t.Helper()
postFrom(t, s, agent, "/v1/responses", `{"model":"codex/gpt-6-luna","input":"ping"}`)
return strings.Join(tried(), ",")
}
if got := send("omp"); got != "acct-plus:" {
t.Fatalf("no tier set: tried %s", got)
}
if err := provider.SetModelTier("codex/gpt-6-luna", "ultrafast"); err != nil {
t.Fatal(err)
}
for _, agent := range []string{"omp", "opencode"} {
if got := send(agent); got != "acct-pro:ultrafast" {
t.Errorf("%s: ultrafast tried %s", agent, got)
}
}
proOut = true
if got := send("omp"); got != "acct-pro:ultrafast,acct-plus:priority" {
t.Errorf("pro out: tried %s", got)
}
proOut = false
if err := provider.SetModelTier("codex/gpt-6-luna", "fast"); err != nil {
t.Fatal(err)
}
if got := send("omp"); got != "acct-plus:priority" {
t.Errorf("fast tried %s", got)
}
if err := provider.SetModelTier("codex/gpt-6-luna", "usual"); err != nil {
t.Fatal(err)
}
if got := send("omp"); got != "acct-plus:" {
t.Errorf("usual again tried %s", got)
}
}
// A group's member is sent as the group says: Ultrafast to the account that
// offers it, whatever tier the model's own settings give it.
func TestGroupMemberUltrafast(t *testing.T) {
proOut := false
tried := tierAccounts(t, &proOut, nil)
to, _ := url.Parse(provider.CodexBase)
provider.CodexBase = "https://chatgpt.com/backend-api/codex"
s := New()
s.client = &http.Client{Transport: roundTripFunc(func(r *http.Request) (*http.Response, error) {
r.URL.Scheme, r.URL.Host = to.Scheme, to.Host
return http.DefaultTransport.RoundTrip(r)
})}
if err := provider.SaveGroup(provider.Group{ID: "u", Name: "U", Members: []string{"codex/gpt-6-luna"}, Fast: []string{"codex/gpt-6-luna"}, Ultra: []string{"codex/gpt-6-luna"}, Routing: provider.Ordered}); err != nil {
t.Fatal(err)
}
send := func() string {
t.Helper()
postFrom(t, s, "omp", "/v1/responses", `{"model":"group/u","input":"ping"}`)
return strings.Join(tried(), ",")
}
if got := send(); got != "acct-pro:ultrafast" {
t.Errorf("ultra member tried %s", got)
}
proOut = true
if got := send(); got != "acct-pro:ultrafast,acct-plus:priority" {
t.Errorf("pro out: tried %s", got)
}
proOut = false
if err := provider.SaveGroup(provider.Group{ID: "u", Name: "U", Members: []string{"codex/gpt-6-luna"}, Fast: []string{"codex/gpt-6-luna"}, Routing: provider.Ordered}); err != nil {
t.Fatal(err)
}
if got := send(); got != "acct-plus:priority" {
t.Errorf("fast member tried %s", got)
}
}