Files
magpie/internal/gui/model_window_test.go
yetone a0d41044bb providers: a provider's model list says the context window agents are told — the one set on it, else models.dev's for a prefixed id — not only its vendor's list's (Discord, ARNO on v0.1.815: provider的上下文窗口覆盖功能好像失效了。cline插件的模型都没有默认的上下文窗口大小 … 如zai/glm-5.3-flash,cline-free/mimo-v2.6-flash) — the Providers page's models (providerInfo's modelJSON.Context) took catalog.Model.Context as the vendor's list or the plugin gave it, while the catalog's entries (entryFor: /v1/models, every agent's config, routing) take the window the user set (Provider.ContextOf) over it, and models.dev's for the id (catalog.ContextOf, which already reads zai/glm-5.3-flash as glm-5.3-flash) where the list says none. So a window set in the editor or with magpie model context reached agents but not the page, the agents' model pickers (which read the same list) or a chip's 1M tag, and a model listed with no window — Cline's plugin gives every model 0 (fixed in its 0.1.2), a relay's prefixed ids — showed none. The window is now one function, Provider.WindowOf (the user's, else ListedWindow: the list's, else models.dev's), which entryFor and providerInfo both read; the page is also told the window before the user's (listed), which the context field's "Each model's most" pick compares against, so a model set to its most still offers it. Lookups by a prefixed id were not broken: in the owner's config 14 of 794 models had no window on the page and one from models.dev for agents (Gemini's, Kiro's auto), the same split. TestProviderModelWindowSaid (a relay serving zai/glm-5.3-flash and own-model: the page says 1M before a window is set and 200K/64K after, as Served does) fails on the old code (the page said 0 where agents were told 1000000); TestPluginModelWindow (Cline's plugin with cline-pass/glm-5.3-flash, cline-free/mimo-v2.6-flash: models.dev's window, then the one set) guards the plugin path, which was already right for agents. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass; model-rate and editor-short-window pass in WebKit. Not tried with the reporter's Cline account; an agent already running keeps the window it started with until it rereads its config.
2026-10-04 13:36:54 +08:00

70 lines
2.4 KiB
Go

package gui
import (
"os"
"path/filepath"
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/provider"
)
// ARNO on Discord (v0.1.815): the window set on a provider's model looked
// not to work, and a model whose id has its vendor's prefix
// (zai/glm-5.3-flash, Cline's cline-free/mimo-v2.6-flash) had none. Agents
// were told both — the catalog's entries take models.dev's window for a
// prefixed id and the user's over it — but the Providers page's model list,
// which the agents' model pickers read too, said only what the vendor's
// list did: nothing, and the same after a window was set. It says the
// window agents are told, and the vendor's own apart (listed).
func TestProviderModelWindowSaid(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][2]int {
t.Helper()
p, err := provider.Find("relay")
if err != nil {
t.Fatal(err)
}
out := map[string][2]int{}
for _, m := range providerInfo(*p, nil).Models {
out[m.ID] = [2]int{m.Context, m.Listed}
}
served := map[string]int{}
for _, e := range provider.Served() {
served[e.Model] = e.Context
}
for id, w := range out {
if served[id] != w[0] {
t.Errorf("%s: the page says %d, agents are told %d", id, w[0], served[id])
}
}
return out
}
if got := said(); got["zai/glm-5.3-flash"] != [2]int{1_000_000, 1_000_000} || got["own-model"] != [2]int{} {
t.Fatalf("before a window is set: %v", got)
}
p, _ := provider.Find("relay")
if err := provider.SetContext(*p, "zai/glm-5.3-flash", 200_000); err != nil {
t.Fatal(err)
}
p, _ = provider.Find("relay")
if err := provider.SetContext(*p, "own-model", 64_000); err != nil {
t.Fatal(err)
}
if got := said(); got["zai/glm-5.3-flash"] != [2]int{200_000, 1_000_000} || got["own-model"] != [2]int{64_000, 0} {
t.Fatalf("set: %v", got)
}
}