Files
magpie/internal/gateway/ark_images_test.go
T
yetone d8501848a7 gateway: an Ark image request's own fields go to Ark, and watermark and response_format are the caller's
axelburks on Discord listed what /v1/images/generations did to a Seedream
request against Ark's images API (docs 82379/1541523). Checked against
those docs and draw.go / draw_volcengine.go; the real ones:

- Image params were dropped. drawing read OpenAI's fields alone, so
  sequential_image_generation and its options (a group of up to 15),
  optimize_prompt_options, tools, layer_decomposition and every other
  Ark field never reached Ark. Now the request's fields magpie doesn't
  read (drawingRead) are drawing.Extra, from a JSON body or a multipart
  form, masked as the prompt is (fails closed), and sent to Ark as they
  came; a form's values are typed as Ark takes them (formValue, with
  Ark's text fields kept as text). layer_decomposition with an image
  needs no prompt.
- watermark and response_format were forced. Every request went with
  watermark false and response_format b64_json. Now watermark false is
  magpie's default only, and a caller's watermark wins; response_format
  "url" asks Ark for its URL and answers it, anything else still asks
  b64_json.
- stream true would have gone to Ark and come back as events this route
  can't read: it is a 400 that names
  /v1/magpie/native/<provider>/images/generations.
Kept as it was: n stays OpenAI's, that many requests, each one image or
one group.

Tests: TestArkImagesPassOnTheirOwnFields (a group, optimize_prompt_options,
a caller's watermark, tools and url reach Ark as sent; a form's fields
typed; stream refused naming the native route). Docs: gateway-routing.md
(the Ark images row and paragraph), docs/integrating.md and the site's
integrate page (en, zh) on the vendor fields and the native route.

Run on mote at the head of this stack (the Ark video fields, the native
route and the Ark image fields, three commits on af9ac3d25):
- go test -count=1 -timeout 45m ./internal/gateway ./internal/gui
  ./internal/access: gateway and access ok; gui red only in
  TestMainWindowCorners/macOS_26_SDK (#3949, red on main).
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./...: clean. gofmt -l: nothing.
- No GUI file or script changes in this stack, so no GUI run.
The commits between were not run on their own at this base.

Broken by hand, each red, then put back:
- Extra not merged into Ark's request: TestArkImagesPassOnTheirOwnFields red
- response_format url not asked of Ark: TestArkImagesPassOnTheirOwnFields red

Not tried: no real Ark image was drawn (no money spent); the shapes are
from Ark's docs, on a fake Ark.

Credit: axelburks on Discord.
2026-11-03 18:46:55 +08:00

50 lines
2.0 KiB
Go

package gateway
import (
"bytes"
"mime/multipart"
"strings"
"testing"
)
// Ark's images fields go as they came: a group with
// sequential_image_generation, optimize_prompt_options, a watermark the
// caller asks for, and an answer as Ark's URL when the caller asks for url.
func TestArkImagesPassOnTheirOwnFields(t *testing.T) {
s, a := arked(t)
body := `{"model":"ark/doubao-seedream-4-5-251128","prompt":"四季","sequential_image_generation":"auto","sequential_image_generation_options":{"max_images":4},
"optimize_prompt_options":{"mode":"fast"},"watermark":true,"tools":[{"type":"web_search"}],"response_format":"url"}`
if code, _, raw := postImages(t, s, "/v1/images/generations", "application/json", body); code != 200 {
t.Fatalf("%d %s", code, raw)
}
m := a.sent(t)[0]
opts, _ := m["sequential_image_generation_options"].(map[string]any)
opt, _ := m["optimize_prompt_options"].(map[string]any)
tools, _ := m["tools"].([]any)
if m["sequential_image_generation"] != "auto" || opts["max_images"] != float64(4) || opt["mode"] != "fast" || m["watermark"] != true ||
len(tools) != 1 || m["response_format"] != "url" {
t.Fatalf("sent %v", m)
}
// a form's fields are typed as Ark takes them
var buf bytes.Buffer
mw := multipart.NewWriter(&buf)
mw.WriteField("model", "ark/doubao-seedream-4-5-251128")
mw.WriteField("prompt", "四季")
mw.WriteField("watermark", "true")
mw.WriteField("sequential_image_generation", "auto")
mw.Close()
if code, _, raw := postImages(t, s, "/v1/images/generations", mw.FormDataContentType(), buf.String()); code != 200 {
t.Fatalf("%d %s", code, raw)
}
if m := a.sent(t)[1]; m["watermark"] != true || m["sequential_image_generation"] != "auto" {
t.Fatalf("sent %v", m)
}
// a stream is Ark's events, which this route doesn't give
code, _, raw := postImages(t, s, "/v1/images/generations", "application/json", `{"model":"ark/doubao-seedream-4-5-251128","prompt":"四季","stream":true}`)
if code != 400 || !strings.Contains(raw, NativePath) {
t.Fatalf("%d %s", code, raw)
}
}