fix(canvas): 分镜生成上下文 - 忽略未绑定资产的角色设计工作流
This commit is contained in:
@@ -22,7 +22,10 @@ export function resolveStoryboardGenerationContext(nodes: CanvasNodeData[]): Sto
|
||||
const stylePresetId = String(styleNode?.metadata?.stylePresetId || "").trim();
|
||||
if (!styleNode || !stylePrompt || !stylePresetId) throw new Error("请先设置项目画风,再生成分镜");
|
||||
|
||||
const characterNodes = nodes.filter((node) => node.metadata?.workflowKind === "character");
|
||||
// `workflowKind=character` is also used by standalone character-design
|
||||
// image workflows. Only nodes linked to a project character asset are
|
||||
// storyboard character cards and therefore participate in this check.
|
||||
const characterNodes = nodes.filter((node) => node.metadata?.workflowKind === "character" && node.metadata?.characterAssetId?.trim());
|
||||
const invalidCharacter = characterNodes.find((node) => !node.metadata?.characterAssetId?.trim() || !node.metadata?.characterVersionId?.trim() || !(node.metadata?.characterName || node.title).trim());
|
||||
if (invalidCharacter) throw new Error(`角色卡“${invalidCharacter.metadata?.characterName || invalidCharacter.title || "未命名角色"}”版本未同步,请刷新角色资产后再生成分镜`);
|
||||
|
||||
|
||||
65
web/test/canvas-storyboard-context.test.ts
Normal file
65
web/test/canvas-storyboard-context.test.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
|
||||
import { resolveStoryboardGenerationContext } from "@/lib/canvas/canvas-storyboard-context";
|
||||
import { CanvasNodeType, type CanvasNodeData } from "@/types/canvas";
|
||||
|
||||
const node = (id: string, type: CanvasNodeType, metadata: CanvasNodeData["metadata"] = {}): CanvasNodeData => ({
|
||||
id,
|
||||
type,
|
||||
title: id,
|
||||
position: { x: 0, y: 0 },
|
||||
width: 320,
|
||||
height: 180,
|
||||
metadata,
|
||||
});
|
||||
|
||||
const styleNode = node("style", CanvasNodeType.Text, {
|
||||
workflowKind: "styleboard",
|
||||
stylePresetId: "style-v1",
|
||||
content: "统一的项目画风",
|
||||
});
|
||||
|
||||
describe("storyboard generation context", () => {
|
||||
it("ignores standalone character-design workflows without a linked asset", () => {
|
||||
const context = resolveStoryboardGenerationContext([
|
||||
styleNode,
|
||||
node("character-turnaround", CanvasNodeType.Image, {
|
||||
workflowKind: "character",
|
||||
composerContent: "生成角色三视图",
|
||||
}),
|
||||
]);
|
||||
|
||||
expect(context.characters).toEqual([]);
|
||||
});
|
||||
|
||||
it("keeps the version check for linked character cards", () => {
|
||||
expect(() => resolveStoryboardGenerationContext([
|
||||
styleNode,
|
||||
node("character-card", CanvasNodeType.Text, {
|
||||
workflowKind: "character",
|
||||
characterAssetId: "asset-1",
|
||||
characterName: "李当歌",
|
||||
}),
|
||||
])).toThrow("角色卡“李当歌”版本未同步");
|
||||
});
|
||||
|
||||
it("passes linked character cards with a current version", () => {
|
||||
const context = resolveStoryboardGenerationContext([
|
||||
styleNode,
|
||||
node("character-card", CanvasNodeType.Text, {
|
||||
workflowKind: "character",
|
||||
characterAssetId: "asset-1",
|
||||
characterVersionId: "version-1",
|
||||
characterName: "李当歌",
|
||||
characterDefinition: { role: "镇国公世子" },
|
||||
}),
|
||||
]);
|
||||
|
||||
expect(context.characters).toEqual([{
|
||||
assetId: "asset-1",
|
||||
versionId: "version-1",
|
||||
name: "李当歌",
|
||||
definition: { role: "镇国公世子" },
|
||||
}]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user