Files
magpie/internal/provider/no_models_test.go
T
yetone 10d60b1899 provider: a provider saved with Select none serves no models, unlisted or not (#1818)
Select none saved `models: []`, which omitempty wrote as no models key at
all, so the provider read back as "no picks" and served the first 24 of
the vendor's list on /v1/models, in auto groups and on the card, while
the editor said none would be served.

What changed:
- Provider.NoModels (json noModels) records the choice; ServesNone() is
  NoModels with no picks. A file with no models key still serves the
  vendor's list as before.
- Exposed() is empty for it, so the catalog, /v1/models and auto groups
  leave it out; resolveIn refuses an explicit pid/model to it; listedBy
  and Deciders skip it (a decide-only provider is still a decider).
- SetModels and normalize clear NoModels once there are picks.
- GUI: the editor sends noModels on Save, an edit that omits it keeps it,
  the card's exposed count is 0, the hint says nothing is served; with
  unlisted the dashed chips explain they are only for groups. Strings in
  en, zh, zh-TW, ja, de.
- CLI: `magpie provider models <id> none`.
- docs/subsystems/providers-accounts.md describes it.

Decision (owner delegated): Select none means none, whether or not
unlisted is on; unlisted keeps meaning "hide from the list, still
usable by groups that name it".

Run:
- go test ./internal/provider ./internal/gui ./internal/cli -count=1
  (green; second pass ran too) with private GOCACHE and sandbox HOME.
- Broke Exposed's ServesNone check: TestSelectNoneServesNone red
  ("exposed 24"); broke resolveIn's: red ("watched/m0 resolved"); broke
  the GUI keep line: TestProviderSaveSelectNone red ("exposed 24").
- GUI tests chromium + webkit, 5 languages: provider-none-picked 20/20,
  provider-draft-picks 10/10 (red with noneChosen broken), plus 12
  related model/group/editor tests green.
- gofmt -l clean; go vet darwin, linux -tags nogui, windows clean for the
  three packages.

Not run: the gateway package; Codex native model narrowing is unchanged.
searcher-pick.test.cjs fails 3 webkit cases (hover timeout) identically
on the unmodified base 556c01c80, unrelated.
2026-10-12 23:45:06 +08:00

106 lines
3.0 KiB
Go

package provider
import (
"fmt"
"strings"
"testing"
"github.com/yetone/magpie/internal/catalog"
)
// #1818: a provider kept only to watch its balance, saved with Select
// none (and Only through routing groups or not), serves none of its
// models: not to agents, not in an auto group, not by its own
// "provider/model" id. Before, with no picks it served the vendor's first
// 24 and joined every auto group.
func TestSelectNoneServesNone(t *testing.T) {
for _, unlisted := range []bool{false, true} {
t.Run(fmt.Sprintf("unlisted=%v", unlisted), func(t *testing.T) {
azureHome(t)
var ms []catalog.Model
for i := range manyModels + 6 {
ms = append(ms, catalog.Model{ID: fmt.Sprintf("m%d", i)})
}
for _, id := range []string{"used", "other", "watched"} {
p := Provider{ID: id, Name: id, Key: "sk-x", Chat: "https://" + id + ".example.invalid/v1"}
if id == "watched" {
p.NoModels, p.Unlisted = true, unlisted
}
if err := Save(p); err != nil {
t.Fatal(err)
}
if err := catalog.SaveLive(id, p.Chat, ms); err != nil {
t.Fatal(err)
}
}
w, err := Find("watched")
if err != nil {
t.Fatal(err)
}
if !w.NoModels || !w.ServesNone() {
t.Fatalf("Select none was not kept: %+v", w)
}
if n := len(w.Exposed()); n != 0 {
t.Errorf("exposed %d, want none", n)
}
for _, e := range Catalog() {
if e.Provider.ID == "watched" {
t.Errorf("catalog has %s", e.ID)
}
}
auto := 0
for _, g := range Groups() {
for _, m := range append(g.Members, g.Matched...) {
if strings.HasPrefix(m, "watched/") {
t.Errorf("group %s has %s", g.ID, m)
}
}
if strings.HasPrefix(g.ID, "auto-") {
auto++
}
}
if auto == 0 { // used and other share every model
t.Error("no auto groups")
}
if _, _, ok := Resolve("watched/m0"); ok {
t.Error("watched/m0 resolved")
}
if p, _, ok := Resolve("used/m0"); !ok || p.ID != "used" {
t.Errorf("used/m0: %v %v", p.ID, ok)
}
// a pick clears it
if err := SetModels("watched", []string{"m3"}); err != nil {
t.Fatal(err)
}
w, _ = Find("watched")
if w.NoModels || w.ServesNone() || len(w.Exposed()) != 1 {
t.Errorf("a pick after Select none: %+v exposed %d", w.NoModels, len(w.Exposed()))
}
})
}
}
// A providers.json from before #1818 has no models key: the vendor's
// list is served as ever, up to manyModels.
func TestNoPicksStillServesTheVendorList(t *testing.T) {
azureHome(t)
var ms []catalog.Model
for i := range manyModels + 6 {
ms = append(ms, catalog.Model{ID: fmt.Sprintf("m%d", i)})
}
p := Provider{ID: "old", Name: "old", Key: "sk-x", Chat: "https://old.example.invalid/v1"}
if err := Save(p); err != nil {
t.Fatal(err)
}
if err := catalog.SaveLive("old", p.Chat, ms); err != nil {
t.Fatal(err)
}
got, err := Find("old")
if err != nil {
t.Fatal(err)
}
if got.NoModels || len(got.Exposed()) != manyModels {
t.Errorf("noModels %v exposed %d, want %d", got.NoModels, len(got.Exposed()), manyModels)
}
}