perf(acceptance): 流式生成唯一图片输入
避免千请求验收重复复用同一图片内容而争用同一资产记录,使每个任务走真实独立上传与物化链路。\n\nGemini 请求体改为流式 Base64 编码,降低压测客户端的大对象内存峰值;新增尺寸、哈希唯一性和请求体还原测试。\n\n验证:Go 全量测试、go vet、迁移安全检查、bash -n、ShellCheck、gofmt、git diff --check 均通过。
This commit is contained in:
@@ -27,6 +27,58 @@ func TestStreamGeminiImageHashDoesNotNeedWholeResponse(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPaddedPNGVariantsAreExactSizeAndUnique(t *testing.T) {
|
||||
first := paddedPNGVariant(256<<10, 1)
|
||||
second := paddedPNGVariant(256<<10, 2)
|
||||
if len(first) != 256<<10 || len(second) != 256<<10 {
|
||||
t.Fatalf("variant sizes=%d/%d", len(first), len(second))
|
||||
}
|
||||
firstHash := sha256.Sum256(first)
|
||||
secondHash := sha256.Sum256(second)
|
||||
if firstHash == secondHash {
|
||||
t.Fatal("distinct variants have the same SHA-256")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStreamGeminiRequestBodyPreservesInput(t *testing.T) {
|
||||
input := paddedPNGVariant(2<<20, 37)
|
||||
var body struct {
|
||||
Contents []struct {
|
||||
Parts []struct {
|
||||
InlineData *struct {
|
||||
MIMEType string `json:"mimeType"`
|
||||
Data string `json:"data"`
|
||||
} `json:"inlineData"`
|
||||
} `json:"parts"`
|
||||
} `json:"contents"`
|
||||
GenerationConfig struct {
|
||||
ResponseModalities []string `json:"responseModalities"`
|
||||
} `json:"generationConfig"`
|
||||
}
|
||||
stream := streamGeminiRequestBody(input)
|
||||
defer stream.Close()
|
||||
if err := json.NewDecoder(stream).Decode(&body); err != nil {
|
||||
t.Fatalf("decode streamed Gemini request: %v", err)
|
||||
}
|
||||
if len(body.Contents) != 1 || len(body.Contents[0].Parts) != 2 || body.Contents[0].Parts[1].InlineData == nil {
|
||||
t.Fatalf("unexpected Gemini body structure: %+v", body)
|
||||
}
|
||||
inlineData := body.Contents[0].Parts[1].InlineData
|
||||
if inlineData.MIMEType != "image/png" {
|
||||
t.Fatalf("mime type=%q", inlineData.MIMEType)
|
||||
}
|
||||
decoded, err := base64.StdEncoding.DecodeString(inlineData.Data)
|
||||
if err != nil {
|
||||
t.Fatalf("decode streamed input: %v", err)
|
||||
}
|
||||
if !bytes.Equal(decoded, input) {
|
||||
t.Fatal("streamed input differs from source")
|
||||
}
|
||||
if len(body.GenerationConfig.ResponseModalities) != 1 || body.GenerationConfig.ResponseModalities[0] != "IMAGE" {
|
||||
t.Fatalf("response modalities=%v", body.GenerationConfig.ResponseModalities)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVideoCombinationsProvide128UniqueInputs(t *testing.T) {
|
||||
images := make([]string, 16)
|
||||
for index := range images {
|
||||
|
||||
Reference in New Issue
Block a user