50 lines
3.0 KiB
JavaScript
50 lines
3.0 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { dbRun } from "../server/db.mjs";
|
|
|
|
const api = process.env.AI_DRAMA_API_BASE || "http://127.0.0.1:8787";
|
|
const scope = { "x-organization-id": "org-studio-lab", "x-workspace-id": "ws-local-aidrama", "x-project-id": "thunder-mouth" };
|
|
|
|
async function request(path, headers, options = {}) {
|
|
const response = await fetch(`${api}${path}`, { ...options, headers: { "content-type": "application/json", ...(headers || {}), ...(options.headers || {}) } });
|
|
const payload = await response.json().catch(() => ({}));
|
|
return { response, payload };
|
|
}
|
|
|
|
async function login(email) {
|
|
const result = await request("/api/auth/login", null, { method: "POST", body: JSON.stringify({ email, password: "Demo@123456" }) });
|
|
assert.equal(result.response.ok, true, `${email} 登录失败`);
|
|
return { authorization: `Bearer ${result.payload.session.token}`, ...scope };
|
|
}
|
|
|
|
const owner = await login("producer@local.test");
|
|
const writer = await login("writer@local.test");
|
|
let runId = "";
|
|
|
|
try {
|
|
const templates = await request("/api/workflows/templates", owner);
|
|
assert.equal(templates.response.ok, true, "管理员读取流程模板失败");
|
|
const main = templates.payload.templates.find((template) => template.templateKey === "ai-manhua-drama");
|
|
assert.ok(main, "缺少 AI 漫剧主流程模板");
|
|
assert.equal(main.status, "active", "AI 漫剧主流程必须是 active");
|
|
assert.ok(main.steps.length >= 5, "流程模板必须包含可执行步骤");
|
|
|
|
const writerRead = await request("/api/workflows/templates", writer);
|
|
assert.equal(writerRead.response.ok, true, "普通生产成员应能读取可用模板");
|
|
const writerWrite = await request("/api/workflows/templates", writer, { method: "POST", body: JSON.stringify({ name: "越权模板", templateKey: "forbidden-template", steps: [{ label: "测试" }] }) });
|
|
assert.equal(writerWrite.response.status, 403, "普通生产成员不能创建工作区流程模板");
|
|
|
|
const plan = await request(`/api/workflows/templates/${encodeURIComponent(main.id)}/instantiate`, owner, { method: "POST", body: JSON.stringify({ mode: "plan", shotId: "shot-01" }) });
|
|
assert.equal(plan.response.status, 201, `流程计划创建失败:${plan.payload.detail || ""}`);
|
|
assert.equal(plan.payload.run.status, "planned", "计划模式不能直接排入任务队列");
|
|
assert.equal(plan.payload.jobs.length, 0, "计划模式不应创建 generation job");
|
|
assert.ok(plan.payload.run.steps.length >= 5, "流程运行记录必须保存步骤快照");
|
|
runId = plan.payload.run.id;
|
|
|
|
const runs = await request("/api/workflows/runs?limit=10", owner);
|
|
assert.equal(runs.response.ok, true, "流程运行记录读取失败");
|
|
assert.ok(runs.payload.runs.some((run) => run.id === runId), "流程运行记录没有按项目 scope 返回");
|
|
console.log(`workflow platform smoke passed: ${main.name} / ${plan.payload.run.steps.length} steps`);
|
|
} finally {
|
|
if (runId) dbRun("DELETE FROM workflow_runs WHERE id = ?", [runId]);
|
|
}
|