217 lines
9.2 KiB
JavaScript
217 lines
9.2 KiB
JavaScript
/* HEL-684 S5 browser validation against the isolated stack:
|
||
* vite dev (5173) → backend (8247) → fake ComfyUI (18188).
|
||
* Covers: context bar hint, submit carries the workbench context, the
|
||
* explicit 回流到源项目 action, the attached state surviving reload,
|
||
* the artifact landing on the workbench source row, the cancel path
|
||
* (context take, no attach → project untouched) and the independent
|
||
* path (no context → no attach action). */
|
||
import { chromium } from 'playwright';
|
||
import fs from 'node:fs';
|
||
import path from 'node:path';
|
||
import { fileURLToPath } from 'node:url';
|
||
|
||
const ROOT = path.dirname(fileURLToPath(import.meta.url));
|
||
const SHOTS = path.join(ROOT, 'shots');
|
||
fs.mkdirSync(SHOTS, { recursive: true });
|
||
|
||
const API = 'http://127.0.0.1:8247';
|
||
const MODE_FILE = path.join(ROOT, 'fake_mode.json');
|
||
const setMode = (m) => fs.writeFileSync(MODE_FILE, JSON.stringify(m));
|
||
|
||
let failures = 0;
|
||
function ok(name, cond, extra = '') {
|
||
const line = `${cond ? 'PASS' : 'FAIL'} ${name}${extra ? ' — ' + extra : ''}`;
|
||
console.log(line);
|
||
if (!cond) failures++;
|
||
}
|
||
|
||
const api = async (p, init) => {
|
||
const r = await fetch(API + p, {
|
||
headers: { 'Content-Type': 'application/json' },
|
||
...init,
|
||
});
|
||
const body = await r.text();
|
||
try {
|
||
return JSON.parse(body);
|
||
} catch {
|
||
return { raw: body, status: r.status };
|
||
}
|
||
};
|
||
|
||
async function waitFor(fn, timeout = 30000, step = 300) {
|
||
const deadline = Date.now() + timeout;
|
||
while (Date.now() < deadline) {
|
||
const v = await fn();
|
||
if (v) return v;
|
||
await new Promise((r) => setTimeout(r, step));
|
||
}
|
||
return null;
|
||
}
|
||
|
||
const run = async () => {
|
||
setMode({ mode: 'ok', delay_sec: 0 });
|
||
|
||
// ---- isolated project with real stage rows ----
|
||
const proj = await api('/api/projects', {
|
||
method: 'POST',
|
||
body: JSON.stringify({ title: '回流验证项目' }),
|
||
});
|
||
const patch = await api(`/api/workbench/projects/${proj.id}/stages/assets`, {
|
||
method: 'PATCH',
|
||
body: JSON.stringify({
|
||
content: {
|
||
assets: [
|
||
{
|
||
id: 'asset-e2e',
|
||
kind: 'character',
|
||
name: '林夏',
|
||
description: '',
|
||
prompt: 'a stoic courier in the rain',
|
||
negative_prompt: '',
|
||
},
|
||
],
|
||
},
|
||
}),
|
||
});
|
||
ok('准备:资产阶段有真实行', patch.ok === true);
|
||
const shotPatch = await api(`/api/workbench/projects/${proj.id}/stages/shot`, {
|
||
method: 'PATCH',
|
||
body: JSON.stringify({
|
||
content: {
|
||
shots: [
|
||
{
|
||
id: 'vshot-e2e',
|
||
shot_no: 'S1',
|
||
description: '',
|
||
prompt: 'slow push in on the courier',
|
||
duration_sec: 5,
|
||
},
|
||
],
|
||
},
|
||
}),
|
||
});
|
||
ok('准备:镜头阶段有真实行', shotPatch.ok === true);
|
||
|
||
const browser = await chromium.launch();
|
||
const ctx = await browser.newContext({ viewport: { width: 1440, height: 900 } });
|
||
const page = await ctx.newPage();
|
||
page.on('pageerror', (e) => console.log('PAGEERROR:', e.message));
|
||
|
||
// ---------- 1. 从资产行进入生成台:上下文条给出回流提示 ----------
|
||
const deskUrl =
|
||
`http://127.0.0.1:5173/image?from=workbench&project=${proj.id}&stage=assets` +
|
||
`&label=${encodeURIComponent('角色「林夏」')}&prompt=${encodeURIComponent('a stoic courier in neon rain')}` +
|
||
`&source_kind=asset&source_id=asset-e2e`;
|
||
await page.goto(deskUrl);
|
||
await page.waitForSelector('#desk-prompt', { timeout: 15000 });
|
||
const note = await page.locator('.context-bar .note').textContent();
|
||
ok('上下文条提示可回流', (note || '').includes('回流'), note);
|
||
ok('上下文条预填提示词', (await page.inputValue('#desk-prompt')).includes('stoic courier'));
|
||
await page.screenshot({ path: `${SHOTS}/hel684-01-desk-context.png` });
|
||
|
||
// ---------- 2. 提交带上下文的生成 → 完成 → 出现「回流到源项目」 ----------
|
||
await page.click('.a-btn.primary'); // 生成
|
||
const job = await waitFor(async () => {
|
||
const jobs = await api('/api/playground/jobs');
|
||
return jobs.find((j) => j.status === 'done' && j.output_paths.length && JSON.stringify(j.payload?.workbench ?? {}).includes('asset-e2e'));
|
||
});
|
||
ok('生成任务完成且携带真实来源(payload.workbench)', !!job, job ? `job ${job.id}` : 'not found');
|
||
await page.waitForTimeout(1200);
|
||
const take = page.locator(`.take[data-job="${job.id}"]`);
|
||
await take.scrollIntoViewIfNeeded();
|
||
const attachBtn = take.locator('button.attach');
|
||
ok('结果卡出现「回流到源项目」动作', (await attachBtn.count()) === 1);
|
||
await page.screenshot({ path: `${SHOTS}/hel684-02-attach-action.png` });
|
||
|
||
// ---------- 3. 点击回流 → 已回流 + 返回项目 ----------
|
||
await attachBtn.click();
|
||
const attachedTag = take.locator('.actions .a-tag', { hasText: '已回流' });
|
||
await attachedTag.waitFor({ timeout: 15000 });
|
||
ok('回流后结果卡显示「已回流」', (await attachedTag.count()) === 1);
|
||
const backLink = take.locator('.actions a', { hasText: '返回项目' });
|
||
ok('回流后提供「返回项目」链接', (await backLink.count()) === 1);
|
||
const overview1 = await api(`/api/workbench/projects/${proj.id}`);
|
||
const row1 = overview1.stages.find((s) => s.stage_key === 'assets').content.assets[0];
|
||
ok('项目资产行挂上回流产物', row1.job && row1.job.output === job.output_paths[0], JSON.stringify(row1.job || {}));
|
||
await page.screenshot({ path: `${SHOTS}/hel684-03-attached.png` });
|
||
|
||
// ---------- 4. 重载后仍是已回流(服务端标记,非客户端记忆) ----------
|
||
await page.reload();
|
||
await page.waitForSelector(`.take[data-job="${job.id}"]`, { timeout: 15000 });
|
||
await page
|
||
.locator(`.take[data-job="${job.id}"] .actions .a-tag`, { hasText: '已回流' })
|
||
.waitFor({ timeout: 15000 });
|
||
ok('重载后仍显示「已回流」', true);
|
||
|
||
// ---------- 5. 返回项目看到产物 ----------
|
||
await page.locator(`.take[data-job="${job.id}"] .actions a`, { hasText: '返回项目' }).click();
|
||
await page.waitForURL(new RegExp(`/workbench/${proj.id}.*stage=assets`), { timeout: 15000 });
|
||
await page.waitForSelector('[data-testid="asset-grid"] .asset-card img', { timeout: 15000 });
|
||
ok('工作台资产卡显示回流图片', true);
|
||
await page.screenshot({ path: `${SHOTS}/hel684-04-workbench-row.png`, fullPage: false });
|
||
|
||
// ---------- 6. 取消回流:带上下文生成但不动回流 → 项目不误写 ----------
|
||
await page.goto(deskUrl);
|
||
await page.waitForSelector('#desk-prompt');
|
||
await page.fill('#desk-prompt', 'second take on purpose not attached');
|
||
await page.click('.a-btn.primary');
|
||
const job2 = await waitFor(async () => {
|
||
const jobs = await api('/api/playground/jobs');
|
||
return jobs.find((j) => j.status === 'done' && j.id !== job.id && JSON.stringify(j.payload?.workbench ?? {}).includes('asset-e2e'));
|
||
});
|
||
ok('第二条带上下文任务完成', !!job2);
|
||
await page.waitForTimeout(1000);
|
||
const overview2 = await api(`/api/workbench/projects/${proj.id}`);
|
||
const row2 = overview2.stages.find((s) => s.stage_key === 'assets').content.assets[0];
|
||
ok('未点回流 → 资产行保持第一份产物(不误写)', row2.job && row2.job.output === job.output_paths[0]);
|
||
const jobsOnProject = (await api(`/api/jobs?project_id=${proj.id}`)).length ?? 0;
|
||
ok('项目任务数不因未回流而增加', jobsOnProject === 1, `${jobsOnProject} job(s)`);
|
||
|
||
// ---------- 7. 独立生成(无上下文)→ 无回流动作 ----------
|
||
await page.goto('http://127.0.0.1:5173/image');
|
||
await page.waitForSelector('#desk-prompt');
|
||
await page.fill('#desk-prompt', 'standalone take without any context');
|
||
await page.click('.a-btn.primary');
|
||
const job3 = await waitFor(async () => {
|
||
const jobs = await api('/api/playground/jobs');
|
||
return jobs.find((j) => j.status === 'done' && j.id !== job.id && j.id !== job2?.id && !j.payload?.workbench);
|
||
});
|
||
ok('独立任务完成且无来源', !!job3);
|
||
await page.waitForTimeout(1000);
|
||
ok('独立结果卡没有回流动作', (await page.locator(`.take[data-job="${job3.id}"] button.attach`).count()) === 0);
|
||
|
||
// ---------- 8. 镜头(视频)路径:上下文 + 回流 ----------
|
||
setMode({ mode: 'ok', delay_sec: 0, videos: true });
|
||
await page.goto(
|
||
`http://127.0.0.1:5173/video?from=workbench&project=${proj.id}&stage=shot` +
|
||
`&label=${encodeURIComponent('镜头 S1')}&prompt=${encodeURIComponent('slow push in on the courier')}` +
|
||
`&source_kind=shot&source_id=vshot-e2e`
|
||
);
|
||
await page.waitForSelector('#desk-prompt', { timeout: 15000 });
|
||
await page.click('.a-btn.primary');
|
||
const vjob = await waitFor(async () => {
|
||
const jobs = await api('/api/playground/jobs');
|
||
return jobs.find((j) => j.status === 'done' && j.kind === 'video' && JSON.stringify(j.payload?.workbench ?? {}).includes('vshot-e2e'));
|
||
}, 40000);
|
||
ok('视频任务完成且携带镜头来源', !!vjob);
|
||
await page.waitForTimeout(1200);
|
||
await page.locator(`.take[data-job="${vjob.id}"] button.attach`).click();
|
||
await page.waitForSelector(`.take[data-job="${vjob.id}"] .a-tag.ok`, { timeout: 15000 });
|
||
const overview3 = await api(`/api/workbench/projects/${proj.id}`);
|
||
const shotRow = overview3.stages.find((s) => s.stage_key === 'shot').content.shots[0];
|
||
ok('镜头行挂上回流视频', shotRow.job && shotRow.job.output === vjob.output_paths[0], JSON.stringify(shotRow.job || {}));
|
||
await page.screenshot({ path: `${SHOTS}/hel684-05-shot-flowback.png` });
|
||
|
||
await browser.close();
|
||
if (failures) {
|
||
console.log(`\n${failures} check(s) FAILED`);
|
||
process.exit(1);
|
||
}
|
||
console.log('\nall checks passed');
|
||
};
|
||
|
||
run().catch((e) => {
|
||
console.error(e);
|
||
process.exit(1);
|
||
});
|