DeepSeek Harness offers its own DeepSeek models beside magpie's in its
model picker, and nothing in magpie could leave them out: `magpie visible`
and the model list only cover magpie's catalog. An agent's model list now
has a switch at the top, "Show {agent}'s own models", for an agent that
has models of its own. Off, its picker offers magpie's alone.
- settings.OwnModelsHidden lists the agents whose own models are left
out. provider.OwnModelsHidden / SetOwnModelsHidden read and write it.
POST /api/settings keeps it: the Settings page doesn't send it.
- agent.Picks(f, cur) is a field's options without the agent's own
(no Ref, a value). It leaves them in when the field has no magpie
option at all, and always keeps the value the agent is set to now, so
the user's own choice isn't dropped or rewritten. The GUI's agent
fields and the TUI picker read it. The CLI still sets an own model by
name.
- GET /api/agent-models/{id} says `own` and `ownHidden`. POST
{ownHidden} sets it. The GUI's switch rolls back if the save fails,
and closing the list filters the picker at once, before the state is
read again. The order view (magpie's models alone) hides the switch.
- Strings in zh, zh-TW, ja, de.
Run: go test ./internal/agent ./internal/provider ./internal/settings
./internal/tui, all green. go test ./internal/gui is green apart from
TestTrayCellClickReleasedPanel, which fails the same alone on
origin/main ee20a1511 (#1661). The new TestAgentOwnModelsHidden goes red
with Picks returning every option. The GUI suites agent-*, gui-*, i18n-*
and settings-* pass 424/424. The new agent-models-own.test.cjs runs in
Chromium and WebKit, en/zh/de/ja, at 420 and 1100 wide, and goes red with
the close-time filter taken out. gofmt is clean, and linux and windows
vet are clean (gui on windows only).
Not tried: the real dsh in the live GUI.
114 lines
3.5 KiB
Go
114 lines
3.5 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/agent"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// DeepSeek Harness's own DeepSeek models, beside magpie's in its picker,
|
|
// can be left out (MizuIro-H, #1642): the agent's model list has a switch
|
|
// for them, its pickers then offer magpie's alone, the model it is set to
|
|
// stays, and another agent's pickers are as they were.
|
|
func TestAgentOwnModelsHidden(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("USERPROFILE", home)
|
|
t.Setenv("DSH_HOME", "")
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
|
|
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
|
|
t.Setenv("CODEX_HOME", filepath.Join(home, ".codex"))
|
|
os.MkdirAll(filepath.Join(home, ".dsh"), 0o755)
|
|
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)
|
|
}
|
|
mux := http.NewServeMux()
|
|
agentModelsAPI(mux)
|
|
call := func(method, body string) (out struct {
|
|
Own, OwnHidden bool
|
|
}) {
|
|
t.Helper()
|
|
w := httptest.NewRecorder()
|
|
mux.ServeHTTP(w, httptest.NewRequest(method, "/api/agent-models/dsh", strings.NewReader(body)))
|
|
if w.Code != 200 {
|
|
t.Fatalf("%s %d %s", method, w.Code, w.Body)
|
|
}
|
|
json.Unmarshal(w.Body.Bytes(), &out)
|
|
return out
|
|
}
|
|
dsh, err := agent.Find("dsh")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
values := func(a *agent.Agent, vals map[string]string) (own, magpie []string) {
|
|
for _, f := range agentFields(a, vals) {
|
|
if f.Key != "model" {
|
|
continue
|
|
}
|
|
for _, o := range f.Options {
|
|
if o.Ref != "" {
|
|
magpie = append(magpie, o.Value)
|
|
} else {
|
|
own = append(own, o.Value)
|
|
}
|
|
}
|
|
}
|
|
return own, magpie
|
|
}
|
|
all := []string{"deepseek-flash", "deepseek-v4-pro", "deepseek-v4-flash"}
|
|
|
|
if got := call("GET", ""); !got.Own || got.OwnHidden {
|
|
t.Fatalf("dsh's list: %+v, want its own models there and shown", got)
|
|
}
|
|
if own, magpie := values(dsh, map[string]string{}); !slices.Equal(own, all) || len(magpie) == 0 {
|
|
t.Fatalf("before: own %v, magpie's %v", own, magpie)
|
|
}
|
|
|
|
if got := call("POST", `{"ownHidden":true}`); !got.OwnHidden {
|
|
t.Fatalf("answered %+v", got)
|
|
}
|
|
if s := settings.Load().OwnModelsHidden; !slices.Equal(s, []string{"dsh"}) {
|
|
t.Fatalf("saved %v", s)
|
|
}
|
|
if got := call("GET", ""); !got.Own || !got.OwnHidden {
|
|
t.Fatalf("dsh's list after: %+v", got)
|
|
}
|
|
own, magpie := values(dsh, map[string]string{})
|
|
if len(own) != 0 || !slices.Contains(magpie, "magpie/relay/m1") {
|
|
t.Fatalf("hidden: own %v left, magpie's %v", own, magpie)
|
|
}
|
|
// the one it is set to stays, the others go
|
|
if own, _ := values(dsh, map[string]string{"model": "deepseek-v4-pro"}); !slices.Equal(own, []string{"deepseek-v4-pro"}) {
|
|
t.Fatalf("set to deepseek-v4-pro: own %v", own)
|
|
}
|
|
// another agent's pickers are as they were
|
|
if provider.OwnModelsHidden("codex") {
|
|
t.Fatal("codex hides its own too")
|
|
}
|
|
// the effort field, not a picker of magpie's models, keeps every level
|
|
for _, f := range agentFields(dsh, map[string]string{}) {
|
|
if f.Key == "effort" && len(f.Options) == 0 {
|
|
t.Fatal("effort lost its levels")
|
|
}
|
|
}
|
|
|
|
if got := call("POST", `{"ownHidden":false}`); got.OwnHidden {
|
|
t.Fatalf("answered %+v", got)
|
|
}
|
|
if own, _ := values(dsh, map[string]string{}); !slices.Equal(own, all) {
|
|
t.Fatalf("shown again: own %v", own)
|
|
}
|
|
if s := settings.Load().OwnModelsHidden; len(s) != 0 {
|
|
t.Fatalf("saved %v", s)
|
|
}
|
|
}
|