refactor(*): 平台架构 - 拆分后端领域模块并同步插件协议与模型能力
This commit is contained in:
1 parent
916043fb5a
commit
6e5cbc8b05
644 files changed
+62731
-2320
No files matched your search
@@ -4,13 +4,74 @@ import { ImageSizePicker } from "../src/components/image-size-picker";
|
||||
import { applyImageSizeSelection } from "../src/components/image-settings-panel";
|
||||
import { ImageSizePresetsEditor } from "../src/components/image-size-presets-editor";
|
||||
import { ModelCapabilityEditor } from "../src/components/model-capability-editor";
|
||||
import { defaultImageCapabilityConfig, normalizeModelCapabilityConfig } from "../src/lib/model-capabilities";
|
||||
import { IMAGE_RATIOS, IMAGE_RESOLUTIONS, imagePresetForRatio, imagePresetValue, imageQualityForTier, imageSizeConfigWithPresets, imageSizePresets, imageTierAvailable } from "../src/lib/image-size-presets";
|
||||
import { defaultImageCapabilityConfig, normalizeImageValue, normalizeModelCapabilityConfig } from "../src/lib/model-capabilities";
|
||||
import { IMAGE_RATIOS, IMAGE_RESOLUTIONS, imagePresetForRatio, imagePresetValue, imageQualityForSelection, imageQualityForTier, imageSizeConfigWithPresets, imageSizePresets, imageTierAvailable } from "../src/lib/image-size-presets";
|
||||
import { buildImageResolutionOptions } from "../src/lib/image-resolution-tiers";
|
||||
import { resolveImageRequestSize, validateImageSize } from "../src/services/api/image-validation";
|
||||
import { buildGeminiImageGenerationConfig } from "../src/lib/gemini-image";
|
||||
|
||||
describe("统一图片分辨率与宽高比", () => {
|
||||
test("默认 Gemini 质量枚举不能把未启用的 1K 显示出来", () => {
|
||||
const profile = defaultImageCapabilityConfig("gemini-image", "nano-banana-pro-4k");
|
||||
profile.size = imageSizeConfigWithPresets(profile, IMAGE_RATIOS.map((ratio) => imagePresetForRatio("4k", ratio)));
|
||||
expect(profile.quality.supported).toBe(true);
|
||||
expect(imageTierAvailable(profile, "4k")).toBe(true);
|
||||
expect(imageTierAvailable(profile, "1k")).toBe(false);
|
||||
const picker = renderToStaticMarkup(<ImageSizePicker profile={profile} size="16:9" quality="high" onChange={() => {}} />);
|
||||
expect(picker).toMatch(/aria-pressed="true"[^>]*>4K/);
|
||||
expect(picker).not.toMatch(/<button[^>]*>1K/);
|
||||
});
|
||||
|
||||
test("无质量参数的固定 4K 模型保留管理员档位,重开及自定义比例不回退 1K", () => {
|
||||
const profile = defaultImageCapabilityConfig("gemini-image", "nano-banana-pro-4k");
|
||||
profile.quality = { supported: false, values: [], default: "auto" };
|
||||
profile.size = imageSizeConfigWithPresets(profile, IMAGE_RATIOS.map((ratio) => imagePresetForRatio("4k", ratio)));
|
||||
expect(imageTierAvailable(profile, "4k")).toBe(true);
|
||||
expect(imageTierAvailable(profile, "1k")).toBe(false);
|
||||
expect(imageQualityForTier(profile, "4k")).toBeUndefined();
|
||||
const picker = renderToStaticMarkup(<ImageSizePicker profile={profile} size="16:9" onChange={() => {}} />);
|
||||
expect(picker).toMatch(/aria-pressed="true"[^>]*>4K/);
|
||||
expect(picker).not.toMatch(/<button[^>]*>[12]K/);
|
||||
expect(picker).toContain("3840 × 2160 px");
|
||||
expect(normalizeImageValue(profile, { size: "16:9", quality: "auto" }).quality).toBe("4k");
|
||||
expect(resolveImageRequestSize(profile, undefined, "16:9")).toEqual({ parameter: "aspect_ratio", value: "16:9" });
|
||||
profile.size.allowCustom = true;
|
||||
const custom = renderToStaticMarkup(<ImageSizePicker profile={profile} size="17:11" onChange={() => {}} />);
|
||||
expect(custom).toMatch(/aria-pressed="true"[^>]*>4K/);
|
||||
expect(custom).toContain("17:11 ·");
|
||||
});
|
||||
|
||||
test("无质量参数时管理员启用的 1K 和 4K 都对用户开放,未启用的 2K 仍隐藏", () => {
|
||||
const profile = defaultImageCapabilityConfig("gemini-image", "test");
|
||||
profile.quality = { supported: false, values: [], default: "auto" };
|
||||
profile.size = imageSizeConfigWithPresets(profile, [...IMAGE_RATIOS.flatMap((ratio) => [imagePresetForRatio("1k", ratio), imagePresetForRatio("4k", ratio)])]);
|
||||
expect(imageTierAvailable(profile, "1k")).toBe(true);
|
||||
expect(imageTierAvailable(profile, "4k")).toBe(true);
|
||||
expect(imageTierAvailable(profile, "2k")).toBe(false);
|
||||
expect(imageQualityForSelection(profile, "4k")).toBe("4k");
|
||||
expect(normalizeImageValue(profile, { size: "16:9", quality: "4k" }).quality).toBe("4k");
|
||||
expect(buildGeminiImageGenerationConfig("16:9", "4k").imageConfig).toEqual({ aspectRatio: "16:9", imageSize: "4K" });
|
||||
const picker = renderToStaticMarkup(<ImageSizePicker profile={profile} size="16:9" onChange={() => {}} />);
|
||||
expect(picker).toMatch(/<button[^>]*>1K/);
|
||||
expect(picker).toMatch(/<button[^>]*>4K/);
|
||||
expect(picker).not.toMatch(/<button[^>]*>2K/);
|
||||
expect(picker).not.toContain("当前协议未配置独立分辨率");
|
||||
const selected = renderToStaticMarkup(<ImageSizePicker profile={profile} size="16:9" quality="4k" onChange={() => {}} />);
|
||||
expect(selected).toMatch(/aria-pressed="true"[^>]*>4K/);
|
||||
expect(selected).not.toMatch(/aria-pressed="true"[^>]*>1K/);
|
||||
expect(selected).toContain("3840 × 2160 px");
|
||||
const editor = renderToStaticMarkup(<ImageSizePresetsEditor profile={profile} onChange={() => {}} />);
|
||||
expect(editor).not.toContain("需先配置此档位对应的质量值,用户端才会开放。");
|
||||
});
|
||||
|
||||
test("真实图片质量字段不被分辨率预设推断覆盖", () => {
|
||||
const profile = defaultImageCapabilityConfig("gemini-image", "test");
|
||||
profile.quality = { supported: true, values: ["auto", "low", "medium", "high"], default: "auto" };
|
||||
profile.size = imageSizeConfigWithPresets(profile, [imagePresetForRatio("2k", "16:9"), imagePresetForRatio("4k", "16:9")]);
|
||||
expect(normalizeImageValue(profile, { size: "16:9", quality: "auto" }).quality).toBe("auto");
|
||||
expect(normalizeImageValue(profile, { size: "16:9", quality: "high" }).quality).toBe("high");
|
||||
});
|
||||
|
||||
test("比例协议切换 4K 时同时提交尺寸和真实质量档位", () => {
|
||||
const changes: Array<[string, string]> = [];
|
||||
applyImageSizeSelection((key, value) => changes.push([key, value]), "16:9", "high");
|
||||
|
||||
Reference in new issue
Block a user