fix(media): 支持大尺寸图像响应并补齐迁移契约
- 为图像协议放宽 JSON 响应上限并显式处理读取与超限错误 - 合并基础模型与平台能力,避免运行时丢失分辨率和比例约束 - 固化稳定 Gemini 图像模型的能力、计价和 preview 兼容别名
This commit is contained in:
@@ -46,6 +46,46 @@ func TestDecodeHTTPResponseForProtocolCapturesOfficialErrorWire(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeHTTPResponseForProtocolAllowsLargeImagePayload(t *testing.T) {
|
||||
payload := `{"data":"` + strings.Repeat("a", int(defaultMaxJSONResponseBytes)) + `"}`
|
||||
response := &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Status: "200 OK",
|
||||
Header: http.Header{"Content-Type": {"application/json"}},
|
||||
Body: io.NopCloser(strings.NewReader(payload)),
|
||||
}
|
||||
|
||||
result, wire, err := decodeHTTPResponseForProtocol(response, ProtocolGeminiGenerateContent)
|
||||
if err != nil {
|
||||
t.Fatalf("large Gemini image response failed: %v", err)
|
||||
}
|
||||
if got, _ := result["data"].(string); len(got) != int(defaultMaxJSONResponseBytes) {
|
||||
t.Fatalf("large Gemini image payload length = %d", len(got))
|
||||
}
|
||||
if wire == nil || len(wire.RawJSON) != len(payload) {
|
||||
t.Fatalf("large Gemini wire payload was truncated: %+v", wire)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeHTTPResponseForProtocolRejectsOversizedDefaultPayload(t *testing.T) {
|
||||
payload := `{"data":"` + strings.Repeat("a", int(defaultMaxJSONResponseBytes)) + `"}`
|
||||
response := &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Status: "200 OK",
|
||||
Header: http.Header{"Content-Type": {"application/json"}},
|
||||
Body: io.NopCloser(strings.NewReader(payload)),
|
||||
}
|
||||
|
||||
_, _, err := decodeHTTPResponseForProtocol(response, ProtocolOpenAIResponses)
|
||||
if err == nil {
|
||||
t.Fatal("expected oversized default response to fail")
|
||||
}
|
||||
clientErr, ok := err.(*ClientError)
|
||||
if !ok || clientErr.Code != "response_too_large" {
|
||||
t.Fatalf("unexpected oversized response error: %T %v", err, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeminiNativeStreamPreservesOfficialEvents(t *testing.T) {
|
||||
var requestedPath string
|
||||
upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user