fix(agent): 创作执行 - 修复会话恢复并校验画风与真实分镜行
This commit is contained in:
1 parent
2856bc7f58
commit
45de256deb
13 files changed
+179
-27
No files matched your search
@@ -5,11 +5,18 @@ import { listAgentCapabilities, buildAgentPluginOperations } from "../src/servic
|
||||
import { applyCanvasAgentOps, type CanvasAgentSnapshot } from "../src/lib/canvas/canvas-agent-ops";
|
||||
import { normalizeCreativeProposal, creativeProposalOps } from "../src/lib/creation/creative-agent-state";
|
||||
import { defaultConfig } from "../src/stores/use-config-store";
|
||||
import { buildCanvasWorkflowOps } from "../src/lib/canvas/canvas-agent-workflow";
|
||||
|
||||
const snapshot: CanvasAgentSnapshot = { projectId: "test", title: "test", nodes: [], connections: [], selectedNodeIds: [], viewport: { x: 0, y: 0, k: 1 } };
|
||||
const pluginId = "agent-extension-test";
|
||||
afterEach(() => { unregisterPlugin(pluginId); usePluginStore.setState({ runtimeStatuses: {} }); });
|
||||
|
||||
test("方案与直接工作流均拒绝只有正文的分镜", () => {
|
||||
const nodes = [{ ref: "shots", kind: "script" as const, title: "10秒分镜", content: "0–2秒近景,2–10秒特写" }];
|
||||
expect(() => normalizeCreativeProposal({ title: "短剧", summary: "分镜", markdown: "方案", workflow: { nodes, edges: [] }, generationItems: [] }, "p", 1, defaultConfig)).toThrow("script.shots");
|
||||
expect(() => buildCanvasWorkflowOps({ nodes, edges: [] }, snapshot, defaultConfig)).toThrow("shots");
|
||||
});
|
||||
|
||||
test("专业方案创建可编辑分镜与上下文连线,不伪造画风已选择或收费任务", () => {
|
||||
const proposal = normalizeCreativeProposal({ title: "短剧", summary: "搭建", markdown: "完整方案", workflow: { nodes: [
|
||||
{ ref: "style", kind: "styleboard", title: "项目画风" },
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { buildAgentStoryboardOperations } from "../src/lib/canvas/canvas-agent-storyboard";
|
||||
import { buildAgentStoryboardOperations, validateAgentStoryboardCreation } from "../src/lib/canvas/canvas-agent-storyboard";
|
||||
import { inspectStoryboardReadiness } from "../src/lib/canvas/canvas-storyboard-context";
|
||||
import { buildCanvasAgentContext } from "../src/lib/canvas/canvas-agent-context";
|
||||
import { createShortDramaPipeline } from "../src/lib/canvas/canvas-short-drama";
|
||||
import { createStoryboardRow } from "../src/lib/canvas/canvas-project-domain";
|
||||
import { applyCanvasAgentOps, type CanvasAgentSnapshot } from "../src/lib/canvas/canvas-agent-ops";
|
||||
@@ -13,6 +15,33 @@ function fixture() {
|
||||
return { snapshot, script };
|
||||
}
|
||||
|
||||
test("Agent 上下文提前指出未选择画风及分镜空行", () => {
|
||||
const { snapshot, script } = fixture();
|
||||
const readiness = buildCanvasAgentContext(snapshot).storyboardReadiness;
|
||||
expect(readiness.canGenerateStoryboard).toBe(false);
|
||||
expect(readiness.style.ready).toBe(false);
|
||||
expect(readiness.blockingReason).toContain("画风");
|
||||
expect(readiness.storyboards.find((item) => item.nodeId === script.id)?.incompleteRowIds).toEqual(["row-1", "row-2"]);
|
||||
expect(readiness.nextActions.join(" ")).toContain("canvas_apply_style");
|
||||
});
|
||||
|
||||
test("已应用画风与真实分镜写入后,返回实际总时长", () => {
|
||||
const { snapshot, script } = fixture();
|
||||
const style = snapshot.nodes.find((node) => node.metadata?.workflowKind === "styleboard")!;
|
||||
style.metadata = { ...style.metadata, stylePresetId: "preset", content: "电影写实" };
|
||||
script.metadata!.storyboard!.rows = [2, 2, 3, 2, 1].map((durationSeconds, i) => createStoryboardRow(i + 1, { durationSeconds, videoMotionPrompt: `镜头${i + 1}` }));
|
||||
const readiness = inspectStoryboardReadiness(snapshot.nodes);
|
||||
expect(readiness.canGenerateStoryboard).toBe(true);
|
||||
expect(readiness.storyboards[0]).toMatchObject({ rowCount: 5, populated: true, totalDurationSeconds: 10 });
|
||||
expect(readiness.nextActions).toEqual([]);
|
||||
});
|
||||
|
||||
test("通用节点创建不能用正文代替真实分镜行", () => {
|
||||
expect(() => validateAgentStoryboardCreation([{ type: "add_node", nodeType: "script", metadata: { content: "镜头1:0–2秒近景;镜头2:2–4秒特写" } }])).toThrow("真实镜头行");
|
||||
const { script } = fixture();
|
||||
expect(() => validateAgentStoryboardCreation([{ type: "add_node", nodeType: "script", metadata: script.metadata }])).toThrow();
|
||||
});
|
||||
|
||||
test("按行修改保留其他镜头及已有生成素材关联", () => {
|
||||
const { snapshot, script } = fixture();
|
||||
const next = applyCanvasAgentOps(snapshot, buildAgentStoryboardOperations(snapshot, { nodeId: script.id, action: "update", rowId: "row-1", patch: { dialogue: "新对白", durationSeconds: 8 } }));
|
||||
|
||||
@@ -30,6 +30,56 @@ const proposal = { id: "p", version: 1, title: "方案", summary: "摘要", mark
|
||||
const submission = (id: string, itemKey: string, taskId?: string): CreationSubmission => ({ id, runId: "run", itemKey, requestHash: "hash", taskId, quote: { model: "model", billingMode: "fixed_request", quantity: 1, amountMicrocredits: 1, estimated: false, expiresAt: "2099-01-01", quoteHash: "quote" } });
|
||||
|
||||
describe("创作控制器恢复", () => {
|
||||
for (const terminal of [true, false]) test(terminal ? "任务已失败时标记生成失败,不能引导反复读取" : "仅查询断线时保留结果恢复语义,不当作需要重做", async () => {
|
||||
const h = harness({ ...initialCreativeState(), proposal, canvasApplied: true, media: [{ ref: "a", nodeId: "a", attempt: 1, submissionId: "a", taskId: "a", status: "queued" }] }, "waiting_task", [submission("a", "a", "a")], async (_id, options) => {
|
||||
if (terminal) options?.onTaskUpdate?.({ id: "a", status: "failed" } as GenerationTask);
|
||||
throw new Error("网络异常。");
|
||||
});
|
||||
try { await h.controller.load("run"); await expect(h.controller.resume()).rejects.toThrow(); expect(h.view().state.media[0].failureKind).toBe(terminal ? "generation" : "observation"); expect(h.counters().executions).toBe(0); }
|
||||
finally { h.controller.dispose(); }
|
||||
});
|
||||
test("刷新页面可接续仍有效的旧连接,不等待旧页面租约过期", async () => {
|
||||
const h = harness(initialCreativeState());
|
||||
const get = h.api.get, claim = h.api.claim;
|
||||
let foreign = true, claims = 0;
|
||||
h.api.get = async (...args) => { const detail = await get(...args); return foreign ? { ...detail, run: { ...detail.run, executionOwner: "previous-page", leaseExpiresAt: "2099-01-01" } } : detail; };
|
||||
h.api.claim = async (...args) => { claims++; foreign = false; return claim(...args); };
|
||||
try { await h.controller.load("run"); expect(h.view().hasControl).toBe(true); expect(claims).toBe(1); expect(h.counters().executions).toBe(0); }
|
||||
finally { h.controller.dispose(); }
|
||||
});
|
||||
test("普通恢复不争抢其他连接,用户重试连接可以显式接续", async () => {
|
||||
const h = harness(initialCreativeState());
|
||||
const get = h.api.get, claim = h.api.claim;
|
||||
let foreign = false, claims = 0;
|
||||
h.api.get = async (...args) => { const detail = await get(...args); return foreign ? { ...detail, run: { ...detail.run, executionOwner: "other-page", leaseExpiresAt: "2099-01-01" } } : detail; };
|
||||
h.api.claim = async (...args) => { claims++; foreign = false; return claim(...args); };
|
||||
try {
|
||||
await h.controller.load("run"); foreign = true;
|
||||
await expect(h.controller.refresh()).rejects.toThrow("重试连接"); expect(claims).toBe(1);
|
||||
await h.controller.takeControl(); expect(claims).toBe(2); expect(h.view().hasControl).toBe(true); expect(h.view().error).toBeUndefined();
|
||||
} finally { h.controller.dispose(); }
|
||||
});
|
||||
test("已提交任务即使保留待处理批次也不能再次展示费用确认", async () => {
|
||||
const h = harness({ ...initialCreativeState(), proposal, canvasApplied: true, pendingPayment: ["a"], media: [{ ref: "a", nodeId: "a", attempt: 1, submissionId: "a", taskId: "task-a", status: "queued" }] }, "waiting_task", [{ ...submission("a", "a", "task-a"), approvedAt: "2026-01-01" }]);
|
||||
try { await h.controller.load("run"); expect(h.view().quote).toBeUndefined(); }
|
||||
finally { h.controller.dispose(); }
|
||||
});
|
||||
test("部分提交后费用卡只保留未提交项", async () => {
|
||||
const h = harness({ ...initialCreativeState(), pendingPayment: ["a", "b"] }, "paused", [submission("a", "a", "task-a"), submission("b", "b")]);
|
||||
try { await h.controller.load("run"); expect(h.view().quote?.items.map((item) => item.id)).toEqual(["b"]); }
|
||||
finally { h.controller.dispose(); }
|
||||
});
|
||||
test("迟到的确认点击复用已提交任务,不重新批准或刷新过期费用", async () => {
|
||||
const old = { ...submission("a", "a", "task-a"), approvedAt: "2000-01-01" };
|
||||
old.quote.expiresAt = "2000-01-01";
|
||||
const completed = { id: "task-a", status: "succeeded", resultJson: JSON.stringify({ images: [{ storageKey: "resource:output" }] }) } as GenerationTask;
|
||||
const h = harness({ ...initialCreativeState(), proposal, canvasApplied: true, pendingPayment: ["a"], media: [{ ref: "a", nodeId: "a", attempt: 1, submissionId: "a", taskId: "task-a", status: "queued" }] }, "waiting_task", [old], async () => completed);
|
||||
h.api.approve = async () => { throw new Error("不应重新批准已提交任务"); };
|
||||
h.api.refreshQuote = async () => { throw new Error("不应刷新已提交任务报价"); };
|
||||
h.api.execute = async (_id, input) => { expect(input.submissionId).toBe("a"); return completed; };
|
||||
try { await h.controller.load("run"); await h.controller.approvePayment(); expect(h.view().state.media[0].status).toBe("ready"); expect(h.view().quote).toBeUndefined(); expect(h.counters().prepares).toBe(0); }
|
||||
finally { h.controller.dispose(); }
|
||||
});
|
||||
test("更新过期报价替换分析关联并等待新批准,不执行模型", async () => {
|
||||
const old = submission("old", "planning:key");
|
||||
const fresh = submission("fresh", "requote:old");
|
||||
|
||||
Reference in new issue
Block a user