settings.hiddenModels had no "zcode", and ZCode's ~/.zcode/v2/config.json and provider_config.json listed every model. The files magpie writes for ZCode already leave out what is hidden for it (magpieModels(id) reads provider.CatalogFor), but its row had no list to hide one in: ZCode's only field puts magpie in its own picker, with no option among the catalog, and the Agents page gives a models line and menu only to an agent that has one (takesCatalog) or ListsModels (Cursor Private Inference). Audit of every agent row: each agent with a field among the catalog (viaMagpie) already had the list. Those whose only field puts magpie's models in their own picker had none: zcode, pencil, t3code, workbuddy, workbuddy-ai and copilot-jetbrains. They now set ListsModels; Claude Desktop's tier pickers list the catalog once connected, and cursor-local had it already. - agent: ListsModels on those six, its doc says when it applies. - gui/api.go: the row's JSON says menu (ListsModels), so app.js gives it the models button as it does Claude Desktop's and Cursor's, rather than a hard-coded set of ids. Tests: - TestEveryPickerOfMagpiesModelsCanBeNarrowed: any built-in agent that puts magpie in a picker with no option among the catalog and no ListsModels fails, so a new agent can't miss it. - TestZCodeListsOnlyThePicked: from a config the user edited by hand (own providers, theme, rules, a manual rule for one of magpie's models, ui lang), hiding one model takes it out of both files at the next sync and showing it puts it back; the user's entries stay at every step. - TestZCodeModelList: through the GUI handlers: connect, the row has menu and 2/2, hide one, settings.hiddenModels.zcode is set, the row reads 1/2, and after SyncCatalog both files list only the other. - tests/zcode-models.test.cjs: ZCode's row in en, zh, zh-TW, ja, de, in the window (1100px) and the tray panel (420px), Chromium and WebKit: the line, the menu button, unticking one posts it and the count drops, ticking it back; no scroll, no <select>, no overflow. 20/20. Without ZCode's ListsModels, the first and third fail (tried); without a.menu in app.js, all 20 GUI cases fail (tried). All in a sandbox HOME; the live ~/.zcode was never touched. Run: go test -tags nogui ./internal/agent ./internal/gui; gofmt -l; GOOS=linux and GOOS=windows go vet -tags nogui ./internal/agent ./internal/gui; node --test on zcode-models, agent-model*, agent-models-*, agent-notice-lang, click-scroll, cursor-local-*, gui-de/ja/zh-tw and i18n-keys, both engines: all pass (three load timeouts under a machine load of ~140 passed rerun alone). go test -tags nogui -timeout 40m ./... on the rebased tree: every package ok but internal/gateway, whose TestQueuedStreamKeptAliveForTheMinute hit its 1.5s read deadline at a machine load of ~130; it passes -count=3 run alone, and this change touches nothing it runs.
106 lines
3.3 KiB
Go
106 lines
3.3 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/agent"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// ZCode's row picks which of magpie's models its picker lists, as every
|
|
// other agent's does (#1508, NovaTrailX: settings.hiddenModels had no
|
|
// zcode, and both its files got every model). Through the page's own
|
|
// handlers: its row has the line and the menu, the list takes one out, the
|
|
// row counts one fewer, and the files magpie writes for it leave it out.
|
|
func TestZCodeModelList(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"))
|
|
if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"m1", "m2"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
dir := filepath.Join(home, ".zcode", "v2")
|
|
os.MkdirAll(dir, 0o755)
|
|
os.WriteFile(filepath.Join(dir, "config.json"), []byte(`{"provider":{"mine":{"name":"Mine","kind":"openai"}}}`), 0o644)
|
|
h := Handler(nil, nil)
|
|
call := func(path, body string, out any) {
|
|
t.Helper()
|
|
method := "POST"
|
|
if body == "" {
|
|
method = "GET"
|
|
}
|
|
rec := httptest.NewRecorder()
|
|
h.ServeHTTP(rec, httptest.NewRequest(method, path, strings.NewReader(body)))
|
|
if rec.Code != 200 {
|
|
t.Fatalf("%s %d %s", path, rec.Code, rec.Body)
|
|
}
|
|
json.Unmarshal(rec.Body.Bytes(), out)
|
|
}
|
|
row := func() agentJSON {
|
|
var s stateJSON
|
|
call("/api/state", "", &s)
|
|
for _, a := range s.Agents {
|
|
if a.ID == "zcode" {
|
|
return a
|
|
}
|
|
}
|
|
t.Fatalf("no zcode in %+v", s.Agents)
|
|
return agentJSON{}
|
|
}
|
|
var s stateJSON
|
|
call("/api/agents/connect/zcode", "{}", &s)
|
|
r := row()
|
|
if !r.Wired || !r.Menu || r.Models == nil || r.Models.Shown != 2 || r.Models.Listed != 2 {
|
|
t.Fatalf("connected, its row: wired %v, menu %v, models %+v", r.Wired, r.Menu, r.Models)
|
|
}
|
|
var list struct {
|
|
Models []agentModelJSON
|
|
Count *modelCountJSON
|
|
}
|
|
call("/api/agent-models/zcode", "", &list)
|
|
if len(list.Models) != 2 {
|
|
t.Fatalf("its list: %+v", list.Models)
|
|
}
|
|
call("/api/agent-models/zcode", `{"hidden":["relay/m2"]}`, &list)
|
|
if list.Count == nil || list.Count.Shown != 1 {
|
|
t.Fatalf("one taken out: %+v", list.Count)
|
|
}
|
|
if got := provider.HiddenModels("zcode"); !got["relay/m2"] || len(got) != 1 {
|
|
t.Fatalf("settings.hiddenModels.zcode: %v", got)
|
|
}
|
|
if r := row(); r.Models == nil || r.Models.Shown != 1 || r.Models.Listed != 2 {
|
|
t.Fatalf("its row after: %+v", r.Models)
|
|
}
|
|
// what a change to the catalog runs (catalog.Changed)
|
|
agent.SyncCatalog()
|
|
var c struct {
|
|
Provider map[string]struct {
|
|
Models map[string]any `json:"models"`
|
|
} `json:"provider"`
|
|
}
|
|
b, _ := os.ReadFile(filepath.Join(dir, "config.json"))
|
|
json.Unmarshal(b, &c)
|
|
if _, ok := c.Provider["mine"]; !ok {
|
|
t.Fatalf("the user's own provider went: %s", b)
|
|
}
|
|
var ids []string
|
|
for id := range c.Provider["magpie"].Models {
|
|
ids = append(ids, id)
|
|
}
|
|
if !slices.Equal(ids, []string{"relay/m1"}) {
|
|
t.Fatalf("config.json lists %v", ids)
|
|
}
|
|
b, _ = os.ReadFile(filepath.Join(dir, "provider_config.json"))
|
|
if !strings.Contains(string(b), `"personalModelIds":["relay/m1"]`) {
|
|
t.Fatalf("provider_config.json: %s", b)
|
|
}
|
|
}
|