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.
96 lines
2.9 KiB
Go
96 lines
2.9 KiB
Go
package gui
|
|
|
|
// #1818: the editor's Select none is saved as noModels with no model
|
|
// picked, kept by a save that doesn't name it, and the card then counts
|
|
// none of the provider's models; a pick clears it.
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
func TestProviderSaveSelectNone(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())
|
|
mux := http.NewServeMux()
|
|
providerRoutes(mux, nil)
|
|
post := func(body string) {
|
|
t.Helper()
|
|
w := httptest.NewRecorder()
|
|
mux.ServeHTTP(w, httptest.NewRequest("POST", "/api/provider/save", strings.NewReader(body)))
|
|
if w.Code != 200 {
|
|
t.Fatalf("%d %s", w.Code, w.Body)
|
|
}
|
|
}
|
|
card := func() (exposed int, none bool) {
|
|
t.Helper()
|
|
w := httptest.NewRecorder()
|
|
mux.ServeHTTP(w, httptest.NewRequest("GET", "/api/providers", nil))
|
|
var got struct {
|
|
Providers []struct {
|
|
ID string `json:"id"`
|
|
Exposed int `json:"exposed"`
|
|
NoModels bool `json:"noModels"`
|
|
} `json:"providers"`
|
|
}
|
|
if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, p := range got.Providers {
|
|
if p.ID == "relay" {
|
|
return p.Exposed, p.NoModels
|
|
}
|
|
}
|
|
t.Fatal("relay not listed")
|
|
return
|
|
}
|
|
|
|
const chat = "http://127.0.0.1:1/v1"
|
|
post(`{"id":"relay","name":"Relay","key":"sk-r","chat":"` + chat + `","new":true}`)
|
|
var ms []catalog.Model
|
|
for i := range 30 {
|
|
ms = append(ms, catalog.Model{ID: fmt.Sprintf("m%d", i)})
|
|
}
|
|
if err := catalog.SaveLive("relay", chat, ms); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if n, none := card(); n != 24 || none {
|
|
t.Fatalf("before: exposed %d none %v", n, none)
|
|
}
|
|
|
|
// the reporter's case: Select none, with and without Only through
|
|
// routing groups
|
|
for _, unlisted := range []string{"false", "true"} {
|
|
post(`{"id":"relay","from":"relay","name":"Relay","key":"","chat":"` + chat + `","models":[],"noModels":true,"unlisted":` + unlisted + `,"headers":{}}`)
|
|
p, _ := provider.Find("relay")
|
|
if !p.NoModels || len(p.Exposed()) != 0 {
|
|
t.Errorf("unlisted=%s: noModels %v exposed %d", unlisted, p.NoModels, len(p.Exposed()))
|
|
}
|
|
if n, none := card(); n != 0 || !none {
|
|
t.Errorf("unlisted=%s card: exposed %d none %v", unlisted, n, none)
|
|
}
|
|
}
|
|
|
|
// a save that doesn't name it (another editor's, the CLI's) keeps it
|
|
post(`{"id":"relay","from":"relay","name":"Relay","key":"","chat":"` + chat + `","headers":{}}`)
|
|
if n, none := card(); n != 0 || !none {
|
|
t.Errorf("not named: exposed %d none %v", n, none)
|
|
}
|
|
|
|
// a pick clears it
|
|
post(`{"id":"relay","from":"relay","name":"Relay","key":"","chat":"` + chat + `","models":["m3"],"noModels":false,"headers":{}}`)
|
|
if n, none := card(); n != 1 || none {
|
|
t.Errorf("picked: exposed %d none %v", n, none)
|
|
}
|
|
}
|