// Frozen original, before and after builds; isolated API, no external generation. const { chromium } = require( process.env.PLAYWRIGHT_MODULE_PATH || "playwright", ); const fs = require("node:fs"), path = require("node:path"), http = require("node:http"), assert = require("node:assert/strict"); const OUT = "../evidence/hel836"; fs.mkdirSync(OUT, { recursive: true }); const original = path.resolve( process.env.HEL836_ORIGINAL || "../originals/01a15a1e-dd09-719d-88ee-d05a5a67e5f6/夜片场-交互样本.html", ); const themed = path.resolve( process.env.HEL836_THEMED || "../originals/01a15ddb-c076-7a58-a0e0-72b98a338c63/夜片场-多主题交互样本.html", ); const { execFileSync } = require("node:child_process"); const API = "http://127.0.0.1:8247", WEB = "http://127.0.0.1:5173"; const report = { geometry: [], motion: [], checks: [], errors: [], mapping: {}, }; const check = (name, value) => { report.checks.push({ name, pass: !!value }); assert(value, name); console.log("PASS", name); }; const pause = (ms) => new Promise((r) => setTimeout(r, ms)); const api = async (p, b, method) => { const r = await fetch(API + p, { method: method || (b ? "POST" : "GET"), headers: { "Content-Type": "application/json" }, body: b ? JSON.stringify(b) : undefined, }); assert(r.ok, await r.clone().text()); return r.json(); }; const server = http.createServer((req, res) => { if (req.url.startsWith("/api/")) { const q = http.request( API + req.url, { method: req.method, headers: req.headers }, (r) => { res.writeHead(r.statusCode, r.headers); r.pipe(res); }, ); req.pipe(q); res.on("close", () => q.destroy()); q.on("error", () => res.end()); return; } if (req.url.startsWith("/sample")) { res.setHeader("Content-Type", "text/html;charset=utf-8"); res.end(fs.readFileSync(req.url.includes("716") ? original : themed)); return; } let file = path.join( path.resolve("../evidence/before/build"), decodeURIComponent(req.url.split("?")[0]), ); if (!fs.existsSync(file) || fs.statSync(file).isDirectory()) file = path.resolve("../evidence/before/build/index.html"); res.setHeader( "Content-Type", { ".js": "text/javascript", ".css": "text/css", ".html": "text/html", ".woff2": "font/woff2", ".svg": "image/svg+xml", ".jpg": "image/jpeg", }[path.extname(file)] || "application/octet-stream", ); fs.createReadStream(file).pipe(res); }); const sockets = new Set(); server.on("connection", (s) => { sockets.add(s); s.on("close", () => sockets.delete(s)); }); async function geometry(p, sample) { return p.evaluate((sample) => { const sel = sample ? { rail: ".wfb", head: ".cc>.ph", stage: ".stage", viewport: "#viewport", frame: ".frame", actions: "#actbar", dock: "#dock", slots: "#slots", positive: "#posTa", negative: "#negTa", params: ".pchip", gen: "#genBtn", history: ".hist", } : { rail: ".workflow-rail", head: ".studio-heading", stage: ".viewer", viewport: ".stage-media", frame: ".print", actions: ".artboard-footer", dock: ".dock .composer", slots: ".media-summary", positive: "#desk-prompt", negative: "#desk-negative", params: ".parameter", gen: ".gen", history: ".history-rail", }; return Object.fromEntries( Object.entries(sel).map(([k, s]) => { const e = document.querySelector(s); if (!e) return [k, null]; const r = e.getBoundingClientRect(), c = getComputedStyle(e); return [ k, { x: r.x, y: r.y, w: r.width, h: r.height, font: c.fontSize, weight: c.fontWeight, radius: c.borderRadius, border: c.borderTopWidth, padding: c.padding, }, ]; }), ); }, sample); } (async () => { await new Promise((r) => server.listen(0, "127.0.0.1", r)); const OLD = "http://127.0.0.1:" + server.address().port; const b = await chromium.launch({ args: ["--no-sandbox", "--disable-dev-shm-usage"], }); try { const ctx = await b.newContext({ viewport: { width: 1440, height: 900 } }); await ctx.addInitScript(() => localStorage.setItem("aigc-lang", "zh")); const p = await ctx.newPage(), before = await ctx.newPage(), s = await ctx.newPage(), v1 = await ctx.newPage(); for (const q of [p, before]) q.on("pageerror", (e) => report.errors.push(e.message)); await s.goto(OLD + "/sample726?still=1&fill=1#create/image"); await v1.goto(OLD + "/sample716?still=1&fill=1#create/image"); const data = await s.evaluate(async () => { const i = new Image(); i.src = st.hist.image[0].img; await i.decode(); const c = document.createElement("canvas"); c.width = i.naturalWidth; c.height = i.naturalHeight; c.getContext("2d").drawImage(i, 0, 0); const fills = {}; for (const [key, src] of Object.entries(st.fills[curWF().id])) { const img = new Image(); img.src = src; await img.decode(); const cv = document.createElement("canvas"); cv.width = img.naturalWidth; cv.height = img.naturalHeight; cv.getContext("2d").drawImage(img, 0, 0); fills[key] = cv.toDataURL("image/png"); } return { img: c.toDataURL("image/png"), pos: $("#posTa").value, neg: $("#negTa").value, wf: curWF(), fills, }; }); fs.writeFileSync( OUT + "/sample-media.png", Buffer.from(data.img.split(",")[1], "base64"), ); for (const old of await api("/api/playground/jobs")) await api("/api/playground/jobs/" + old.id, undefined, "DELETE"); const f = JSON.parse(fs.readFileSync("e2e/shots/reference/fixtures.json")); const base = await api("/api/workflows/" + f.dual); const wf = await api("/api/workflows", { name: data.wf.name, kind: "image", workflow_json: { ...base.workflow_json, 5: { class_type: "LoadImage", inputs: { image: "" }, _meta: { title: "(Input:image) 参考图" }, }, 6: { class_type: "LoadImageMask", inputs: { image: "", channel: "red" }, _meta: { title: "(Input:mask) 遮罩" }, }, }, }); const form = new FormData(); form.append( "file", new Blob([fs.readFileSync(OUT + "/sample-media.png")], { type: "image/png", }), "sample.png", ); const upload = await ( await fetch(API + "/api/playground/uploads", { method: "POST", body: form, }) ).json(); const filled = {}; for (const [key, src] of Object.entries(data.fills)) { const form = new FormData(); form.append( "file", new Blob([Buffer.from(src.split(",")[1], "base64")], { type: "image/png", }), key + ".png", ); filled[key] = await ( await fetch(API + "/api/playground/uploads", { method: "POST", body: form, }) ).json(); } fs.writeFileSync( "e2e/fake_mode.json", JSON.stringify({ mode: "ok", unique_filename: true, image_file: path.resolve(OUT + "/sample-media.png"), }), ); const j = await api("/api/playground/generate", { workflow_id: wf.id, input_values: { 1: data.pos, 2: data.neg, 3: 42, 5: Object.entries(filled).find(([key]) => key.startsWith("input"))[1] .path, 6: Object.entries(filled).find(([key]) => key.startsWith("mask"))[1] .path, }, }); let job; for (let i = 0; i < 150; i++) { job = (await api("/api/playground/jobs")).find((x) => x.id === j.job.id); if (job.status === "done") break; await pause(100); } assert.equal(job.status, "done"); await api( "/api/workflows/" + wf.id, { model_family: "Qwen", source_path: data.wf.file }, "PATCH", ); for (const q of [s, v1]) await q.evaluate((id) => { st.hist.image = [{ ...st.hist.image[0], n: id }]; renderCreate(); }, job.id); report.mapping = { workflow: wf.id, job: job.id, input_values: job.payload.input_values, original: data.wf, media: "same sample PNG through isolated real API", }; for (const q of [p, before]) { await q.goto((q === p ? WEB : OLD) + "/create?wf=" + wf.id); await q.locator("#desk-negative").waitFor(); await q .locator(".history-take") .filter({ hasText: "#" + job.id }) .click(); await q.getByRole("button", { name: "复用参数", exact: true }).click(); if ( await q .getByRole("button", { name: "返回当前创作", exact: true }) .count() ) await q .getByRole("button", { name: "返回当前创作", exact: true }) .click(); await q.locator(".print img").waitFor(); await q.locator(".print img").evaluate((e) => e.decode()); } const count = await p.locator(".workflow-pick").count(); await p.locator(".family-label").first().click(); check( "workflow family collapses without selecting another workflow", (await p.locator(".workflow-pick").count()) < count && (await p.locator(".model-selector").innerText()) === data.wf.name, ); await p.locator(".family-label").first().click(); check( "workflow family expands", (await p.locator(".workflow-pick").count()) === count, ); for (const q of [p, before]) { await q .locator(".workflow-row.selected .row-actions button") .first() .click(); await q.locator(".rail-list").evaluate((e) => (e.scrollTop = 0)); } for (const q of [p, before]) await q.locator("#desk-prompt").evaluate((e) => { e.blur(); e.scrollTop = 0; }); await pause(3500); for (const [width, height] of [ [1440, 900], [1366, 768], [1280, 720], ]) for (const theme of ["night", "day", "grade", "bluehour"]) { for (const q of [p, before, s, v1]) { await q.setViewportSize({ width, height }); await q.evaluate( (t) => (document.documentElement.dataset.theme = t), theme, ); } await s.evaluate(() => renderCreate()); await v1.evaluate(() => renderCreate()); await pause(350); const row = { width, height, theme, after: await geometry(p, false), before: await geometry(before, false), sample: await geometry(s, true), v1: await geometry(v1, true), }; report.geometry.push(row); for (const key of [ "head", "stage", "viewport", "actions", "dock", "positive", "negative", "history", ]) check( `${width}/${theme}/${key} geometry matches original`, ["x", "y", "w", "h"].every( (k) => Math.abs(row.after[key][k] - row.sample[key][k]) <= 1, ), ); check( `${width}/${theme} parameter capsules`, row.after.params.h === 28 && row.after.params.font === "12px", ); check( `${width}/${theme} no horizontal overflow`, await p.evaluate( () => document.documentElement.scrollWidth <= innerWidth, ), ); for (const [q, label] of [ [p, "after"], [before, "before"], [s, "726"], [v1, "716"], ]) if (theme === "night" || label !== "716") await q.screenshot({ path: `${OUT}/${width}-${theme}-${label}.png`, }); } // Same viewport parameter dialogs, historical state and landscape video. for (const [width, height] of [ [1440, 900], [1366, 768], [1280, 720], ]) for (const theme of ["night", "day", "grade", "bluehour"]) { for (const q of [p, before, s]) { await q.setViewportSize({ width, height }); await q.evaluate( (t) => (document.documentElement.dataset.theme = t), theme, ); } for (const q of [p, before]) await q .getByRole("button", { name: "创作设置⌄", exact: true }) .click(); await s.evaluate(() => openPop()); await pause(250); for (const [q, label] of [ [p, "after"], [before, "before"], [s, "726"], ]) await q.screenshot({ path: `${OUT}/params-${width}-${theme}-${label}.png`, }); const pop = await p.locator(".anchored .modal-panel").boundingBox(); check( `parameter dialog reachable ${width}/${theme}`, pop.y >= 0 && pop.x >= 0 && pop.x + pop.width <= width && pop.y + pop.height <= height, ); for (const q of [p, before]) await q.keyboard.press("Escape"); await s.evaluate(() => $("#paramPop").classList.remove("on")); } for (const q of [p, before]) await q .locator(".history-take") .filter({ hasText: "#" + job.id }) .click(); await s.evaluate(() => { st.viewing = st.hist.image[0]; renderHist(); renderViewport(); }); const currentInput = await p.locator("#desk-prompt").inputValue(); for (const [width, height] of [ [1440, 900], [1366, 768], [1280, 720], ]) for (const theme of ["night", "day", "grade", "bluehour"]) { for (const q of [p, before, s]) { await q.setViewportSize({ width, height }); await q.evaluate( (t) => (document.documentElement.dataset.theme = t), theme, ); } await pause(200); await s.evaluate(() => renderViewport()); for (const [q, label] of [ [p, "after"], [before, "before"], [s, "726"], ]) await q.screenshot({ path: `${OUT}/history-${width}-${theme}-${label}.png`, }); const actual = await geometry(p, false), sample = await geometry(s, true); report.geometry.push({ width, height, theme, state: "history", actual, sample, }); check( `history preserves input and stage geometry ${width}/${theme}`, currentInput === (await p.locator("#desk-prompt").inputValue()) && ["x", "y", "w", "h"].every( (k) => Math.abs(actual.viewport[k] - sample.viewport[k]) <= 1, ) && (await p .locator(".history-banner") .evaluate((e) => e.getBoundingClientRect().height === 34)), ); } for (const q of [p, before]) await q .getByRole("button", { name: "返回当前创作", exact: true }) .click(); await s.evaluate(() => { st.viewing = null; renderHist(); renderViewport(); }); // Fixture video uses the exact still from the original player; only playback is real. await s.evaluate(() => { st.kind = "video"; renderCreate(); }); const videoData = await s.evaluate(async () => { const it = st.hist.video[0], i = new Image(); i.src = it.img; await i.decode(); const c = document.createElement("canvas"); c.width = i.naturalWidth; c.height = i.naturalHeight; c.getContext("2d").drawImage(i, 0, 0); const fills = {}; for (const [key, src] of Object.entries(st.fills[curWF().id])) { const im = new Image(); im.src = src; await im.decode(); const cv = document.createElement("canvas"); cv.width = im.naturalWidth; cv.height = im.naturalHeight; cv.getContext("2d").drawImage(im, 0, 0); fills[key] = cv.toDataURL("image/png"); } return { img: c.toDataURL("image/png"), pos: prompts.video[0], neg: prompts.video[1], wf: curWF(), fills, }; }); fs.writeFileSync( OUT + "/video-still.png", Buffer.from(videoData.img.split(",")[1], "base64"), ); execFileSync( process.env.FFMPEG_BINARY || "ffmpeg", [ "-y", "-loop", "1", "-i", path.resolve(OUT + "/video-still.png"), "-t", "5", "-r", "12", "-pix_fmt", "yuv420p", path.resolve(OUT + "/sample.mp4"), ], { stdio: "ignore" }, ); fs.writeFileSync( "e2e/fake_mode.json", JSON.stringify({ mode: "ok", videos: true, unique_filename: true, video_file: path.resolve(OUT + "/sample.mp4"), }), ); const h3 = await api("/api/workflows/" + f.h3); const videoWF = await api("/api/workflows", { name: videoData.wf.name, kind: "video", workflow_json: { ...h3.workflow_json, 4: { class_type: "CLIPTextEncode", inputs: { text: videoData.neg }, _meta: { title: "(Input:negative) 反向提示词" }, }, }, }); await api( "/api/workflows/" + videoWF.id, { model_family: "MiniMax-H3", source_path: videoData.wf.file }, "PATCH", ); const vfill = {}; for (const [key, src] of Object.entries(videoData.fills)) { const form = new FormData(); form.append( "file", new Blob([Buffer.from(src.split(",")[1], "base64")], { type: "image/png", }), key + ".png", ); vfill[key] = await ( await fetch(API + "/api/playground/uploads", { method: "POST", body: form, }) ).json(); } const v = await api("/api/playground/generate", { workflow_id: videoWF.id, input_values: { 1: videoData.pos, 2: vfill.first0.path, 3: vfill.last0.path, 4: videoData.neg, }, }); let vjob; for (let i = 0; i < 150; i++) { vjob = (await api("/api/playground/jobs")).find((x) => x.id === v.job.id); if (vjob.status === "done") break; await pause(100); } assert.equal(vjob.status, "done"); for (const q of [p, before]) { await q.goto( (q === p ? WEB : OLD) + "/create?kind=video&wf=" + videoWF.id, ); await q .locator(".history-take") .filter({ hasText: "#" + vjob.id }) .click(); await q.getByRole("button", { name: "复用参数", exact: true }).click(); await q.locator(".print video").waitFor(); await q .locator(".print video") .evaluate( (v) => new Promise((r) => v.readyState >= 1 ? r() : v.addEventListener("loadedmetadata", r, { once: true }), ), ); } await s.evaluate((id) => { st.hist.video = [{ ...st.hist.video[0], n: id }]; $("#posTa").value = prompts.video[0]; renderCreate(); }, vjob.id); await pause(3500); for (const [width, height] of [ [1440, 900], [1366, 768], [1280, 720], ]) for (const theme of ["night", "day", "grade", "bluehour"]) { for (const q of [p, before, s]) { await q.setViewportSize({ width, height }); await q.evaluate( (t) => (document.documentElement.dataset.theme = t), theme, ); } await s.evaluate(() => renderCreate()); await pause(250); await s.evaluate(() => renderViewport()); for (const [q, label] of [ [p, "after"], [before, "before"], [s, "726"], ]) await q.screenshot({ path: `${OUT}/video-${width}-${theme}-${label}.png`, }); const frame = await p.locator(".print").boundingBox(), ref = await s.locator(".player").boundingBox(); report.geometry.push({ width, height, theme, state: "video", frame, ref, }); check( `video 40px controls and contain ${width}/${theme}`, (await p .locator(".player-controls") .evaluate((e) => e.getBoundingClientRect().height === 40)) && (await p .locator("video") .first() .evaluate( (v) => v.paused && getComputedStyle(v).objectFit === "contain", )), ); check( `video frame geometry ${width}/${theme}`, ["x", "y", "width", "height"].every( (k) => Math.abs(frame[k] - ref[k]) <= 1, ), ); } await p.getByRole("button", { name: "播放此视频", exact: true }).click(); await pause(500); check( "custom video button advances real playback", await p .locator(".print video") .evaluate((v) => !v.paused && v.currentTime > 0), ); await p.getByRole("button", { name: "暂停视频", exact: true }).click(); check( "custom pause works", await p.locator(".print video").evaluate((v) => v.paused), ); await p.locator(".player-seek").fill("2"); check( "seek updates real media", await p .locator(".print video") .evaluate((v) => Math.abs(v.currentTime - 2) < 0.1), ); await p.goto(WEB + "/agents"); await before.goto(OLD + "/agents"); await s.goto(OLD + "/sample726#agents"); await p.locator(".orb").waitFor(); await pause(400); for (const [q, label] of [ [p, "after"], [before, "before"], [s, "sample"], ]) { for (const t of [0, 3000, 9000]) { const r = await q.evaluate( (t) => [...document.querySelectorAll(".orb .ring")].map((e) => { const animations = e.getAnimations(); for (const a of animations) { a.pause(); a.currentTime = t; } const c = getComputedStyle(e), dot = getComputedStyle(e, "::before"), m = new DOMMatrix(c.transform), r = e.getBoundingClientRect(), w = e.offsetWidth, h = e.offsetHeight; const x = parseFloat(dot.left) + parseFloat(dot.width) / 2 - w / 2, y = parseFloat(dot.top) + parseFloat(dot.height) / 2 - h / 2; return { w, h, animation: c.animationName, count: animations.length, center: { x: r.x + r.width / 2, y: r.y + r.height / 2 }, dot: { x: r.x + r.width / 2 + m.a * x + m.c * y, y: r.y + r.height / 2 + m.b * x + m.d * y, }, transform: c.transform, }; }), t, ); report.motion.push({ label, t, rings: r }); await q.screenshot({ path: `${OUT}/rings-${label}-${t}.png` }); } } for (const row of report.motion.filter((r) => r.label === "after")) { const original = report.motion.find( (r) => r.label === "sample" && r.t === row.t, ); check( `ring paths match sample at ${row.t}ms`, row.rings.every( (r, i) => r.count === 1 && r.transform === original.rings[i].transform && r.w === original.rings[i].w && r.h === original.rings[i].h, ), ); } await p.evaluate(() => document.querySelectorAll(".orb .ring").forEach((e) => e.getAnimations().forEach((a) => { a.currentTime = 0; a.play(); }), ), ); const start = await p .locator(".orb .ring") .first() .evaluate((e) => getComputedStyle(e).transform); await pause(600); check( "rings advance with real elapsed time", (await p .locator(".orb .ring") .first() .evaluate((e) => getComputedStyle(e).transform)) !== start, ); await p.screenshot({ path: OUT + "/rings-natural-600ms.png" }); const mode = async (label) => { await p.getByRole("button", { name: "主题", exact: true }).click(); await p .locator(".theme-motion") .getByRole("button", { name: label, exact: true }) .click(); await p.keyboard.press("Escape"); }; await mode("克制"); check( "calm stops loops but keeps static rings", (await p.locator(".orb").isVisible()) && (await p.evaluate(() => document .querySelector(".orb") .getAnimations({ subtree: true }) .every((a) => a.playState !== "running"), )), ); await mode("关闭"); check("off hides decorative rings", !(await p.locator(".orb").isVisible())); await mode("完整"); await p.emulateMedia({ reducedMotion: "reduce" }); await p.waitForFunction( () => document.documentElement.dataset.motion === "off", ); check( "OS reduce overrides full without changing saved choice", await p.evaluate( () => document.documentElement.dataset.motion === "off" && localStorage.getItem("aigc-motion") === "full", ), ); await p.emulateMedia({ reducedMotion: "no-preference" }); await p.waitForFunction( () => document.documentElement.dataset.motion === "full", ); check( "OS restoration keeps preference", await p.evaluate( () => document.documentElement.dataset.motion === "full", ), ); check("no browser errors", report.errors.length === 0); fs.writeFileSync(OUT + "/report.json", JSON.stringify(report, null, 2)); console.log("CAPTURED", report.geometry.length, report.motion.length); for (const socket of sockets) socket.destroy(); await ctx.close(); } finally { fs.writeFileSync(OUT + "/report.json", JSON.stringify(report, null, 2)); await b.close(); for (const socket of sockets) socket.destroy(); await new Promise((r) => server.close(r)); } })().catch((e) => { console.error(e); process.exitCode = 1; });