Files
magpie/internal/gui/image_hidden_test.go
T
yetone ded4935745 providers: an image model can be unticked in its provider's editor, and leaves the lists (321sssrt on X)
A provider's editor lists its image models as chips under "Image models"
("图像模型"); a click unticks one, and Save keeps it as the provider's
HiddenDrawers, a deny list beside the Models allow list. An unticked
model leaves Settings > Images' picker, Automatic's choice (and so the
Magpie Image MCP's when nothing is picked), the gateway's /v1/models
image entries and Aside's image options (gateway.OfferedDrawers).

A hidden model still draws when a request names it (resolveDrawing reads
Drawers), and a Settings > Images pick made before it was hidden stays
the pick: it is still listed, as picked, and the row says it is unticked
in its provider and leaves the list once another is picked
(ImageGenHidden), so a pick never stops drawing in silence. A Save that
leaves hiddenDrawers out keeps them; [] clears them. Strings in en, zh,
zh-TW, ja, de. docs/subsystems/gateway-routing.md has the section.

Run, at this and the next commit on e84f40369:
- mote: gofmt -l (none); go vet ./...; GOOS=linux go vet -tags nogui
  ./...; GOOS=windows go vet ./...; GOOS=linux go build -tags nogui;
  GOOS=windows go build: ok. go test -count=1 -run
  "Draw|Drawer|Image|Budget|HiddenDrawers|Account|Aside" over
  internal/provider, gateway, gui and agent: all four ok.
- wsl-run (magpie-desktop, Playwright 1.62.0), Chromium and WebKit:
  image-models-hide (new: en, zh, zh-TW, ja, de at 1000px and 360px),
  images-missing, images-codex-one, image-mcp, image-timeout-setting,
  images-library-way and i18n-keys: 182 of 182.
- Rebased again onto 4d9058a98 (which changed app.js, api.go and
  i18n.js, "Picked only" among them) and run there: go vet
  ./internal/gui and go test -run "Budget|Image|Drawer" ./internal/gui
  ok; wsl-run, both engines: image-models-hide,
  provider-picked-only-shows-picks, images-missing and i18n-keys, 90 of 90.
  Pushed on 0366e35c1, which changes only internal/catalog after it.
Before the rebase (on e15b2277c): the same vet and builds ok, and the
four packages whole with -timeout 45m: internal/provider ok (1061s);
gateway, gui and agent were still running on a loaded mote when this
was pushed (the owner's rule: no commit held behind a full suite).
- New tests: TestHiddenDrawerLeavesListsButStillDraws (gateway),
  TestImageModelsHidden (gui), the HiddenDrawers round-trip in
  account_test.go.

Broken by hand:
- OfferedDrawers returning every drawer: the gateway test is red
  ("offered [gpt-image-hidden gpt-image-shown]").
- The GUI test against the old app.js, api.go, draw.go and i18n.js:
  21 of 26 red.

Not tried: real accounts; a full ./... run (mote at load 200 to 300);
the GUI run on mote (its Chromium crashed under that load, so the GUI
ran on WSL); the real Linux app.
2026-10-29 15:50:37 +08:00

96 lines
2.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package gui
import (
"net/http"
"net/http/httptest"
"os"
"slices"
"strings"
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/settings"
)
// 321sssrt on X: image models unticked in a provider's editor are saved
// as HiddenDrawers, kept by a Save that leaves them out and cleared by [];
// Settings › Images leaves them out, except the one picked there, which
// stays listed as picked with the row saying it is hidden.
func TestImageModelsHidden(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.String())
}
}
const base = `"id":"pics","name":"Pics","key":"sk-p","chat":"https://pics.example/v1","icon":"generic"`
post(`{` + base + `,"new":true}`)
if err := catalog.SaveLive("pics", "https://pics.example/v1", []catalog.Model{{ID: "text"}, {ID: "img-a", Draws: true}, {ID: "img-b", Draws: true}}); err != nil {
t.Fatal(err)
}
hidden := func() []string {
t.Helper()
p, err := provider.Find("pics")
if err != nil {
t.Fatal(err)
}
info := providerInfo(*p, nil)
if !slices.Equal(info.HiddenDrawers, p.HiddenDrawers) {
t.Fatalf("the editor is shown %v, saved %v", info.HiddenDrawers, p.HiddenDrawers)
}
return p.HiddenDrawers
}
listed := func() (ids []string) {
for _, m := range settingsState().ImageGenModels {
if m.Provider == "pics" {
ids = append(ids, m.ID)
}
}
return
}
post(`{` + base + `,"from":"pics","models":[],"headers":{},"hiddenDrawers":["img-a"]}`)
if got := hidden(); !slices.Equal(got, []string{"img-a"}) {
t.Fatalf("saved %v", got)
}
if got := listed(); !slices.Equal(got, []string{"pics/img-b"}) {
t.Fatalf("Settings › Images lists %v", got)
}
if settingsState().ImageGenHidden {
t.Fatal("hidden note with nothing hidden picked")
}
st := settings.Load()
st.ImageGen = "pics/img-a"
if err := settings.Save(st); err != nil {
t.Fatal(err)
}
if got := listed(); !slices.Equal(got, []string{"pics/img-a", "pics/img-b"}) {
t.Fatalf("a hidden pick isn't listed as picked: %v", got)
}
if !settingsState().ImageGenHidden {
t.Fatal("a hidden pick isn't said to be hidden")
}
post(`{` + base + `,"from":"pics","models":[],"headers":{}}`)
if got := hidden(); !slices.Equal(got, []string{"img-a"}) {
t.Fatalf("a Save that left them out changed them: %v", got)
}
post(`{` + base + `,"from":"pics","models":[],"headers":{},"hiddenDrawers":[]}`)
if got := hidden(); len(got) != 0 {
t.Fatalf("[] kept %v", got)
}
if settingsState().ImageGenHidden {
t.Fatal("ticked again, still said to be hidden")
}
}