feat: integrate platform backend and application interfaces

This commit is contained in:
Qiufeng
2026-09-02 21:09:47 +08:00
parent cd9ac1af70
commit b16390dd41
648 changed files with 102488 additions and 17737 deletions
+47
View File
@@ -0,0 +1,47 @@
import test from "node:test";
import assert from "node:assert/strict";
import { imageModelFor, imageSizeFor, normalizeImageParams, OPENAI_IMAGE_RATIOS, OPENAI_IMAGE_RESOLUTIONS } from "../src/image-options.ts";
test("OpenAI image ratio matrix produces aligned sizes for every resolution tier", () => {
for (const resolution of OPENAI_IMAGE_RESOLUTIONS) {
for (const ratio of OPENAI_IMAGE_RATIOS) {
const size = imageSizeFor(ratio, resolution);
if (ratio === "auto") {
assert.equal(size, "auto");
continue;
}
const match = /^(\d+)x(\d+)$/.exec(size);
assert.ok(match, `${resolution} ${ratio}`);
const width = Number(match[1]);
const height = Number(match[2]);
assert.equal(width % 16, 0);
assert.equal(height % 16, 0);
assert.ok(width >= 16 && height >= 16);
assert.ok(width * height <= 8_294_400);
assert.ok(Math.max(width, height) / Math.min(width, height) <= 3);
}
}
});
test("OpenAI image parameter defaults are explicit and transparent JPEG is coerced to PNG", () => {
const params = normalizeImageParams({ ratio: "16:9", resolution: "2K", background: "transparent", output_format: "jpeg" });
assert.equal(params.size, "2048x1152");
assert.equal(params.background, "transparent");
assert.equal(params.output_format, "png");
assert.equal(params.quality, "auto");
assert.equal(params.moderation, "auto");
assert.equal(params.ratio, undefined);
assert.equal(params.resolution, undefined);
});
test("OpenAI image model selection falls back from a missing tier mapping to the base model", () => {
assert.equal(imageModelFor("configured-image-model", "4K", { "1K": "mapped-1k" }), "configured-image-model");
assert.equal(imageModelFor(undefined, "2K", {}), "gpt-image-2");
assert.equal(imageModelFor("configured-image-model", "2K", { "2K": "mapped-2k" }), "mapped-2k");
});
test("invalid explicit image sizes are replaced by the selected ratio and resolution", () => {
assert.equal(normalizeImageParams({ size: "0x0", ratio: "1:1", resolution: "2K" }).size, "2048x2048");
assert.equal(normalizeImageParams({ size: "1000x1000", ratio: "1:1", resolution: "1K" }).size, "1024x1024");
assert.equal(normalizeImageParams({ size: "2048x1152", ratio: "16:9", resolution: "2K" }).size, "2048x1152");
});