Files
magpie/internal/gui/agent_hides_test.go
T
yetone 53a2e385e7 providers: the editor says which agent's own list leaves a ticked model out
Kylin_Cloud on X reported that after hiding single models in an agent's model
list on the Agents page, the provider's editor still showed every model ticked,
as if the change hadn't synced. These are two different settings. The editor's
picks apply to every agent, while an agent's own list (HiddenModels, or
PickedModels in "only" mode) can still leave a model out. Showing both as one
tick hid the second.

The editor now shows the truth without merging the two settings:
- /api/providers gives each agent's `hides`: the provider's models that the
  agent's list leaves out (provider.ModelOff). They are read once per shared
  list (a WSL copy or an omp profile is not told twice), and only for agents
  whose list leaves something out.
- Under the models, one line per agent: "Codex's model list leaves out beta:
  shown again from there, on the Agents page." The chip's title says the same.
- With "Only through routing groups" ticked, no agent lists the models, so no
  line appears. A picked chip's title says the routing groups use it and agents
  don't see it.

No layout change: the line is a hint, like the "in no routing group" hint
beside it. It has no left border. Strings are in zh, zh-TW, ja and de.

Run:
- gofmt -l: clean. go vet -tags nogui for darwin, linux and windows
  (internal/gui, internal/provider) on mote: ok.
- TestProviderInfoSaysAnAgentsHiddenModels (new) on mote: ok.
- agent-hides-editor.test.cjs (new), en/zh/zh-TW/ja/de at 1000px and 420px:
  - Chromium on mote: 10/10.
  - WebKit on mote: 10/10 timed out at launch (#4125). WebKit on the Windows
    box (win-run): 10/10.
- The full Go suite and the whole GUI suite were run at the head after the next
  commit; see its body.

Broken by hand:
- With drawHiders() left out of draw(), the GUI test was red 10/10 (Chromium).
- With providerInfo's hides never filled, the Go test was red ("Codex leaves
  out relay's b ...: map[]").

Not tried: the real app with a real agent's hidden models. Only fixtures and a
sandbox HOME were used.
2026-10-30 18:03:55 +08:00

63 lines
2.1 KiB
Go

package gui
import (
"os"
"slices"
"testing"
"github.com/yetone/magpie/internal/agent"
"github.com/yetone/magpie/internal/provider"
)
// Kylin_Cloud on X: models left out of an agent's own list on the Agents
// page looked ticked in the provider's editor, as if the two were one
// setting. They are two (the picks are every agent's), so the editor is
// told, by agent, which of the provider's models each list leaves out.
// A WSL copy of the agent shares its list and is told once.
func TestProviderInfoSaysAnAgentsHiddenModels(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Setenv("USERPROFILE", os.Getenv("HOME"))
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
t.Setenv("XDG_CACHE_HOME", t.TempDir())
p := provider.Provider{ID: "relay", Name: "Relay", Chat: "http://127.0.0.1:1/v1", Key: "key", Models: []string{"a", "b", "c"}}
if err := provider.Save(p); err != nil {
t.Fatal(err)
}
got, err := provider.Find("relay")
if err != nil {
t.Fatal(err)
}
codex := &agent.Agent{ID: "codex", Name: "Codex", Bin: "codex"}
wsl := &agent.Agent{ID: "codex@wsl:Ubuntu", Name: "Codex (WSL)", Bin: "codex"}
claude := &agent.Agent{ID: "claude", Name: "Claude Code", Bin: "claude"}
agents := []*agent.Agent{codex, wsl, claude}
hides := func() map[string][]string {
t.Helper()
out := map[string][]string{}
for _, a := range providerInfo(*got, agentUses(agents, provider.GroupFinder())).Agents {
if a.Hides != nil {
out[a.ID] = a.Hides
}
}
return out
}
if h := hides(); len(h) != 0 {
t.Fatalf("nothing is hidden yet: %v", h)
}
if err := provider.SetHiddenModels("codex", []string{"relay/b", "other/b"}); err != nil {
t.Fatal(err)
}
if h := hides(); len(h) != 1 || !slices.Equal(h["codex"], []string{"b"}) {
t.Fatalf("Codex leaves out relay's b, told once: %v", h)
}
if err := provider.SetOnlyPicked("claude", true); err != nil {
t.Fatal(err)
}
if err := provider.SetPickedModels("claude", []string{"relay/a"}); err != nil {
t.Fatal(err)
}
if h := hides(); !slices.Equal(slices.Sorted(slices.Values(h["claude"])), []string{"b", "c"}) {
t.Fatalf("Claude Code's list picks only a: %v", h)
}
}