feat(*): 创作配置 - 支持 Midjourney、多图保存与自定义公告
Co-authored-by: ddcat666 <26564566+ddcat666@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
|
||||
import { applyGeneratedMediaResultMetadata, applyGenerationTaskResultToNodes, videoMetadata } from "@/lib/canvas/canvas-generation-task-sync";
|
||||
import { applyGeneratedMediaResultMetadata, applyGenerationTaskResultToNodes, generationTaskOutputsApplied, shouldRecoverCanvasImageOutputs, videoMetadata } from "@/lib/canvas/canvas-generation-task-sync";
|
||||
import { commitCanvasGenerationResult } from "@/lib/canvas/canvas-generation-result";
|
||||
import { resetGenerationTaskMetadata } from "@/lib/canvas/canvas-task-state";
|
||||
import { CanvasNodeType, type CanvasNodeData } from "@/types/canvas";
|
||||
|
||||
function videoNode(assetId: string, storageKey: string): CanvasNodeData {
|
||||
@@ -16,6 +18,30 @@ function videoNode(assetId: string, storageKey: string): CanvasNodeData {
|
||||
}
|
||||
|
||||
describe("applyGeneratedMediaResultMetadata", () => {
|
||||
test("旧 Midjourney 单图节点需要补齐结果,新堆叠与普通模型不重复恢复", () => {
|
||||
const old = { ...videoNode("asset", "resource:old"), type: CanvasNodeType.Image, metadata: { content: "/old.png", status: "success" as const, taskId: "task", producedModel: "CHANNEL::Midjourney v8.2 高速" } };
|
||||
const task = { id: "task", type: "canvas_image", status: "succeeded" as const, prompt: "", attempts: 1, createdAt: "", updatedAt: "", resultJson: JSON.stringify({ images: Array.from({ length: 4 }, () => ({ dataUrl: "/image.png" })) }) };
|
||||
expect(shouldRecoverCanvasImageOutputs(old)).toBe(true);
|
||||
expect(generationTaskOutputsApplied(old, task)).toBe(false);
|
||||
expect(shouldRecoverCanvasImageOutputs({ ...old, metadata: { ...old.metadata, generationOutputCount: 4 } })).toBe(false);
|
||||
expect(generationTaskOutputsApplied({ ...old, metadata: { ...old.metadata, generationOutputCount: 4 } }, task)).toBe(true);
|
||||
expect(shouldRecoverCanvasImageOutputs({ ...old, metadata: { ...old.metadata, batchRootId: "root" } })).toBe(false);
|
||||
expect(shouldRecoverCanvasImageOutputs({ ...old, metadata: { ...old.metadata, producedModel: "other-model" } })).toBe(false);
|
||||
expect(resetGenerationTaskMetadata({ generationOutputCount: 4 }).generationOutputCount).toBeUndefined();
|
||||
});
|
||||
test("多图提交保留保存期间的移动和改名,重复提交不新增或覆盖图片", () => {
|
||||
const before = { ...videoNode("", ""), type: CanvasNodeType.Image, metadata: { taskId: "task" } };
|
||||
const result = { ...before, metadata: { taskId: "task", content: "/new.png", isBatchRoot: true, batchChildIds: ["child"] } };
|
||||
const child = { ...result, id: "child", position: { x: 440, y: 0 }, metadata: { content: "/child.png", batchRootId: before.id } };
|
||||
const live = { ...before, title: "改名", position: { x: 500, y: 100 } };
|
||||
const committed = commitCanvasGenerationResult([live], before, result, "task", [child]);
|
||||
expect(committed[0]).toMatchObject({ title: "改名", position: { x: 500, y: 100 } });
|
||||
expect(committed[1].position).toEqual({ x: 940, y: 100 });
|
||||
const edited = { ...committed[1], title: "我的图片", position: { x: 3000, y: 2000 } };
|
||||
expect(commitCanvasGenerationResult([committed[0], edited], before, result, "task", [child])).toEqual([committed[0], edited]);
|
||||
expect(() => commitCanvasGenerationResult([], before, result, "task", [child])).toThrow("已删除");
|
||||
expect(() => commitCanvasGenerationResult([{ ...live, metadata: { taskId: "new-task" } }], before, result, "task", [child])).toThrow("其他生成任务");
|
||||
});
|
||||
test("明确指定的节点已删除时不能根据 taskId 误更新其他节点", async () => {
|
||||
const other = { ...videoNode("asset", "video:key"), metadata: { taskId: "task" } };
|
||||
const applied = await applyGenerationTaskResultToNodes([other], { id: "task", type: "canvas_video", status: "succeeded", prompt: "", attempts: 1, createdAt: "", updatedAt: "" }, "deleted-node");
|
||||
|
||||
Reference in New Issue
Block a user