fix(canvas): Grok 图片生成 - 移除冲突的 size 参数并锁定请求体格式

Co-authored-by: yepwait <1239738103@qq.com>
Original-PR: https://github.com/ddcat-ai/open-ai-canvas/pull/209
This commit is contained in:
yepandyepwait authored and GitHub committed 2026-08-14 09:59:18 +08:00
1 parent 1e4cf84c10
commit 477aebded5
3 files changed
+16 -5

No files matched your search

+13 -1
View File
@@ -229,9 +229,21 @@ func TestGrokImageRequestBodyMapsAspectRatio(t *testing.T) {
if path != "/images/generations" {
t.Fatalf("path = %q", path)
}
if body.AspectRatio != "9:16" || body.Size != "9:16" || body.Resolution != "2k" {
if body.AspectRatio != "9:16" || body.Resolution != "2k" {
t.Fatalf("body = %#v", body)
}
encoded, err := json.Marshal(body)
if err != nil {
t.Fatalf("marshal body: %v", err)
}
var payload map[string]any
if err := json.Unmarshal(encoded, &payload); err != nil {
t.Fatalf("unmarshal body: %v", err)
}
// Grok 使用 aspect_ratio;测试锁定请求 JSON,防止非法 size 字段再次混入。
if _, exists := payload["size"]; exists {
t.Fatalf("request body must not contain size: %s", encoded)
}
if got := normalizeGrokImageAspectRatio("1280x720"); got != "16:9" {
t.Fatalf("normalize 1280x720 = %q", got)
}