Files
magpie/internal/gateway/draw_group_pick_test.go
T
yetone d9cf85ae8b images: a routing group can be Settings > Images' image model (7up6666 on X)
Settings > Images > Image generation now offers each routing group with
a member that draws (gateway.GroupDraws: a member among its provider's
Drawers), with no provider of its own, so the picker puts it under
Routing groups as the Image recognition picker does. Picked, "group/<id>"
is what a request naming no model draws with, the Magpie Image MCP's
included: the gateway already drew on a group member by member in its
routing's order (drawingGroup, #2005), it was only never offered.

A picked group none of whose members draws any more (all removed, or a
group of chat models) is DrawerMissing (drawerMissing): the row says the
pick is missing and Automatic draws in its place, as for a removed model.
Before, a group of chat models would have been sent the drawing.
ListedDrawer and DrawerHidden leave a group ref as it is.

Run:
- mote, at this change on e84f40369: gofmt -l, go vet ./...,
  GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./..., the
  Linux and Windows builds: ok. go test -count=1 -run
  "Draw|Drawer|Image|Budget|HiddenDrawers|Account|Aside" over
  internal/provider, gateway, gui and agent: all four ok (the new tests,
  TestImageGroupMovesOnToTheNextMember and the size budgets among them).
- wsl-run, Chromium and WebKit: the seven image GUI files 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.

New tests: TestImageGroupPickedInSettingsDraws (gateway: the group
pick draws with no model named, over HTTP and through the Magpie Image
MCP, moving past a member's 502; a chat-only group and one whose drawers
are gone are missing), TestImageGenOffersDrawingGroups (gui).

Broken by hand:
- drawerMissing without the GroupDraws check: the gateway test is red
  ("chat-only group: drawer \"group/talkers\" missing \"\"").
- api.go without the group loop: the gui test is red (group not offered).

Not tried: a real group of real image accounts; a GUI test (app.js is
unchanged: its picker already files an entry with no provider under
Routing groups); the real Linux app.
2026-10-29 15:50:37 +08:00

99 lines
3.7 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 gateway
import (
"io"
"net/http"
"net/http/httptest"
"strings"
"sync/atomic"
"testing"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/settings"
)
// 7up6666 on X: a routing group of image models, picked in Settings ›
// Images, is what a request naming no model draws with, the Magpie Image
// MCP's included: on its members in its routing's order, the next asked
// while one fails. A group with no member that draws is no pick (it shows
// as missing, and Automatic draws in its place), nor is one whose members
// are all gone.
func TestImageGroupPickedInSettingsDraws(t *testing.T) {
s, e := easeled(t)
t.Setenv("MAGPIE_PUBLIC_URL", "")
t.Cleanup(s.imageStore.running.Wait)
var brokeAsked atomic.Int32
broke := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
brokeAsked.Add(1)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(502)
io.WriteString(w, `{"error":{"message":"upstream error: bad gateway","type":"upstream_error"}}`)
}))
t.Cleanup(broke.Close)
if err := provider.Save(provider.Provider{ID: "flare-a", Name: "Flare A", Chat: broke.URL + "/v1", Key: "ka", Models: []string{"gpt-image-2.5-flare"}}); err != nil {
t.Fatal(err)
}
art, _ := provider.Find("art")
art.Models = append(art.Models, "gpt-image-2.5-flare")
if err := provider.Save(*art); err != nil {
t.Fatal(err)
}
for _, g := range []provider.Group{
{ID: "painters", Name: "Painters", Members: []string{"flare-a/gpt-image-2.5-flare", "art/gpt-image-2.5-flare"}, Routing: "order"},
{ID: "talkers", Name: "Talkers", Members: []string{"art/text"}},
} {
if err := provider.SaveGroup(g); err != nil {
t.Fatal(err)
}
}
if !GroupDraws("group/painters") || GroupDraws("group/talkers") || GroupDraws("group/nope") {
t.Fatal("GroupDraws")
}
if ListedDrawer("group/painters") != "group/painters" || DrawerHidden("group/painters") {
t.Fatal("a group pick is listed as it is, and never hidden")
}
pick := func(v string) {
t.Helper()
st := settings.Load()
st.ImageGen = v
if err := settings.Save(st); err != nil {
t.Fatal(err)
}
}
pick("group/painters")
if Drawer() != "group/painters" || DrawerMissing() != "" {
t.Fatalf("the group pick isn't what draws: %q missing %q", Drawer(), DrawerMissing())
}
code, a, raw := postImages(t, s, "/v1/images/generations", "application/json", `{"prompt":"a magpie"}`)
if code != 200 || len(a.Data) != 1 || a.Model != "art/gpt-image-2.5-flare" || brokeAsked.Load() == 0 {
t.Fatalf("drawn with no model named: %d %s (first member asked %d)", code, raw, brokeAsked.Load())
}
// the MCP draws with the pick too
h := lanGuard(s.Handler())
before := len(e.got("/v1/images/generations"))
m := readImageReply(t, imagePost(h, "127.0.0.1:5000", imageToolCall(GenerateImageTool, map[string]any{"prompt": "a magpie"})))
if m.Result.IsError || len(e.got("/v1/images/generations")) != before+1 || !strings.Contains(m.Result.Content[0].Text, "art/gpt-image-2.5-flare") {
t.Fatalf("MCP: %+v", m)
}
// a group that draws nothing is said missing, and Automatic draws
pick("group/talkers")
if DrawerMissing() != "group/talkers" || Drawer() == "group/talkers" || Drawer() == "" {
t.Fatalf("chat-only group: drawer %q missing %q", Drawer(), DrawerMissing())
}
// as is one whose drawing members are all gone
pick("group/painters")
if err := provider.Delete("flare-a"); err != nil {
t.Fatal(err)
}
art, _ = provider.Find("art")
art.Models = []string{"text"}
if err := provider.Save(*art); err != nil {
t.Fatal(err)
}
if DrawerMissing() != "group/painters" || Drawer() == "group/painters" {
t.Fatalf("group with no drawers left: drawer %q missing %q", Drawer(), DrawerMissing())
}
}