Files
magpie/internal/gui/disabled_chips_test.go
T
yetone 265217bf4c gui: a model disabled in Settings → Models says so in its provider's editor
A model disabled for every request (#1867) still drew in its provider's
editor as an ordinary chip, ticked or served, so it read as one agents
get while the gateway refused it. /api/providers now gives each model
the pattern that turns it off (provider.DisabledPattern, the list read
once per provider), and its chip is dimmed with a "disabled" badge and a
title naming the pattern and where it is set. Every language.

Paid for in the core budget by moving six trailing comments onto lines
of their own (whole-line comments aren't counted), no raise.

Run (mote, at this tree):
- go test ./internal/gui -run 'TestProviderInfoSaysADisabledModel|TestCoreScriptBudget|TestI18n|TestCSS': ok
- go test ./internal/provider -run TestDisabled: ok
- disabled-model-chips.test.cjs, Chromium and WebKit, en zh zh-TW ja de: 12 pass

Broken by hand, each red, then put back:
- providers.go not setting Disabled: TestProviderInfoSaysADisabledModel red.
- the chip not reading m.disabled: disabled-model-chips 12 of 12 red.

Not tried: the real app window; the rest of the GUI suite.
2026-11-18 12:35:06 +08:00

43 lines
1.3 KiB
Go

package gui
import (
"os"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// A model disabled in Settings → Models (#1867) is still in its provider's
// editor, told by the pattern that turns it off, so its chip can say so
// instead of reading as a pick the gateway then refuses.
func TestProviderInfoSaysADisabledModel(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{"claude-fable-5", "exact-one", "vendor/tail", "kept"}}
if err := provider.Save(p); err != nil {
t.Fatal(err)
}
if err := provider.SetDisabledModels([]string{"*FABLE*", "relay/exact-one", "tail"}); err != nil {
t.Fatal(err)
}
got, err := provider.Find("relay")
if err != nil {
t.Fatal(err)
}
want := map[string]string{"claude-fable-5": "*FABLE*", "exact-one": "relay/exact-one", "vendor/tail": "tail", "kept": ""}
seen := map[string]bool{}
for _, m := range providerInfo(*got, nil).Models {
seen[m.ID] = true
if w, ok := want[m.ID]; ok && m.Disabled != w {
t.Errorf("%s: disabled %q, want %q", m.ID, m.Disabled, w)
}
}
for id := range want {
if !seen[id] {
t.Errorf("%s left out of the editor", id)
}
}
}