fix(provider): 修正媒体请求转换与上游错误透传
按上游协议能力延迟处理媒体资源:OpenAI 兼容平台默认使用 multipart,显式配置后才发送 JSON URL;Gemini 官方协议使用 Files API,兼容协议使用内嵌 Base64,并同步覆盖相关媒体客户端。\n\n安全的上游 400/422 原始错误会作为下游 message 返回,同时保留结构化诊断信息和历史任务兼容。\n\n验证:API 全量无缓存测试、go vet、pnpm lint、pnpm test、pnpm build、pnpm openapi、git diff --check。
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/easyai/easyai-ai-gateway/apps/api/internal/publicerror"
|
||||
"github.com/easyai/easyai-ai-gateway/apps/api/internal/store"
|
||||
)
|
||||
|
||||
@@ -191,6 +192,34 @@ func TestEasyAITaskResultResponseMovesImageDataURLToB64JSON(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEasyAITaskResultResponseForwardsSafeUpstreamParameterMessage(t *testing.T) {
|
||||
raw := "Duplicate parameter: 'image'. Use image[]=<value> for multiple values."
|
||||
legacy := publicerror.Error{
|
||||
Code: "upstream_invalid_request",
|
||||
Message: "The upstream service rejected the request parameters.",
|
||||
Category: "upstream",
|
||||
Source: "upstream",
|
||||
HTTPStatus: http.StatusBadRequest,
|
||||
Version: "v1",
|
||||
}
|
||||
response := easyAITaskResultResponse(store.GatewayTask{
|
||||
ID: "image-error-1",
|
||||
Kind: "images.edits",
|
||||
Status: "failed",
|
||||
ErrorCode: "http_400",
|
||||
ErrorMessage: raw,
|
||||
PublicError: &legacy,
|
||||
})
|
||||
standard, ok := response["error"].(publicerror.Error)
|
||||
if !ok {
|
||||
t.Fatalf("unexpected EasyAI error payload: %+v", response)
|
||||
}
|
||||
upstream, _ := standard.Details["upstreamError"].(map[string]any)
|
||||
if response["message"] != raw || standard.Message != raw || upstream["message"] != raw {
|
||||
t.Fatalf("EasyAI result did not forward safe upstream diagnostics: %+v", response)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEasyAITaskResultResponsePreservesAudioDataURLAsContent(t *testing.T) {
|
||||
base64Payload := "SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjYwLjMuMTAwAAAAAAAAAAAAAAD/"
|
||||
task := store.GatewayTask{
|
||||
|
||||
Reference in New Issue
Block a user