Files
aigc-home/e2e/reference/check.cjs
T

363 lines
14 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const { chromium } = require(
process.env.PLAYWRIGHT_MODULE_PATH || "playwright",
);
const assert = require("node:assert/strict"),
fs = require("fs"),
path = require("path");
const root = path.resolve(__dirname, "../.."),
runtime = path.join(root, "e2e/shots/reference");
fs.mkdirSync(runtime, { recursive: true });
const f = JSON.parse(fs.readFileSync(path.join(runtime, "fixtures.json"))),
API = "http://127.0.0.1:8247",
WEB = "http://127.0.0.1:5173";
const modepath = path.join(root, "e2e/fake_mode.json"),
savedMode = fs.existsSync(modepath) ? fs.readFileSync(modepath) : null;
const checks = [],
errors = [];
const ok = (name, value) => {
assert(value, name);
checks.push(name);
console.log("PASS", name);
};
async function api(url, body, method) {
const r = await fetch(API + url, {
method: method || (body ? "POST" : "GET"),
headers: { "Content-Type": "application/json" },
body: body ? JSON.stringify(body) : undefined,
});
if (!r.ok) throw Error(url + " " + r.status + " " + (await r.text()));
return r.json();
}
async function wait(fn) {
const end = Date.now() + 18000;
while (Date.now() < end) {
const value = await fn();
if (value) return value;
await new Promise((r) => setTimeout(r, 150));
}
throw Error("condition timeout");
}
function mode(videos = false) {
fs.writeFileSync(
modepath,
JSON.stringify({
mode: "ok",
delay_sec: 0,
unique_filename: true,
videos,
image_file: path.join(root, "calliope-web/static/refract/coast.jpg"),
}),
);
}
(async () => {
let b;
try {
const config = await api("/api/settings");
assert.equal(
path.resolve(config.data_dir),
path.join(runtime, "data"),
"Run the dedicated e2e/reference/server.py before this writing test.",
);
b = await chromium.launch({
executablePath: process.env.CHROMIUM_EXECUTABLE_PATH,
args: ["--no-sandbox", "--disable-dev-shm-usage"],
});
const p = await b.newPage({ viewport: { width: 1440, height: 900 } });
p.on("pageerror", (e) => errors.push(e.message));
p.setDefaultTimeout(12000);
await p.goto(WEB + "/image?wf=" + f.dual);
await p.locator("#desk-negative").waitFor();
ok(
"真实工作流显示正反向左右分栏",
await p
.locator(".prompt-pair")
.evaluate(
(e) =>
getComputedStyle(e).gridTemplateColumns.split(" ").length === 2,
),
);
await p.locator("#desk-prompt").fill("正向草稿");
await p.locator("#desk-negative").fill("反向草稿");
ok(
"工作流列表可应对超过 48 项",
(await p.locator(".workflow-pick").count()) >= 48,
);
await p.locator(".rail-tools input").fill("Qwen");
ok(
"列表搜索过滤真实元数据",
(await p.locator(".workflow-pick").count()) === 1,
);
await p.locator(".row-actions button").first().click();
ok(
"置顶不切换工作流、不清空草稿",
(await p.locator("#desk-prompt").inputValue()) === "正向草稿",
);
await p
.getByRole("button", { name: "创作设置", exact: true })
.first()
.click();
await p.locator(".modal-panel input[type=number]").first().fill("99");
await p.getByRole("button", { name: "取消", exact: true }).click();
await p
.getByRole("button", { name: "创作设置", exact: true })
.first()
.click();
ok(
"参数取消不改当前值",
(await p
.locator(".modal-panel input[type=number]")
.first()
.inputValue()) === "42",
);
await p.locator(".modal-panel input[type=number]").first().fill("101");
await p.getByRole("button", { name: "保存设置", exact: true }).click();
await p
.getByRole("button", { name: "创作设置", exact: true })
.first()
.click();
ok(
"参数保存应用到当前工作流",
(await p
.locator(".modal-panel input[type=number]")
.first()
.inputValue()) === "101",
);
await p.keyboard.press("Escape");
const beforeImage = Math.max(
0,
...(await api("/api/playground/jobs")).map((j) => j.id),
);
mode();
await p.locator(".gen").click();
const job = await wait(async () => {
const rows = await api("/api/playground/jobs");
return rows.find(
(j) =>
j.id > beforeImage && j.workflow_id === f.dual && j.status === "done",
);
});
ok("真实生成请求提交且取得结果", !!job.output_paths[0]);
ok(
"正反向与种子写入任务",
JSON.stringify(job.payload).includes("正向草稿") &&
JSON.stringify(job.payload).includes("反向草稿") &&
JSON.stringify(job.payload).includes("101"),
);
await p.locator(".result-item").first().click();
await p.screenshot({ path: path.join(runtime, "正式施工-创作台.png") });
await p.goto(WEB + "/video?wf=" + f.h3);
await p.locator(".a-slot").filter({ hasText: "首帧" }).waitFor();
const first = p
.locator(".a-slot")
.filter({ has: p.getByText("首帧", { exact: true }) }),
last = p
.locator(".a-slot")
.filter({ has: p.getByText("尾帧", { exact: true }) });
await first
.locator("input[type=file]")
.setInputFiles(path.join(root, "calliope-web/static/refract/coast.jpg"));
await last
.locator("input[type=file]")
.setInputFiles(path.join(root, "calliope-web/static/refract/arch.jpg"));
await wait(
async () =>
(await first.locator("img").count()) &&
(await last.locator("img").count()),
);
ok("H3 首尾帧真实上传保留", true);
const beforeVideo = Math.max(
0,
...(await api("/api/playground/jobs")).map((j) => j.id),
);
mode(true);
await p.locator(".gen").click();
const video = await wait(async () => {
const rows = await api("/api/playground/jobs");
return rows.find(
(j) =>
j.id > beforeVideo && j.workflow_id === f.h3 && j.status === "done",
);
});
await p.locator(".result-item").first().click();
await p.locator(".main video").waitFor();
ok(
"视频默认暂停且不自动播放",
await p.locator(".main video").evaluate((v) => v.paused && !v.autoplay),
);
ok(
"播放按钮明确可见",
await p
.getByRole("button", { name: "播放视频", exact: true })
.isVisible(),
);
await p.setViewportSize({ width: 1280, height: 720 });
ok(
"小窗口播放键仍完整可见",
await p
.getByRole("button", { name: "播放视频", exact: true })
.evaluate((e) => {
const r = e.getBoundingClientRect();
return r.top >= 0 && r.bottom <= innerHeight && r.right <= innerWidth;
}),
);
await p.screenshot({ path: path.join(runtime, "正式施工-首尾帧视频.png") });
await p.goto(WEB + "/agents");
await p.getByRole("button", { name: /新任务/ }).click();
await p.locator(".agent-intro").waitFor();
ok(
"智能体独立主题页面",
await p
.locator(".agent-scene img")
.evaluate((e) => e.complete && e.naturalWidth > 0),
);
await p.locator(".agent-composer textarea").fill("故事草稿 A");
await p.locator(".agent-row").filter({ hasText: "视觉设计" }).click();
await p.locator(".agent-composer textarea").fill("视觉草稿 B");
await p.locator(".agent-row").filter({ hasText: "剧本创作" }).click();
ok(
"五个智能体各自保留草稿",
(await p.locator(".agent-composer textarea").inputValue()) ===
"故事草稿 A",
);
await p.locator(".agent-controls .agent-option").first().click();
await p.locator(".style-card").filter({ hasText: "日系动画" }).click();
await p.getByRole("button", { name: "取消", exact: true }).click();
ok(
"风格取消不应用",
(await p.locator(".agent-controls .agent-option").first().innerText()) ===
"治愈绘本",
);
await p.locator(".agent-controls .agent-option").first().click();
await p.locator(".style-card").filter({ hasText: "日系动画" }).click();
await p.getByRole("button", { name: "应用风格", exact: true }).click();
ok(
"风格应用保留任务",
(await p.locator(".agent-composer textarea").inputValue()) ===
"故事草稿 A",
);
await p
.getByRole("button", { name: /默认大模型⌄|隔离测试模型 B⌄/ })
.click();
await p
.locator(".model-choice")
.filter({ hasText: "隔离测试模型 B" })
.click();
await p.getByRole("button", { name: "应用模型", exact: true }).click();
await p.getByRole("button", { name: /隔离测试模型 B⌄/ }).waitFor();
ok(
"模型选择通过真实设置接口绑定",
Object.values(
(await api("/api/settings")).agent_llm_assignments,
).includes("reference-model-b"),
);
await p.getByRole("button", { name: /选择技能/ }).click();
await p.locator(".skill-choice").nth(1).click();
await p.getByRole("button", { name: "应用技能", exact: true }).click();
await p
.locator('select[aria-label="智能体关联项目"]')
.selectOption(String(f.project));
await p
.locator(".agent-composer input[type=file]")
.setInputFiles(path.join(root, "calliope-web/static/refract/coast.jpg"));
await p.locator(".agent-attachments img").waitFor();
await p.getByRole("button", { name: /引用工作流/ }).click();
await p
.locator(".modal-panel .model-choice")
.filter({ hasText: "Qwen·正反向测试" })
.click();
await p.locator(".agent-send").click();
const session = await wait(async () => {
const sessions = await api("/api/agent/sessions?agent_key=script");
return sessions
.filter((s) => s.project_id === f.project)
.sort((a, b) => b.id - a.id)[0];
});
const detail = await wait(async () => {
const d = await api("/api/agent/sessions/" + session.id);
return d.messages.some((m) => m.role === "assistant") ? d : null;
});
const message = detail.messages.find((m) => m.role === "user");
ok(
"真实消息包含风格与技能引用",
message.content.includes("日系动画") &&
message.mentions.some((m) => m.type === "skill") &&
message.mentions.some((m) => m.type === "workflow"),
);
ok("参考材料真实上传并随任务发送", message.attachments.length === 1);
ok(
"后端智能体回复呈现在对话",
detail.messages.some((m) => m.content.includes("隔离测试模型回复")),
);
await p
.getByText(/隔离测试模型回复/)
.first()
.waitFor();
await p.screenshot({ path: path.join(runtime, "正式施工-智能体对话.png") });
await p.getByRole("button", { name: /编辑内容并带回项目/ }).click();
await p
.locator("#agent-result-editor")
.fill(
"这是编辑后带回项目的故事文稿。小女孩把折好的纸船放进海面,海风吹了一整夜,第二天纸船带回一片银色的树叶。",
);
await p
.getByRole("button", { name: "保存到项目草稿", exact: true })
.click();
await p.waitForURL("**/workbench/" + f.project + "?stage=script");
const wb = await api("/api/workbench/projects/" + f.project);
ok(
"智能体结果真实保存为待确认项目草稿",
wb.stages
.find((s) => s.stage_key === "script")
.content.text.includes("编辑后带回项目") &&
wb.stages.find((s) => s.stage_key === "script").status ===
"awaiting_confirm",
);
await p.goto(WEB + "/agents");
await p.getByRole("button", { name: /新任务/ }).click();
await p.locator(".agent-intro").waitFor();
await p.setViewportSize({ width: 1600, height: 900 });
await p.screenshot({ path: path.join(runtime, "正式施工-智能体首页.png") });
await p.locator(".agent-controls .agent-option").first().click();
await p.screenshot({ path: path.join(runtime, "正式施工-风格选择.png") });
await p.keyboard.press("Escape");
await p.getByRole("button", { name: "智能体设置", exact: true }).click();
ok(
"技能管理和自定义编辑可访问",
await p
.getByRole("button", { name: "+ 自定义技能", exact: true })
.isVisible(),
);
await p.getByRole("button", { name: "+ 自定义技能", exact: true }).click();
await p.screenshot({ path: path.join(runtime, "正式施工-自定义技能.png") });
await p.keyboard.press("Escape");
await p.goto(WEB + "/workbench/" + f.project);
await p.locator("[data-testid=workbench-page]").waitFor();
ok(
"五阶段横向排列",
await p
.locator(".stepper")
.evaluate((e) => getComputedStyle(e).flexDirection === "row"),
);
ok(
"项目上下文与真实任务区保留",
(await p.locator(".side-col .side-card").count()) >= 2,
);
await p.screenshot({ path: path.join(runtime, "正式施工-项目工作台.png") });
await p.goto(WEB + "/");
await p.screenshot({ path: path.join(runtime, "正式施工-工作室.png") });
ok("没有页面脚本错误", errors.length === 0);
fs.writeFileSync(
path.join(runtime, "results.json"),
JSON.stringify({ checks, errors }, null, 2),
);
console.log("PASS TOTAL", checks.length);
} finally {
if (b) await b.close();
if (savedMode) fs.writeFileSync(modepath, savedMode);
else if (fs.existsSync(modepath)) fs.unlinkSync(modepath);
}
})().catch((e) => {
console.error(e);
process.exitCode = 1;
});