feat(HEL-728): establish approved themes and compatible studio navigation
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
+397
@@ -0,0 +1,397 @@
|
||||
// B0 state preservation and navigation checks on the disposable reference stack.
|
||||
const { chromium } = require(
|
||||
process.env.PLAYWRIGHT_MODULE_PATH || "playwright",
|
||||
);
|
||||
const assert = require("node:assert/strict"),
|
||||
fs = require("node:fs"),
|
||||
path = require("node:path");
|
||||
const out = path.resolve("e2e/shots/hel728"),
|
||||
f = JSON.parse(fs.readFileSync("e2e/shots/reference/fixtures.json"));
|
||||
const WEB = "http://127.0.0.1:5173",
|
||||
API = "http://127.0.0.1:8247";
|
||||
const themes = ["night", "day", "grade", "bluehour"],
|
||||
names = ["夜片场", "日光棚", "调色间", "蓝调时刻"];
|
||||
const checks = [];
|
||||
function ok(name, value) {
|
||||
assert(value, name);
|
||||
checks.push(name);
|
||||
console.log("PASS", name);
|
||||
}
|
||||
async function change(p, id) {
|
||||
await p.getByRole("button", { name: "主题", exact: true }).click();
|
||||
await p
|
||||
.locator(".choice")
|
||||
.filter({ hasText: names[themes.indexOf(id)] })
|
||||
.click();
|
||||
await p.keyboard.press("Escape");
|
||||
await p.waitForFunction(
|
||||
(id) => document.documentElement.dataset.theme === id,
|
||||
id,
|
||||
);
|
||||
}
|
||||
async function waitJob(id) {
|
||||
for (let i = 0; i < 120; i++) {
|
||||
const j = (
|
||||
await fetch(API + "/api/playground/jobs").then((r) => r.json())
|
||||
).find((j) => j.id === id);
|
||||
assert(j, "submitted job remains in queue");
|
||||
if (j.status === "done") return j;
|
||||
assert(!["failed", "cancelled"].includes(j.status), JSON.stringify(j));
|
||||
await new Promise((r) => setTimeout(r, 200));
|
||||
}
|
||||
throw Error("job timed out");
|
||||
}
|
||||
(async () => {
|
||||
const browser = await chromium.launch({
|
||||
executablePath: process.env.CHROMIUM_EXECUTABLE_PATH,
|
||||
headless: true,
|
||||
args: ["--no-sandbox"],
|
||||
});
|
||||
const errors = [];
|
||||
const modepath = "e2e/fake_mode.json",
|
||||
saved = fs.existsSync(modepath) ? fs.readFileSync(modepath) : null;
|
||||
try {
|
||||
const context = await browser.newContext({
|
||||
viewport: { width: 1440, height: 900 },
|
||||
}),
|
||||
p = await context.newPage();
|
||||
p.on(
|
||||
"pageerror",
|
||||
(e) => (errors.push(e.message), console.error("PAGEERROR", e.stack)),
|
||||
);
|
||||
await p.goto(WEB + "/image?wf=" + f.dual);
|
||||
await p.locator("#desk-prompt").waitFor();
|
||||
ok(
|
||||
"默认主题为夜片场",
|
||||
await p.evaluate(
|
||||
() => document.documentElement.dataset.theme === "night",
|
||||
),
|
||||
);
|
||||
await p.locator("#desk-prompt").fill("切换主题时保留的半篇提示词");
|
||||
await p.locator("#desk-negative").fill("反向草稿");
|
||||
await p
|
||||
.locator("#desk-prompt")
|
||||
.evaluate((e) => (window.__promptElement = e));
|
||||
for (const id of themes) {
|
||||
await change(p, id);
|
||||
ok(
|
||||
id + " 保留原编辑组件和正反向草稿",
|
||||
(await p
|
||||
.locator("#desk-prompt")
|
||||
.evaluate(
|
||||
(e) =>
|
||||
e === window.__promptElement &&
|
||||
e.value === "切换主题时保留的半篇提示词",
|
||||
)) && (await p.locator("#desk-negative").inputValue()) === "反向草稿",
|
||||
);
|
||||
}
|
||||
await p.reload();
|
||||
await p.locator("#desk-prompt").waitFor();
|
||||
ok(
|
||||
"刷新恢复主题和草稿",
|
||||
(await p.evaluate(
|
||||
() => document.documentElement.dataset.theme === "bluehour",
|
||||
)) &&
|
||||
(await p.locator("#desk-prompt").inputValue()) ===
|
||||
"切换主题时保留的半篇提示词",
|
||||
);
|
||||
// Keyboard selection and focus return use the existing layered Modal.
|
||||
const trigger = p.getByRole("button", { name: "主题", exact: true });
|
||||
await trigger.click();
|
||||
await p.locator(".choice").first().focus();
|
||||
await p.keyboard.press("ArrowDown");
|
||||
ok(
|
||||
"方向键移动主题选项焦点",
|
||||
await p
|
||||
.locator(".choice")
|
||||
.nth(1)
|
||||
.evaluate((e) => document.activeElement === e),
|
||||
);
|
||||
await p.keyboard.press("Enter");
|
||||
await p.keyboard.press("Escape");
|
||||
ok(
|
||||
"Esc 关闭并恢复入口焦点",
|
||||
await trigger.evaluate((e) => document.activeElement === e),
|
||||
);
|
||||
// All source URL parameters survive the temporary gateway.
|
||||
const q = new URLSearchParams({
|
||||
kind: "video",
|
||||
wf: String(f.h3),
|
||||
from: "workbench",
|
||||
project: String(f.project),
|
||||
stage: "shot",
|
||||
source_kind: "shot",
|
||||
source_id: "s1",
|
||||
label: "镜头一",
|
||||
prompt: "上下文提示词",
|
||||
negative: "上下文反向",
|
||||
duration: "6",
|
||||
mode: "image2video",
|
||||
});
|
||||
await p.goto(WEB + "/create?" + q + "#source");
|
||||
await p.locator("#desk-prompt").waitFor();
|
||||
ok(
|
||||
"创作台兼容入口保留全部参数及片段",
|
||||
new URL(p.url()).pathname === "/video" &&
|
||||
[...q].every(([k, v]) => new URL(p.url()).searchParams.get(k) === v) &&
|
||||
new URL(p.url()).hash === "#source",
|
||||
);
|
||||
await p.goto(WEB + "/video?wf=" + f.h3);
|
||||
await p.getByRole("button", { name: "管理素材", exact: true }).click();
|
||||
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.waitFor();
|
||||
await first
|
||||
.locator("input[type=file]")
|
||||
.setInputFiles("calliope-web/static/refract/coast.jpg");
|
||||
await last
|
||||
.locator("input[type=file]")
|
||||
.setInputFiles("calliope-web/static/refract/arch.jpg");
|
||||
await first.locator("img").waitFor();
|
||||
await last.locator("img").waitFor();
|
||||
await p.locator("#desk-prompt").fill("上传和进行中任务保留");
|
||||
const sources = [
|
||||
await first.locator("img").getAttribute("src"),
|
||||
await last.locator("img").getAttribute("src"),
|
||||
];
|
||||
await p.getByRole("button", { name: "完成", exact: true }).click();
|
||||
await p.locator("#desk-prompt").evaluate((e) => (window.__videoPrompt = e));
|
||||
fs.writeFileSync(
|
||||
modepath,
|
||||
JSON.stringify({ mode: "ok", delay_sec: 12, videos: true }),
|
||||
);
|
||||
const response = p.waitForResponse(
|
||||
(r) =>
|
||||
r.url().endsWith("/api/playground/generate") &&
|
||||
r.request().method() === "POST",
|
||||
);
|
||||
await p.locator(".gen").click();
|
||||
const job = (await (await response).json()).job;
|
||||
ok("隔离真实队列已收到任务", !!job.id);
|
||||
for (const id of themes) {
|
||||
await change(p, id);
|
||||
ok(
|
||||
id + " 上传素材和运行中编辑状态保留",
|
||||
(await p.locator(".media-token img").nth(0).getAttribute("src")) ===
|
||||
sources[0] &&
|
||||
(await p.locator(".media-token img").nth(1).getAttribute("src")) ===
|
||||
sources[1] &&
|
||||
(await p
|
||||
.locator("#desk-prompt")
|
||||
.evaluate(
|
||||
(e) =>
|
||||
e === window.__videoPrompt &&
|
||||
e.value === "上传和进行中任务保留",
|
||||
)),
|
||||
);
|
||||
}
|
||||
const completed = await waitJob(job.id);
|
||||
ok(
|
||||
"切主题后原任务完成且产物归属不变",
|
||||
completed.workflow_id === f.h3 && completed.output_paths.length > 0,
|
||||
);
|
||||
await p.locator(".artboard video").waitFor();
|
||||
await change(p, "day");
|
||||
ok(
|
||||
"切主题保留视频节点和暂停状态",
|
||||
await p
|
||||
.locator(".artboard video")
|
||||
.evaluate((v) => v.paused && !v.autoplay),
|
||||
);
|
||||
await p.screenshot({ path: path.join(out, "uploaded-video-state.png") });
|
||||
await p.goto(WEB + "/agents");
|
||||
await p.locator(".agent-composer textarea").fill("智能体任务输入草稿");
|
||||
await p
|
||||
.locator(".agent-composer textarea")
|
||||
.evaluate((e) => (window.__agentElement = e));
|
||||
await change(p, "night");
|
||||
ok(
|
||||
"切主题保留智能体任务输入组件和草稿",
|
||||
await p
|
||||
.locator(".agent-composer textarea")
|
||||
.evaluate(
|
||||
(e) =>
|
||||
e === window.__agentElement && e.value === "智能体任务输入草稿",
|
||||
),
|
||||
);
|
||||
// Preserve dirty settings separately from the appearance section.
|
||||
await p.goto(WEB + "/settings");
|
||||
await p.locator("input[type=number]").first().fill("2");
|
||||
await change(p, "grade");
|
||||
ok(
|
||||
"切主题保留未保存设置",
|
||||
(await p.locator("input[type=number]").first().inputValue()) === "2",
|
||||
);
|
||||
await p.getByRole("button", { name: "放弃", exact: true }).click();
|
||||
await p.goto(WEB + "/settings?tab=appearance");
|
||||
await p.locator(".choices").waitFor();
|
||||
await p.emulateMedia({ reducedMotion: "reduce" });
|
||||
for (const size of [
|
||||
[1440, 900],
|
||||
[1366, 768],
|
||||
[1280, 720],
|
||||
]) {
|
||||
await p.setViewportSize({ width: size[0], height: size[1] });
|
||||
for (const id of themes) {
|
||||
await p
|
||||
.locator(".choice")
|
||||
.filter({ hasText: names[themes.indexOf(id)] })
|
||||
.click();
|
||||
ok(
|
||||
`${size} ${id} 导航入口和四主题完整可见`,
|
||||
(await p
|
||||
.locator(".sidebar")
|
||||
.evaluate((e) => e.scrollHeight <= e.clientHeight + 1)) &&
|
||||
(await p
|
||||
.locator(".choices")
|
||||
.evaluate((e) => e.getBoundingClientRect().right <= innerWidth)),
|
||||
);
|
||||
await p.screenshot({
|
||||
path: path.join(out, `${id}-${size[0]}x${size[1]}.png`),
|
||||
});
|
||||
}
|
||||
}
|
||||
await p.goto(WEB + "/model-connections?tab=llm&keep=hello#models");
|
||||
await p.locator(".sidebar").waitFor();
|
||||
ok(
|
||||
"模型连接入口保留页签参数",
|
||||
new URL(p.url()).pathname === "/models" &&
|
||||
new URL(p.url()).searchParams.get("keep") === "hello" &&
|
||||
new URL(p.url()).hash === "#models",
|
||||
);
|
||||
await p.goto(
|
||||
WEB + "/project/" + f.project + "?stage=assets&keep=source#draft",
|
||||
);
|
||||
await p.locator(".sidebar").waitFor();
|
||||
ok(
|
||||
"旧项目链接保留阶段参数",
|
||||
new URL(p.url()).pathname === "/workbench/" + f.project &&
|
||||
new URL(p.url()).searchParams.get("keep") === "source" &&
|
||||
new URL(p.url()).hash === "#draft",
|
||||
);
|
||||
// Explicit legacy tools remain searchable until B1/B2 relocate them.
|
||||
await p.keyboard.press("Control+k");
|
||||
for (const label of ["视频创作", "大语言模型", "试验台", "三维搭景"])
|
||||
ok(
|
||||
"全局搜索保留 " + label,
|
||||
(await p.getByRole("option").filter({ hasText: label }).count()) > 0,
|
||||
);
|
||||
await p.keyboard.press("Escape");
|
||||
// Block framework scripts to verify the remembered theme before hydration.
|
||||
const colours = [
|
||||
"rgb(7, 8, 12)",
|
||||
"rgb(233, 228, 218)",
|
||||
"rgb(27, 27, 28)",
|
||||
"rgb(10, 16, 41)",
|
||||
];
|
||||
for (let n = 0; n < themes.length; n++) {
|
||||
const cold = await browser.newContext();
|
||||
await cold.addInitScript(
|
||||
(id) => localStorage.setItem("aigc-theme", id),
|
||||
themes[n],
|
||||
);
|
||||
const coldPage = await cold.newPage();
|
||||
await coldPage.route("**/*", (route) =>
|
||||
route.request().resourceType() === "script"
|
||||
? route.abort()
|
||||
: route.continue(),
|
||||
);
|
||||
await coldPage.goto(WEB + "/", { waitUntil: "domcontentloaded" });
|
||||
ok(
|
||||
themes[n] + " 首次绘制前恢复主题及底色",
|
||||
await coldPage.evaluate(
|
||||
({ id, colour }) =>
|
||||
document.documentElement.dataset.theme === id &&
|
||||
getComputedStyle(document.documentElement).backgroundColor ===
|
||||
colour &&
|
||||
!document.querySelector(".refract-shell"),
|
||||
{ id: themes[n], colour: colours[n] },
|
||||
),
|
||||
);
|
||||
await cold.close();
|
||||
}
|
||||
const reference = await browser.newPage();
|
||||
await reference.goto(
|
||||
"file://" + path.resolve("design/nocturne/reference.html"),
|
||||
);
|
||||
await reference.evaluate(() => {
|
||||
document.documentElement.classList.add("capture", "reduce");
|
||||
go("settings");
|
||||
});
|
||||
for (const [width, height] of [
|
||||
[1440, 900],
|
||||
[1366, 768],
|
||||
[1280, 720],
|
||||
]) {
|
||||
await reference.setViewportSize({ width, height });
|
||||
await reference.screenshot({
|
||||
path: path.join(out, `reference-${width}x${height}.png`),
|
||||
});
|
||||
}
|
||||
await reference.close();
|
||||
const blocked = await browser.newContext();
|
||||
await blocked.addInitScript(() =>
|
||||
Object.defineProperty(window, "localStorage", {
|
||||
get() {
|
||||
throw new DOMException("blocked", "SecurityError");
|
||||
},
|
||||
}),
|
||||
);
|
||||
const b = await blocked.newPage();
|
||||
b.on(
|
||||
"pageerror",
|
||||
(e) => (errors.push(e.message), console.error("PAGEERROR", e.stack)),
|
||||
);
|
||||
await b.goto(WEB + "/image?wf=" + f.dual);
|
||||
await b.locator("#desk-prompt").fill("禁止存储仍可编辑");
|
||||
await change(b, "day");
|
||||
await b.getByRole("button", { name: "主题", exact: true }).click();
|
||||
ok(
|
||||
"存储被禁用仍可切换且显示提示",
|
||||
await b
|
||||
.getByText("浏览器禁止本地存储:本次有效,其他操作不受影响")
|
||||
.isVisible(),
|
||||
);
|
||||
await b.keyboard.press("Escape");
|
||||
ok(
|
||||
"存储被禁用保留输入",
|
||||
(await b.locator("#desk-prompt").inputValue()) === "禁止存储仍可编辑",
|
||||
);
|
||||
await b.screenshot({ path: path.join(out, "storage-blocked.png") });
|
||||
const invalid = await browser.newContext();
|
||||
await invalid.addInitScript(() =>
|
||||
localStorage.setItem("aigc-theme", "invalid"),
|
||||
);
|
||||
const i = await invalid.newPage();
|
||||
await i.goto(WEB + "/settings?tab=appearance");
|
||||
await i.locator(".choices").waitFor();
|
||||
ok(
|
||||
"无效存储回退夜片场",
|
||||
await i.evaluate(
|
||||
() => document.documentElement.dataset.theme === "night",
|
||||
),
|
||||
);
|
||||
if (errors.length) console.error("BROWSER ERRORS", errors);
|
||||
fs.writeFileSync(
|
||||
path.join(out, "results.json"),
|
||||
JSON.stringify({ checks, errors }, null, 2),
|
||||
);
|
||||
ok("浏览器无运行错误", errors.length === 0);
|
||||
fs.writeFileSync(
|
||||
path.join(out, "results.json"),
|
||||
JSON.stringify({ checks, errors }, null, 2),
|
||||
);
|
||||
console.log("TOTAL", checks.length);
|
||||
} finally {
|
||||
if (saved) fs.writeFileSync(modepath, saved);
|
||||
else if (fs.existsSync(modepath)) fs.unlinkSync(modepath);
|
||||
await browser.close();
|
||||
}
|
||||
})().catch((e) => {
|
||||
console.error(e);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
"""Run the isolated regression stack in the foreground and always stop children."""
|
||||
import os, signal, socket, subprocess, time, urllib.request
|
||||
from pathlib import Path
|
||||
root=Path(__file__).resolve().parents[1]
|
||||
os.chdir(root)
|
||||
py=str(root/'calliope-backend/.venv/bin/python')
|
||||
logs=root/'e2e/shots/hel728'; logs.mkdir(parents=True,exist_ok=True)
|
||||
env=os.environ.copy()
|
||||
for port in [8247,5173,18188,18189]:
|
||||
with socket.socket() as probe:
|
||||
assert probe.connect_ex(('127.0.0.1',port)) != 0, f'Test port {port} is already in use'
|
||||
# Every run gets fresh disposable state; retain prior evidence instead of deleting it.
|
||||
reference=root/'e2e/shots/reference'
|
||||
if reference.exists():reference.rename(reference.with_name('reference.previous-'+str(time.time_ns())))
|
||||
processes=[]; handles=[]
|
||||
try:
|
||||
for name,cmd in [('api',[py,'e2e/reference/server.py']),('comfy',[py,'e2e/fake_comfy.py']),('llm',[py,'e2e/reference/fake_llm.py']),('web',['npm','--prefix',os.environ.get('HEL728_WEB_DIR','calliope-web'),'run','dev'])]:
|
||||
h=open(logs/(name+'.log'),'w');handles.append(h);processes.append(subprocess.Popen(cmd,stdout=h,stderr=subprocess.STDOUT,env=env,start_new_session=True))
|
||||
for url in ['http://127.0.0.1:8247/api/health','http://127.0.0.1:5173']:
|
||||
for i in range(100):
|
||||
try:
|
||||
urllib.request.urlopen(url,timeout=2); break
|
||||
except Exception:
|
||||
if any(p.poll() is not None for p in processes): raise RuntimeError('A test service failed')
|
||||
if i==99:raise
|
||||
time.sleep(.2)
|
||||
for cmd in [[py,'e2e/seed.py'],[py,'e2e/reference/seed.py']]:subprocess.run(cmd,env=env,check=True)
|
||||
failures=[]
|
||||
scripts=os.environ.get('HEL728_TESTS','e2e/reference/check.cjs,e2e/reference/check-copy-fallback.cjs,e2e/hel728.cjs').split(',')
|
||||
for script in scripts:
|
||||
print('RUN',script,flush=True)
|
||||
result=subprocess.run(['node',script],env=env)
|
||||
if result.returncode:failures.append(script)
|
||||
print('FAILED SCRIPTS',failures,flush=True)
|
||||
if failures:raise SystemExit(1)
|
||||
|
||||
finally:
|
||||
for p in processes:
|
||||
if p.poll() is None:os.killpg(p.pid,signal.SIGTERM)
|
||||
for p in processes:
|
||||
try:p.wait(timeout=10)
|
||||
except subprocess.TimeoutExpired:os.killpg(p.pid,signal.SIGKILL);p.wait()
|
||||
for h in handles:h.close()
|
||||
Reference in New Issue
Block a user