Files
magpie/internal/gui/model_output_test.go
T
yetone e5b5397c96 providers: a model's context window and max output are set in its Model settings row
sayagoodbyeplz on Discord: WorkBuddy's deepseek-v4.1-flash replies 128000
tokens, not the 384000 models.dev lists, and there was no visible place
to set that for one model. The editor's Advanced Context window and Max
output already took "model=size", but a user looking at the model never
saw them.

Each model's row in Model settings now has a Context window box and a
Max output box beside "Listed as". The placeholder is the listed value
(the vendor's list, else models.dev's, within the window), or the "*"
value from Advanced when one is set. A value typed there is staged as
model=size in Advanced's field, so both say the same thing, and the Save
sends it in contexts/outputs as before. An empty box drops the model's
own value. A bad value is refused with Advanced's message. Restore
default clears both, and its title says so in every language. A
classifier-only provider has neither box, as in Advanced.
/api/providers gives each model a listedOutput (its reply limit without
the user's Max output) so the placeholder doesn't show the user's own
value back.

The boxes are drawn by modellimits.js, imported when the editor draws a
model's row (like keyspend.js), and nine comments in app.js are cut, so
the core stays in its budget with no raise (1,533,541 of 1,533,802 on a5c97cd83).

Run (mote before the modellimits.js move; WSL magpie-desktop, Go 1.26.8,
at this tree, after it, since mote went down):
- go vet ./... (mote, darwin; again on internal/gui, agent and provider
  at the rebased head on a5c97cd83); GOOS=windows go vet ./... and
  GOOS=linux go vet -tags nogui ./... (WSL): ok
- go test ./internal/gui/ ./internal/agent/ ./internal/provider/ (mote): ok,
  except the real-window AppKit tests TestCoveredWindowStaysUp and
  TestClosingWindowMarksPageOutOfSight killed at their deadlines (#4924,
  #2645); WSL, -tags nogui: TestProviderModelOutput*|Budget ok
- TestProviderModelOutputSaid gains a check that listedOutput is
  models.dev's 131072 while the user's 100000 is set
- node --test internal/gui/tests/model-limits.test.cjs (new): 20/20,
  Chromium and WebKit, en/zh/zh-TW/ja/de, 1200 and 420px: placeholder
  384K, 128k typed -> Advanced "deepseek-v4.1-flash=128k" and unsaved,
  a bad value refused, Advanced's "*" becomes the placeholder, the Save
  body's outputs/contexts, Restore default clears the model's own
- WSL, at this tree: model-limits, model-headers, model-price-tiers,
  model-api-preset, provider-detect, provider-listed-as,
  provider-same-as, provider-max-output, provider-output-picks,
  old-webkit, i18n-keys: 105/106, the one red i18n-keys' "a plugin's
  words are its own", red at a46190e1f too (#5332, #5426);
  TestCoreScriptBudget ok. Before that, every model-*, provider-*,
  editor-*, context-picks/tune*, i18n-*, menu-scroll, click-scroll and
  old-webkit file (2325 tests): the reds in model-chip-steady,
  model-copy-id, provider-models-rest, provider-picks-stay,
  provider-fetch-again, provider-typed, model-suffix-own, model-load,
  editor-advanced-align and click-scroll are red the same at a46190e1f on
  WSL (#4388, #4621, #4396, #4397, #5232, #4673, #4962, #4615, #4385).
  That run found two of this change's own: the rows' hooks kept on the
  draft made an untouched editor read as unsaved (model-price-tiers,
  model-api-preset), and a row filled after an await moved the page
  (provider-detect); the hooks are left out of the draft's value and a
  row is filled at once once modellimits.js is loaded.
Broken by hand: model-limits.test.cjs on origin/main's assets fails at
once (no .mlimit row).
Not tried: the real app window; the full GUI suite.
Full suite not run at push.

Reported-by: sayagoodbyeplz (Discord)
2026-11-08 19:05:36 +08:00

123 lines
4.6 KiB
Go

package gui
import (
"os"
"path/filepath"
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/provider"
)
// ARNO on Discord: a model's output limit wasn't in the Gateway's model
// tooltip, though agents were told one when it was written to their
// config. The page's models carried no output at all, so the tooltip had
// a line only for routing groups. Each model now says the reply limit
// agents are told: the vendor's list's, else models.dev's, else the
// user's Max output over both.
func TestProviderModelOutputSaid(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755)
os.WriteFile(catalog.CachePath(), []byte(`{
"zai":{"id":"zai","models":{"glm-5.3-flash":{"id":"glm-5.3-flash","limit":{"context":1000000,"output":131072}}}}}`), 0o644)
catalog.Reset()
t.Cleanup(catalog.Reset)
if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"zai/glm-5.3-flash", "own-model"}}); err != nil {
t.Fatal(err)
}
said := func() map[string]int {
t.Helper()
p, err := provider.Find("relay")
if err != nil {
t.Fatal(err)
}
out := map[string]int{}
for _, m := range providerInfo(*p, nil).Models {
out[m.ID] = m.Output
}
for _, e := range provider.Served() {
if n, ok := out[e.Model]; ok && n != e.Output {
t.Errorf("%s: the page says %d, agents are told %d", e.Model, n, e.Output)
}
}
return out
}
if got := said(); got["zai/glm-5.3-flash"] != 131072 || got["own-model"] != 0 {
t.Fatalf("models.dev's: %v", got)
}
if err := provider.SetModelOutput("relay/own-model", 64_000); err != nil {
t.Fatal(err)
}
if got := said(); got["own-model"] != 64_000 {
t.Fatalf("the user's: %v", got)
}
// Model settings' Max output shows what is listed when none is set, the
// user's own aside (sayagoodbyeplz on Discord: 384000 from models.dev
// beside the 128000 typed over it)
if err := provider.SetModelOutput("relay/zai/glm-5.3-flash", 100_000); err != nil {
t.Fatal(err)
}
p, err := provider.Find("relay")
if err != nil {
t.Fatal(err)
}
for _, m := range providerInfo(*p, nil).Models {
if m.ID == "zai/glm-5.3-flash" && (m.Output != 100_000 || m.ListedOutput != 131072) {
t.Errorf("with the user's 100000: output %d, listed %d; want 100000, models.dev's 131072", m.Output, m.ListedOutput)
}
}
}
// #1438 (yhong91): a model's reply limit is shown within the window shown
// beside it, as agents are told it and /v1/models gives it — models.dev's
// 500000 for grok-4.7 against the 256000 its backend lists. One within its
// window, or with no window known, is shown as it was, and so is a group's.
func TestProviderModelOutputWithinTheWindow(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755)
os.WriteFile(catalog.CachePath(), []byte(`{"xai":{"id":"xai","models":{"grok-4.7":{"id":"grok-4.7","limit":{"context":500000,"output":500000}}}}}`), 0o644)
catalog.Reset()
t.Cleanup(catalog.Reset)
if err := provider.Save(provider.Provider{ID: "gx", Name: "GX", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"grok-4.7", "own-within", "own-nowindow"}}); err != nil {
t.Fatal(err)
}
if err := catalog.SaveLive("gx", "http://127.0.0.1:1/v1", []catalog.Model{
{ID: "grok-4.7", Context: 256000}, {ID: "own-within", Context: 128000, Output: 64000}, {ID: "own-nowindow", Output: 500000}}); err != nil {
t.Fatal(err)
}
if err := provider.SaveGroup(provider.Group{ID: "g", Name: "G", Members: []string{"gx/grok-4.7"}}); err != nil {
t.Fatal(err)
}
p, err := provider.Find("gx")
if err != nil {
t.Fatal(err)
}
got := map[string][2]int{}
for _, m := range providerInfo(*p, nil).Models {
got[m.ID] = [2]int{m.Context, m.Output}
}
for id, want := range map[string][2]int{"grok-4.7": {256000, 256000}, "own-within": {128000, 64000}, "own-nowindow": {0, 500000}} {
if got[id] != want {
t.Errorf("%s: the page says window, output %v; want %v", id, got[id], want)
}
}
seen := false
for _, g := range providersState().Gateway.Groups {
seen = seen || g.ID == provider.GroupPrefix+"g"
if g.ID == provider.GroupPrefix+"g" && (g.Context != 256000 || g.Output != 256000) {
t.Errorf("the group: window %d, output %d", g.Context, g.Output)
}
}
if !seen {
t.Error("the group is not on the Gateway page")
}
}