/** Run via verify-hel751.py; explicit API fake, local-only origins, no user data. */ import fs from "node:fs/promises"; import http from "node:http"; import path from "node:path"; import { pathToFileURL } from "node:url"; const { chromium } = await import( process.env.PLAYWRIGHT_MODULE || "playwright" ); const out = process.env.HEL751_OUT, data = process.env.HEL751_DATA; const fixture = JSON.parse( await fs.readFile(path.join(data, "fixtures.json"), "utf8"), ); let jobs = structuredClone(fixture.jobs), apiError = false, imageFixture; const result = { checks: [], measurements: [], errors: [], mutations: [], externalBlocked: [], apiReads: [], }; const check = (v, n) => { result.checks.push({ name: n, pass: !!v }); if (!v) throw Error(n); }; const server = http.createServer(async (req, res) => { try { const p = new URL(req.url, "http://local").pathname; let f = path.join("calliope-web/build", decodeURIComponent(p)); if (!path.extname(f)) f = path.join("calliope-web/build", "index.html"); const bytes = await fs.readFile(f); res.setHeader( "Content-Type", f.endsWith(".js") ? "text/javascript" : f.endsWith(".css") ? "text/css" : f.endsWith(".html") ? "text/html" : "application/octet-stream", ); res.end(bytes); } catch { res.writeHead(404); res.end(); } }); await new Promise((r) => server.listen(0, "127.0.0.1", r)); const base = `http://127.0.0.1:${server.address().port}`; const browser = await chromium.launch({ headless: true, args: ["--no-sandbox"], }); try { const context = await browser.newContext({ viewport: { width: 1440, height: 900 }, timezoneId: "Asia/Shanghai", recordVideo: { dir: path.join(out, "recordings"), size: { width: 1440, height: 900 }, }, }); await context.addInitScript(() => { localStorage.setItem("aigc-lang", "zh"); localStorage.setItem("aigc-reduce-motion", "1"); window.__sse = []; window.EventSource = class { constructor() { window.__sse.push(this); setTimeout(() => this.onopen?.(), 0); } addEventListener(t, f) { (this.handlers ??= {})[t] = f; } close() {} }; }); await context.route("**/*", async (route) => { const req = route.request(), u = new URL(req.url()); if (["data:", "blob:", "file:"].includes(u.protocol)) return route.continue(); if (u.origin !== base) { result.externalBlocked.push(u.origin); return route.abort(); } if (!u.pathname.startsWith("/api/")) return route.continue(); const json = (body) => route.fulfill({ json: body }); if (u.pathname === "/api/file") { if (u.searchParams.get("path")?.endsWith(".mp4")) { const bytes = await fs.readFile(path.join(data, "video.mp4")); const range = req.headers()["range"]?.match(/bytes=(\d+)-(\d*)/); if (range) { const start = +range[1], end = range[2] ? Math.min(+range[2], bytes.length - 1) : bytes.length - 1; return route.fulfill({ status: 206, body: bytes.subarray(start, end + 1), contentType: "video/mp4", headers: { "Accept-Ranges": "bytes", "Content-Range": `bytes ${start}-${end}/${bytes.length}`, "Content-Length": String(end - start + 1), }, }); } return route.fulfill({ body: bytes, contentType: "video/mp4", headers: { "Accept-Ranges": "bytes", "Content-Length": String(bytes.length), }, }); } return route.fulfill({ body: imageFixture || Buffer.from( "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jR1kAAAAASUVORK5CYII=", "base64", ), contentType: "image/png", }); } if (req.method() !== "GET") { result.mutations.push({ path: u.pathname, method: req.method() }); const m = u.pathname.match(/^\/api\/jobs\/(\d+)\/(cancel|retry)$/); if (m) { const j = jobs.find((j) => j.id === +m[1]); j.status = m[2] === "cancel" ? "failed" : "pending"; j.error = m[2] === "cancel" ? "cancelled" : null; return json(j); } const d = u.pathname.match(/^\/api\/playground\/jobs\/(\d+)$/); if (d && req.method() === "DELETE") { jobs = jobs.filter((j) => j.id !== +d[1]); return json({ ok: true }); } if (u.pathname.includes("test")) return json({ ok: true }); throw Error(`Unexpected mutation ${req.method()} ${u.pathname}`); } result.apiReads.push(u.pathname); if (u.pathname === "/api/jobs") { if (apiError) return route.fulfill({ status: 500, body: "HEL751 isolated error" }); return json(jobs); } if (u.pathname === "/api/workflows") return json(fixture.workflows); if (u.pathname === "/api/projects") return json([{ id: 1, title: "雾港来信" }]); if (u.pathname === "/api/settings") return json({ comfyui_endpoints: [], llm_profiles: [], queue_concurrency: 1, dry_run: false, }); if (u.pathname === "/api/comfyui/endpoints") return json({ endpoints: [], active_id: null }); if (u.pathname.includes("/jobs")) return json([]); if (u.pathname.includes("/sessions")) return json([]); if ( u.pathname === "/api/library/media" || u.pathname === "/api/agent/agents" || u.pathname === "/api/agent/memories" ) return json([]); const wf = u.pathname.match(/^\/api\/workflows\/(\d+)$/); if (wf) return json({ ...fixture.workflows.find((w) => w.id === +wf[1]), workflow_json: {}, output_map: [ { nodeId: "2", kind: fixture.workflows.find((w) => w.id === +wf[1]).kind, }, ], }); return json({}); }); const page = await context.newPage(); page.on("pageerror", (e) => result.errors.push(e.message)); const ref = await context.newPage(); await ref.goto( pathToFileURL(path.resolve("../attachments/夜片场-多主题交互样本.html")) .href, ); await ref.evaluate(() => { go("tasks"); document.documentElement.classList.add("capture"); }); // Reuse the corresponding original synthetic still only inside this API fake. // Canvas avoids capturing a parent page during its opacity entrance animation. imageFixture = Buffer.from( await ref.evaluate(async () => { const img = new Image(); img.src = still(64, 96, 64); await img.decode(); const canvas = document.createElement("canvas"); canvas.width = 48; canvas.height = 32; canvas.getContext("2d").drawImage(img, 0, 0, 48, 32); return canvas.toDataURL("image/png").split(",")[1]; }), "base64", ); const progress = () => page.evaluate(() => { for (const es of window.__sse) for (const [id, pct] of [ [1, 62], [2, 35], ]) es.handlers?.["job.progress"]?.({ data: JSON.stringify({ type: "job.progress", data: { job_id: id, progress: pct, phase: "comfy_running" }, }), }); }); const measure = (p, selectors) => p.evaluate( (selectors) => Object.fromEntries( Object.entries(selectors).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, width: r.width, height: r.height, font: c.fontSize, radius: c.borderRadius, color: c.color, background: c.backgroundColor, }, ]; }), ), selectors, ); for (const [width, height] of process.env.HEL751_SKIP_VISUAL ? [] : [ [1440, 900], [1366, 768], [1280, 720], ]) for (const theme of ["night", "day", "grade", "bluehour"]) { await page.setViewportSize({ width, height }); await ref.setViewportSize({ width, height }); await page.goto(base + "/tasks"); await page.locator(".task-table tbody tr").first().waitFor(); await progress(); await page.evaluate((theme) => { localStorage.setItem("aigc-theme", theme); window.dispatchEvent( new StorageEvent("storage", { key: "aigc-theme", newValue: theme }), ); }, theme); await ref.evaluate((theme) => setTheme(theme), theme); await page.waitForTimeout(650); const name = `tasks-${theme}-${width}`; await page.screenshot({ path: path.join(out, name + "-actual.png") }); await ref.screenshot({ path: path.join(out, name + "-sample.png") }); result.measurements.push({ theme, width, height, actual: await measure(page, { header: ".management-header", table: ".task-table", head: ".task-table thead", row: ".task-table tbody tr", thumbnail: ".task-thumbnail", segment: ".task-tabs", search: ".task-search", progress: ".task-progress", tag: ".task-table .mg-tag", }), sample: await measure(ref, { header: "#p-tasks .ph", table: "#p-tasks .tbl", head: "#p-tasks thead", row: "#taskTable tr", thumbnail: "#taskTable td>div", segment: "#p-tasks .seg", search: "#p-tasks .input", progress: "#taskTable .bar", tag: "#taskTable .tag", }), }); const measured = result.measurements.at(-1); for (const key of [ "header", "table", "head", "row", "thumbnail", "segment", "search", "progress", ]) for (const axis of ["width", "height"]) check( Math.abs(measured.actual[key][axis] - measured.sample[key][axis]) < 0.1, `${name}: ${key} ${axis} matches sample`, ); check( (await page.locator(".mg-side,.mg-detail").count()) === 0, `${name}: no permanent sidebars`, ); check( await page.evaluate( () => document.documentElement.scrollWidth <= innerWidth, ), `${name}: no document overflow`, ); } await page.setViewportSize({ width: 1440, height: 900 }); if (process.env.HEL751_SKIP_VISUAL) { await page.goto(base + "/tasks"); await page.locator("tbody tr").first().waitFor(); } await page.locator(".task-tabs button").nth(1).click(); check((await page.locator("tbody tr").count()) === 3, "active filter"); await page.locator(".task-tabs button").nth(2).click(); check((await page.locator("tbody tr").count()) === 1, "failed filter"); await page.locator(".task-tabs button").nth(3).click(); check((await page.locator("tbody tr").count()) === 3, "image filter"); await page.locator(".task-tabs button").nth(4).click(); check((await page.locator("tbody tr").count()) === 3, "video filter"); await page.locator(".task-tabs button").first().click(); await page.getByRole("searchbox").fill("镜头 07"); await page.waitForTimeout(100); check((await page.locator("tbody tr").count()) === 1, "search by task title"); await page.getByRole("searchbox").fill("HEL751 absent"); await page.waitForTimeout(100); check((await page.locator("tbody tr").count()) === 0, "search empty"); await page.screenshot({ path: path.join(out, "search-empty.png") }); await page.getByRole("searchbox").fill(""); await page.getByRole("button", { name: "查看任务 #6", exact: true }).click(); await page.getByRole("dialog").waitFor(); const video = page.locator("video"); await video.evaluate( (v) => new Promise((r) => v.readyState >= 1 ? r() : v.addEventListener("loadedmetadata", r, { once: true }), ), ); check( await video.evaluate( (v) => v.paused && v.controls && !v.autoplay && !v.muted && v.volume === 1, ), "video manual playback with sound", ); await video.hover(); const videoBox = await video.boundingBox(); await video.click({ position: { x: 26, y: videoBox.height - 28 } }); await page.waitForTimeout(250); check( await video.evaluate((v) => !v.paused && v.currentTime > 0), "explicit video play", ); await video.evaluate((v) => { v.pause(); v.currentTime = 0.7; v.volume = 0.4; }); await page.waitForTimeout(300); result.videoState = await video.evaluate((v) => ({ paused: v.paused, time: v.currentTime, volume: v.volume, duration: v.duration, seekable: v.seekable.length, error: v.error?.message, })); check( result.videoState.paused && result.videoState.time > 0.6 && Math.abs(result.videoState.volume - 0.4) < 0.001, "pause seek volume", ); await page.screenshot({ path: path.join(out, "video-preview.png") }); await page.keyboard.press("Tab"); check( await page .getByRole("dialog") .evaluate((e) => e.contains(document.activeElement)), "modal focus stays inside", ); await page.getByRole("dialog").locator(".modal-close").focus(); await page.keyboard.press("Escape"); await page.getByRole("dialog").waitFor({ state: "hidden" }); check((await page.locator("video").count()) === 0, "close unmounts video"); check( await page .getByRole("button", { name: "查看任务 #6", exact: true }) .evaluate((e) => e === document.activeElement), "modal restores trigger focus", ); await page.getByRole("button", { name: "查看任务 #5", exact: true }).click(); await page.getByRole("dialog").waitFor(); check( (await page.getByRole("dialog").locator("img").count()) === 1, "image preview", ); const [download] = await Promise.all([ page.waitForEvent("download"), page.getByRole("link", { name: "下载", exact: true }).click(), ]); check(!(await download.failure()), "native image download"); await download.saveAs(path.join(out, "downloaded-fixture.png")); await page.getByRole("button", { name: "删除", exact: true }).click(); check( (await page.locator("tbody tr").count()) === 5, "delete removes row immediately", ); await page.getByRole("button", { name: "撤销", exact: true }).click(); check((await page.locator("tbody tr").count()) === 6, "undo restores row"); check( !result.mutations.some((m) => m.method === "DELETE"), "undo prevents DELETE", ); await page.getByRole("button", { name: "查看任务 #5", exact: true }).click(); await page.getByRole("button", { name: "删除", exact: true }).click(); await page.waitForTimeout(5300); check( result.mutations.some((m) => m.method === "DELETE"), "delete commits after undo window", ); await page .locator("tbody tr") .filter({ hasText: "参考生视频 #21" }) .getByRole("button", { name: "重试", exact: true }) .click(); await page.waitForTimeout(150); check( jobs.find((j) => j.id === 4).status === "pending", "retry uses real API contract", ); await page .locator("tbody tr") .filter({ hasText: "Qwen 局部重绘" }) .getByRole("button", { name: "取消", exact: true }) .click(); await page.waitForTimeout(150); check( jobs.find((j) => j.id === 3).error === "cancelled", "cancel uses real API contract", ); await page.getByRole("button", { name: "查看任务 #1", exact: true }).click(); await page.getByRole("button", { name: "创作台", exact: true }).click(); check( (await page.locator("tbody tr").count()) === 2, "source filter retained in details", ); await page.getByRole("button", { name: "全部来源", exact: true }).click(); const testJob = { ...structuredClone(fixture.jobs[4]), id: 8, origin: "workflow_test", payload: { source: "workflow_test", title: "HEL751 workflow test" }, output_paths: ["HEL751-fixture-4.png"], }; jobs.push(testJob); await page.goto(base + "/tasks"); await page.getByRole("button", { name: "查看任务 #8", exact: true }).click(); await page.getByRole("button", { name: "工作流试跑", exact: true }).click(); check( (await page.locator("tbody tr").count()) === 1, "workflow test source isolated", ); await page.getByRole("button", { name: "全部来源", exact: true }).click(); // Pending/running without a numeric report must remain unknown. await page.goto(base + "/tasks"); await page.locator("tbody tr").first().waitFor(); check( (await page.locator(".task-progress").count()) === 0, "no fabricated percentages after reload", ); jobs = []; await page.goto(base + "/tasks"); await page.waitForTimeout(400); check((await page.locator("tbody tr").count()) === 0, "true empty data"); await page.screenshot({ path: path.join(out, "true-empty.png") }); apiError = true; await page.goto(base + "/tasks"); await page .getByRole("alert") .filter({ hasText: "任务加载失败" }) .waitFor({ timeout: 15000 }); check(true, "API failure shown honestly"); apiError = false; jobs = structuredClone(fixture.jobs); await page.getByRole("button", { name: "重试", exact: true }).click(); await page.locator("tbody tr").first().waitFor(); check(true, "load retry restores tasks"); for (const route of [ "workflows", "connections", "library", "settings", "create?kind=image", "create?kind=video", ]) { await page.goto(base + "/" + route); await page.waitForTimeout(400); await page.screenshot({ path: path.join(out, "regression-" + route.replace(/\W/g, "-") + ".png"), }); check( (await page.locator(".task-table").count()) === 0, `${route}: task table styles scoped`, ); if (route.startsWith("create?")) { const textarea = page.locator(".studio-form textarea").first(); await textarea.fill("HEL751 isolated creative draft"); check( (await textarea.inputValue()) === "HEL751 isolated creative draft", `${route}: prompt remains editable`, ); await page.reload(); await page.locator(".studio-form textarea").first().waitFor(); check( (await page.locator(".studio-form textarea").first().inputValue()) === "HEL751 isolated creative draft", `${route}: draft survives reload`, ); } if (route === "workflows") check( (await page .locator(".mg-side") .evaluate((e) => e.getBoundingClientRect().width)) === 220, "workflow sidebar retains 220px", ); } check(result.errors.length === 0, "no browser page errors"); await context.close(); } finally { await fs.writeFile( path.join(out, "results.json"), JSON.stringify(result, null, 2), ); await browser.close(); await new Promise((r) => server.close(r)); }