fix(canvas): 画布批量生成 - 修复节点丢失、资源引用及刷新状态不一致
This commit is contained in:
@@ -17,6 +17,32 @@ function imageNode(id: string, status: CanvasNodeStatus, metadata: Partial<NonNu
|
||||
}
|
||||
|
||||
describe("canvas image batch retry", () => {
|
||||
test("旧批次索引不能删除属于其他批次的节点", () => {
|
||||
const root = imageNode("root", "loading", { isBatchRoot: true, batchChildIds: ["foreign"] });
|
||||
const foreign = imageNode("foreign", "loading", { batchRootId: "other-root" });
|
||||
expect(retireImageBatchChildren(root, [root, foreign], []).removedIds).toEqual([]);
|
||||
expect(cancelIncompleteImageBatch(root.id, [foreign.id], [root, foreign], []).nodes).toContain(foreign);
|
||||
});
|
||||
test("清理和取消只移除无持久资源的占位,不能删除尚未恢复预览的成功图片", () => {
|
||||
const root = imageNode("root", "loading", { isBatchRoot: true, batchChildIds: ["done", "pending"] });
|
||||
const done = imageNode("done", "success", { batchRootId: root.id, storageKey: "resource:done", assetId: "asset-done" });
|
||||
const pending = imageNode("pending", "loading", { batchRootId: root.id });
|
||||
const nodes = [root, done, pending];
|
||||
expect(retireImageBatchChildren(root, nodes, []).removedIds).toEqual(["pending"]);
|
||||
expect(cancelIncompleteImageBatch(root.id, ["done", "pending"], nodes, []).removedIds).toEqual(["pending"]);
|
||||
expect(reconcileImageBatchRoot(root, nodes).metadata).toMatchObject({ status: "success", storageKey: "resource:done", assetId: "asset-done", primaryImageId: "done" });
|
||||
});
|
||||
|
||||
test("刷新后五张图两成三败,根节点保留成功资源及准确失败数", () => {
|
||||
const children = Array.from({ length: 5 }, (_, i) => imageNode(`child-${i}`, i < 2 ? "success" : "error", {
|
||||
batchRootId: "root", ...(i < 2 ? { storageKey: `resource:${i}`, assetId: `asset-${i}` } : { errorDetails: "上游失败" }),
|
||||
}));
|
||||
const root = imageNode("root", "error", { isBatchRoot: true, batchChildIds: children.map((node) => node.id), taskId: "old-task", taskStatus: "failed" });
|
||||
const next = reconcileImageBatchRoot(root, [root, ...children]);
|
||||
expect(next.metadata).toMatchObject({ status: "success", storageKey: "resource:0", batchFailedCount: 3 });
|
||||
expect(next.metadata.taskId).toBeUndefined();
|
||||
});
|
||||
|
||||
test("只按批次顺序返回属于当前根节点的失败图片", () => {
|
||||
const root = imageNode("root", "error", { isBatchRoot: true, batchChildIds: ["failed-2", "success", "failed-1", "loading", "foreign"] });
|
||||
const nodes = [
|
||||
|
||||
Reference in New Issue
Block a user