Files
magpie/internal/provider/codex_drawtest_test.go
T
yetone 7c5c90f958 provider: a ChatGPT account's GPT Image is tested by drawing, as the gateway draws it (ChangQiu on Discord)
ChangQiu added gpt-image-2.5 to a ChatGPT (Codex) subscription, and the
editor's Test failed. The Test asked every model as a chat on the Codex
backend's /responses, and that endpoint refuses an image model: 400
model_not_found, "The 'gpt-image-2.5' model is not supported when using
Codex with a ChatGPT account" (a real call). Drawing through the gateway
already worked: drawsFamily lets any gpt-image-* draw on
/backend-api/codex/images/generations.

What the vendor's own clients send:
- Codex CLI (codex-rs ext/image-generation tool.rs) names one model,
  IMAGE_MODEL = "gpt-image-2".
- CLIProxyAPI (executor/codex_openai_images.go) passes gpt-image-1.5 to
  2.6 and their -flare/-sunburst variants straight into the same
  /images/generations JSON. magpie sends the same shape.
- Real calls with one account: gpt-image-2.5, gpt-image-2 and the made-up
  gpt-image-9.9-nope each answered 200 with the same thing: 1536x1024, 12
  input / 343 output tokens, x-codex-active-limit imagegen_premium. The
  backend picks the model itself (#1865), so the list keeps one GPT Image.

Changes:
- provider.testOne: a ChatGPT account's gpt-image-* is tested on
  {codex base}/images/generations with a tiny drawing. probeOnce adds
  Codex's image headers (Accept json, x-codex-imagegen-request-id,
  x-codex-image-turn-id), as gateway sendWith does.
- The editor's Image models row, for a provider whose vendor picks the
  drawer (gateway.VendorPicksDrawer, new providerInfo.drawPicks), says
  why only one GPT Image is listed. It reuses an existing string, so
  there are no new keys. After the rebase onto 51bdc985b the core was
  44 bytes over its 1,533,802 budget. renderDrawers' comment line was
  dropped to fit, and the budget is not raised.

Run (mote):
- go vet, GOOS=linux go vet -tags nogui and GOOS=windows go vet, on
  internal/provider and internal/gui; gofmt -l is clean.
- go test -run of TestChatGPTAccountTestsGPTImageByDrawing (at this head),
  TestCoreScriptBudget, TestImageGenCodexOneEntry and
  TestProviderInfoListsImageModels: ok.
- node --test of image-models-hide, video-models-hide and i18n-keys: 77
  of 78. The red is i18n-keys "a plugin's words are its own" (routing's
  "No session ID", usage's "View routing"). It is red the same on a
  fresh origin/main 51bdc985b and filed as #5327/#5332.

Real account: a small main built on mote, run here under a sandbox
HOME holding a copy of ~/.codex/auth.json (the access token had 166h
left, so no refresh). provider.Find("codex").TestModels: gpt-image-2.5
ok 200 in 8.8s, gpt-image-2 ok 200 in 10.4s. The copy matched the live
auth.json byte for byte afterwards.

Broken by hand: with the old test.go, the new test goes red. Its
requests went to /responses with Accept text/event-stream.

Not tried: the editor's Test clicked in the GUI app, and Windows or
Linux runs of the Test. A Copilot account's image models likely have
the same Test gap; that is filed as #5377, not changed here.
2026-11-05 18:31:22 +08:00

73 lines
3.3 KiB
Go

package provider
import (
"context"
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"strings"
"sync"
"testing"
)
// ChangQiu on Discord: a ChatGPT account's gpt-image-2.5, typed in by
// hand, failed its Test, since it was asked as a chat on /responses, which
// the backend refuses for an image model (its real 400, below). It is
// asked as the gateway draws it: on the Codex backend's images API, in
// JSON, with Codex CLI's image ids, and the backend's real answer (its
// fields as chatgpt.com sent them, the picture cut short) is a pass. Any
// gpt-image-* name goes, as the backend takes any (drawsFamily).
func TestChatGPTAccountTestsGPTImageByDrawing(t *testing.T) {
azureHome(t)
type asked struct {
path, accept, imagegen, turn, auth, account string
body map[string]any
}
var mu sync.Mutex
var got []asked
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, _ := io.ReadAll(r.Body)
a := asked{path: r.URL.Path, accept: r.Header.Get("Accept"), imagegen: r.Header.Get("x-codex-imagegen-request-id"), turn: r.Header.Get("x-codex-image-turn-id"), auth: r.Header.Get("Authorization"), account: r.Header.Get("chatgpt-account-id")}
_ = json.Unmarshal(b, &a.body)
mu.Lock()
got = append(got, a)
mu.Unlock()
w.Header().Set("Content-Type", "application/json")
if strings.HasSuffix(r.URL.Path, "/images/generations") {
w.Write([]byte(`{"created": 1793873496, "background": "opaque", "data": [{"b64_json": "iVBORw0KGgoAAAANSUhEUgAA", "generation_id": "bfe49c3e-1703-47eb-a9e0-6ee5d86ac69e"}], "output_format": "png", "quality": "low", "safety_identifier": null, "size": "1536x1024", "usage": {"input_tokens": 12, "input_tokens_details": {"image_tokens": 0, "text_tokens": 12}, "output_tokens": 343, "output_tokens_details": {"image_tokens": 343, "text_tokens": 0}, "total_tokens": 355}}`))
return
}
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(`{"detail":"The 'gpt-image-2.5' model is not supported when using Codex with a ChatGPT account.","error":{"type":"invalid_request_error","code":"model_not_found","message":"The 'gpt-image-2.5' model is not supported when using Codex with a ChatGPT account."}}`))
}))
defer srv.Close()
p := Provider{ID: "codex", Name: "Codex", Responses: srv.URL + "/backend-api/codex", Account: &Account{
Agent: "codex", User: "me@example.com",
sign: codexSign(func(context.Context) (string, string, error) { return "tok", "acct-1", nil }),
}}
rs := p.TestModels(context.Background(), []string{"gpt-image-2.5", "gpt-image-2"})
for _, r := range rs {
if !r.OK {
t.Errorf("%s: %+v", r.Model, r)
}
}
if len(got) != 2 {
t.Fatalf("asked %d times: %+v", len(got), got)
}
for _, a := range got {
if a.path != "/backend-api/codex/images/generations" {
t.Errorf("asked at %s, not the images API", a.path)
}
if m, _ := a.body["model"].(string); !strings.HasPrefix(m, "gpt-image-2") || a.body["prompt"] == nil {
t.Errorf("body %v", a.body)
}
if a.accept != "application/json" || a.imagegen == "" || a.turn == "" || a.imagegen == a.turn {
t.Errorf("Accept %q, x-codex-imagegen-request-id %q, x-codex-image-turn-id %q", a.accept, a.imagegen, a.turn)
}
if a.auth != "Bearer tok" || a.account != "acct-1" {
t.Errorf("signed as %q for %q", a.auth, a.account)
}
}
}