Files
magpie/internal/gui/image_gen_codex_test.go
T
yetone 2d6939ec64 gateway: Automatic draws with the newest GPT Image, and a ChatGPT account's shows as GPT Image (StarBits on X)
StarBits asked on X whether magpie draws with OpenAI's newest image model,
as the editor showed "gpt-image-2".

- AutoDrawer took the cheapest priced model. An OpenAI key lists
  gpt-image-2.5/2.6 with no price (models.dev prices gpt-image-2 only), so
  Automatic kept an older GPT Image. Now a GPT Image that a newer one set
  up supersedes is never picked (gptImageGenOf: version, then
  base/Sunburst > Flare > mini; dall-e and chatgpt-image-latest under all),
  and an unpriced one is costed as the newest priced one. Another kind of
  model that costs less still wins.
- A ChatGPT (Codex) account's backend ignores the model name (#1865;
  re-checked today with a real account: gpt-image-2, 2.6-sunburst,
  2.5-flare and a bogus id all drew the same 1536x1024 image), so it is
  never superseded, and its chip now reads its name "GPT Image" with the
  id as tooltip (/api/providers drawNames). Unticking still saves the id.
- docs/subsystems/gateway-routing.md says both.

Run (on mote, at this tree):
- go test -tags nogui -run 'AutoDrawer|GPTImageGen|Codex.*Image|ImageGen|Drawer|Draw'
  ./internal/gateway ./internal/gui: ok
- GUI: chatgpt-image-chip (new), image-models-hide, video-models-hide,
  group-pick-drawers, chromium + webkit, en/zh/zh-TW/ja/de, 1000 and
  360px: 100 pass, 0 fail
- gofmt -l: clean
- Full go test ./... -timeout 45m and Linux/Windows vet: running; record
  follows in the next commit or a comment.

Broken by hand: without the supersede filter TestAutoDrawerTakesNewestGPTImage
picks oa/dall-e-3; without the ChatGPT exclusion TestAutoDrawerKeepsChatGPTsOwnPick
picks oa/gpt-image-2.6-sunburst; with the chip label reverted the GUI test
is red.

Not tried: a real OpenAI key's live model list in the app.
2026-11-05 19:56:08 +08:00

77 lines
2.6 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 (
"encoding/base64"
"encoding/json"
"os"
"path/filepath"
"testing"
"time"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/settings"
)
// #1865: Settings › Images lists a ChatGPT account's one GPT Image, marked
// as the vendor's pick, and a gpt-image-2.5 saved when it was listed shows
// as that entry while the saved value is kept as it is.
func TestImageGenCodexOneEntry(t *testing.T) {
h := t.TempDir()
t.Setenv("HOME", h)
t.Setenv("USERPROFILE", h)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
t.Setenv("CODEX_HOME", "")
claims := func(m map[string]any) string {
b, _ := json.Marshal(m)
return "h." + base64.RawURLEncoding.EncodeToString(b) + ".s"
}
auth, _ := json.Marshal(map[string]any{"auth_mode": "chatgpt", "tokens": map[string]any{
"id_token": claims(map[string]any{"email": "me@example.com"}),
"access_token": claims(map[string]any{"exp": time.Now().Add(time.Hour).Unix()}),
"refresh_token": "r", "account_id": "acct-1"}})
os.MkdirAll(filepath.Join(h, ".codex"), 0o755)
if err := os.WriteFile(filepath.Join(h, ".codex", "auth.json"), auth, 0o600); err != nil {
t.Fatal(err)
}
provider.ForgetAccounts()
t.Cleanup(provider.ForgetAccounts)
st := settings.Load()
st.ImageGen = "codex/gpt-image-2.5"
if err := settings.Save(st); err != nil {
t.Fatal(err)
}
s := settingsState()
var codex []modelRef
for _, m := range s.ImageGenModels {
if m.Provider == "codex" {
codex = append(codex, m)
}
}
if len(codex) != 1 || codex[0].ID != "codex/gpt-image-2" || codex[0].Name != "GPT Image" || !codex[0].VendorPicks {
t.Fatalf("codex image models %+v", codex)
}
if s.ImageGen != "codex/gpt-image-2.5" || s.ImageGenShown != "codex/gpt-image-2" || s.ImageGenMissing != "" {
t.Fatalf("imageGen %q shown %q missing %q", s.ImageGen, s.ImageGenShown, s.ImageGenMissing)
}
st.ImageGen = "codex/gpt-image-2"
if err := settings.Save(st); err != nil {
t.Fatal(err)
}
if s := settingsState(); s.ImageGenShown != "" {
t.Fatalf("a listed pick is shown as %q", s.ImageGenShown)
}
// its editor's Image models says why it lists one (ChangQiu on
// Discord looked there for gpt-image-2.5)
p, err := provider.Find("codex")
if err != nil {
t.Fatal(err)
}
if j := providerInfo(*p, nil); !j.DrawPicks || len(j.DrawIDs) != 1 {
t.Fatalf("editor's drawIds %v, drawPicks %v", j.DrawIDs, j.DrawPicks)
} else if j.DrawNames[j.DrawIDs[0]] != "GPT Image" {
// StarBits on X read the chip's gpt-image-2 as an old model
t.Fatalf("editor shows %q by %v", j.DrawIDs[0], j.DrawNames)
}
}