fix(wp7-02): normalize generated image dimensions
Dada P0-A isolated Windows CI / validate-and-package (push) Failing after 2m17s

This commit is contained in:
suyx
2026-08-04 17:19:41 +08:00
parent 9d6f4ac24b
commit ae725a2d01
11 changed files with 153 additions and 17 deletions
@@ -1,10 +1,13 @@
import { describe, expect, it } from "vitest";
import { GeminiFlashAdapter } from "../../apps/worker/src/ai-adapter-gemini-flash.js";
import { GeminiProAdapter } from "../../apps/worker/src/ai-adapter-gemini-pro.js";
import { GptImageAdapter } from "../../apps/worker/src/ai-adapter-gpt-image.js";
import {
gptImageRequestSizeForRatio,
normalizeImageOutputToRatio,
productDimensionsForRatio,
} from "../../apps/worker/src/image-output-normalizer.js";
} from "../../apps/worker/src/image-output-normalizer.mjs";
const onePixelPng = Buffer.from(
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=",
@@ -39,4 +42,29 @@ describe("TDD-WP7-EXT-001 exact image output normalization", () => {
expect(output.bytes.subarray(0, 8).toString("hex")).toBe("89504e470d0a1a0a");
expect(productDimensionsForRatio("9:16")).toEqual({ pixelHeight: 1920, pixelWidth: 1080 });
});
it("is used by all three production adapter boundaries", async () => {
const encoded = onePixelPng.toString("base64");
const adapters = [
new GeminiFlashAdapter({ transport: {
async start() { return { candidates: [{ inline_data: { data: encoded, mime_type: "image/png" }, pixelHeight: 1, pixelWidth: 1 }] }; },
async poll() { return {}; },
} }),
new GeminiProAdapter({ transport: {
async start() { return { operation: { done: true, response: { candidates: [{ inline_data: { data: encoded, mime_type: "image/png" }, pixelHeight: 1, pixelWidth: 1 }] } } }; },
async poll() { return {}; },
} }),
new GptImageAdapter({ transport: {
async start() { return { data: [{ b64_json: encoded, pixelHeight: 1, pixelWidth: 1 }] }; },
async poll() { return {}; },
} }),
];
for (const adapter of adapters) {
const result = await adapter.start({
configSnapshot: {}, generationId: `normalization-${adapter.modelId}`, modelId: adapter.modelId,
prompt: "sanitized fixture", ratio: "1:1", referenceAssetIds: [],
});
expect(result).toMatchObject({ status: "completed", outputs: [{ mimeType: "image/png", pixelHeight: 1080, pixelWidth: 1080 }] });
}
});
});