Files
aigc-home/e2e/seedvr2-loop-document.mjs
T

104 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.
// Local GET-only: 89 saved positions, three complete Notes, 35 frozen summaries.
import fs from 'node:fs';
import assert from 'node:assert/strict';
const { chromium } = await import(process.env.PLAYWRIGHT_MODULE || 'playwright');
const out='.local-evidence/seedvr2-loop-document/browser';fs.mkdirSync(out,{recursive:true});
const checks=[],requests=[],errors=[],blockedFonts=[],assertionGroups={},interceptions=[];let group='aggregate';
function check(condition,label){assert.ok(condition,label);checks.push(label);assertionGroups[group]=(assertionGroups[group]||0)+1;console.log('PASS '+label);}
const browser=await chromium.launch({headless:true,executablePath:process.env.BROWSER_EXECUTABLE});
try {
const page=await browser.newPage({viewport:{width:1440,height:1000}});
await page.route('**/*',route=>{
const u=new URL(route.request().url());
if(u.hostname==='fonts.googleapis.com'){blockedFonts.push(String(u));return route.fulfill({contentType:'text/css',body:''});}
if(route.request().method()!=='GET'||u.hostname!=='127.0.0.1'||u.pathname==='/api/view'||(/\.(mp4|png|wav|mp3|webm)$/i.test(u.pathname)&&u.pathname!=='/favicon.png')){errors.push('Forbidden request '+u);return route.abort();}
return route.continue();
});
page.on('request',r=>{if(r.url().includes('/api/'))requests.push({method:r.method(),url:r.url()});});
page.on('pageerror',e=>errors.push(e.message));
requests.push({method:'GET',url:'http://127.0.0.1:8247/api/workflows'});
const records=await(await fetch('http://127.0.0.1:8247/api/workflows')).json();
const names=['Seedvr2_视频放大FOR循环长视频','VOSR2_视频放大_分批循环长视频','视频模型放大插帧(简单快速版)','图像放大比较','VOSR2_图像超分放大','Seedvr2_3b_int8_视频放大','Seedvr2_3b_int8_图像放大','RTX_video_upscale','RTX_image_upscale','手动按分镜视频截取','sam3_图像视频-提示词遮罩分割','多视频合成分屏展示','图像4种添加水印节点','birefnet_图像移除背景','加载本地latent解码','截取视频每一帧','双图像或视频合并显示','视频转gif动图图片','加载图片合成视频','视频倒放','NLF_视频人物动作骨架获取','openpose-video-姿态检测','sdpose_视频人物姿势骨架提取','gemma4_提示词反推(图像视频音频)','图像合并成四宫格','图像分割-多宫格分割','Qwen_image2.1_图像编辑_背景移除','Qwen_image2.1_图像编辑_提示词增强','Qwen_image2.1_文生图_提示词增强','ControlNet_aux_常用样例','Qwen3-ASR-语音转文字','Qwen3-ASR-Subtitle语音转字幕','Minimax-H3提示词增强','音频转MP3格式','音频人声分离','视频-音频分离','图像嵌入文字描述'];
const details=[];
for(const name of names){const r=records.find(r=>r.name===name);assert.ok(r);const url=`http://127.0.0.1:8247/api/workflows/${r.id}`;requests.push({method:'GET',url});details.push(await(await fetch(url)).json());}
check(details.length===37&&details.reduce((n,d)=>n+d.doc_json.fixed_version.fields.length,0)===1281,'37图1281保存位置');
check(details.reduce((n,d)=>n+(d.doc_json.source_notes?.length||0),0)===40,'37图40源注释');
await page.goto('http://127.0.0.1:5173/connections',{waitUntil:'networkidle'});
const dialog=page.getByRole('dialog',{name:'工作流说明'});
const fixedCard=dialog.locator('.card').filter({has:page.getByText('固定版本参数说明',{exact:true})});
async function begin(name){const row=page.locator('.wf-row').filter({has:page.locator('.wf-name').filter({hasText:name})}).first();const button=row.getByRole('button',{name:'说明',exact:true});await button.focus();await page.keyboard.press('Enter');return button;}
async function loaded(){await dialog.getByText('用途与来源',{exact:true}).waitFor();await dialog.evaluate(el=>Promise.all(el.getAnimations().map(a=>a.finished)));}
for(const width of [1440,390]){
await page.setViewportSize({width,height:width===390?844:1000});
for(const d of details){
group=details.indexOf(d)<1?'new_vosr2_loop':'old_thirty_six';const b=d.doc_json.fixed_version,button=await begin(d.name);await loaded();
const overview=dialog.locator('.card').filter({has:page.getByText('用途与来源',{exact:true})});
check((await overview.innerText()).includes(b.user_overview),`${width} ${d.name}默认中文用途`);
check(!(await dialog.getByText('源图与审校记录',{exact:true}).locator('..').evaluate(el=>el.open)),`${width} ${d.name}源审校默认折叠`);
check(!(await dialog.getByText('核对范围与来源依据',{exact:true}).locator('..').evaluate(el=>el.open)),`${width} ${d.name}技术范围默认折叠`);
const visible=await fixedCard.innerText();
check(!visible.includes('执行标量')&&!visible.includes('widgetId')&&!visible.includes(b.source_sha256)&&!visible.includes('UUID'),`${width} ${d.name}默认无执行计数/实现标识`);
check(visible.includes('依据固定版本整理,目标环境与实际效果未核对。'),`${width} ${d.name}默认依据限制可见`);
for(const t of ['说明未定稿','未验证实跑','未检查'])check((await dialog.innerText()).includes(t),`${width} ${d.name} ${t}`);
check(!d.is_enabled&&!d.doc_completed_at&&!d.exec_verified_at,`${width} ${d.name}停用/时间戳空`);
check(await fixedCard.locator('summary').filter({hasText:/^节点 [\d:]+ · /}).count()===b.fields.length,`${width} ${d.name}参数全保留`);
check(await dialog.locator('.drawer-body').evaluate(el=>el.scrollWidth<=el.clientWidth),`${width} ${d.name}默认无溢出`);
await dialog.locator('.drawer-body').evaluate(el=>el.scrollTop=0);
if(details.indexOf(d)<1)await page.screenshot({path:`${out}/${width}-${d.id}-default.png`});
if(details.indexOf(d)>0){await page.keyboard.press('Escape');await dialog.waitFor({state:'hidden'});check(await button.evaluate(el=>el===document.activeElement),`${width} ${d.name}旧图归还焦点`);continue;}
await dialog.getByText('源图与审校记录',{exact:true}).click();
check((await overview.innerText()).includes(d.doc_json.purpose)&&(await overview.innerText()).includes(d.source_repo_path),`${width} ${d.name}原用途/源路径展开保留`);
await dialog.getByText('核对范围与来源依据',{exact:true}).click();
const flowText=await fixedCard.innerText();check(flowText.includes('被连线覆盖 15 项')&&flowText.includes('仅前端控制 23 项'),`${width}准确覆盖与前端位置计数`);
for(const line of b.flow)check(flowText.includes(line),`${width} ${d.name}展开流程 ${b.flow.indexOf(line)}`);
if(width===1440){await fixedCard.getByText(b.flow[2],{exact:true}).evaluate(el=>el.scrollIntoView({block:'center'}));await page.screenshot({path:`${out}/${width}-${d.id}-branch-flow.png`});}
await dialog.getByText('版本、源图与连线依据',{exact:true}).click();
check((await fixedCard.innerText()).includes(b.source_sha256)&&b.versions.every(v=>(v&&true)),`${width} ${d.name}原件摘要可展开`);
const versionText=await fixedCard.innerText();
for(const v of b.versions)check(versionText.includes(v),`${width} ${d.name}版本 ${b.versions.indexOf(v)}`);
if(details.indexOf(d)<1){
for(const f of b.fields){
const summary=fixedCard.locator(`details[data-fixed-field="${f.pointer}"] > summary`);await summary.focus();await page.keyboard.press('Enter');const box=summary.locator('..');
check(await box.evaluate(el=>el.open),`${width} ${f.node_id}.${f.field}键盘展开`);
let text=await box.innerText();check(text.includes(f.effect)&&text.includes(f.limits)&&text.includes(f.schema_default)&&text.includes(f.execution_note)&&text.includes(f.unit),`${width} ${f.node_id}.${f.field}用途/单位/范围/来源条件`);
check(await box.locator(':scope > pre').textContent()===(typeof f.value==='string'?f.value:JSON.stringify(f.value,null,2)),`${width} ${f.node_id}.${f.field}精确保留现值`);
check(!text.includes(f.pointer),`${width} ${f.node_id}.${f.field}指针默认折叠`);
await box.getByText('来源依据',{exact:true}).click();text=await box.innerText();
check(text.includes(f.pointer)&&text.includes(f.named_pointer)&&text.includes(f.class_type)&&text.includes(f.json_type)&&f.evidence.every(i=>{const e=b.sources[i];return text.includes(e.commit)&&text.includes(e.sha256)&&text.includes(e.lines.join('~'));}),`${width} ${f.node_id}.${f.field}精确源码/类型/指针`);
check(await dialog.locator('.drawer-body').evaluate(el=>el.scrollWidth<=el.clientWidth),`${width} ${f.node_id}.${f.field}展开无溢出`);
if(f.node_id==='143:133'&&f.field==='control_after_generate')await page.screenshot({path:`${out}/${width}-${d.id}-fixed-sources-corrected.png`});
if((width===1440&&f.field==='seed_1'&&f.node_id==='143')||(width===390&&f.field==='expression'&&f.node_id==='33'))await page.screenshot({path:`${out}/${width}-${d.id}-${f.node_id}-${f.field}.png`});
await summary.click();
}
for(const n of b.comments){const summary=dialog.getByText(`节点 ${n.node_id}`,{exact:true});await summary.click();const expected=d.doc_json.source_notes.find(x=>String(x.node_id)===n.node_id);check(await summary.locator('..').locator('pre').textContent()===JSON.stringify(expected.content,null,2),`${width}注释${n.node_id}全文`);check(await dialog.locator('.drawer-body').evaluate(el=>el.scrollWidth<=el.clientWidth),`${width}注释${n.node_id}无溢出`);if(width===390){await summary.evaluate(el=>el.scrollIntoView({block:'start'}));await page.screenshot({path:`${out}/${width}-${d.id}-${n.node_id}-note.png`});}await summary.click();}
await dialog.getByRole('button',{name:'关闭',exact:true}).focus();await page.keyboard.press('Tab');check(await dialog.evaluate(el=>el.contains(document.activeElement)),`${width}Tab焦点保留`);await page.keyboard.press('Shift+Tab');check(await dialog.evaluate(el=>el.contains(document.activeElement)),`${width}ShiftTab焦点保留`);
}
await page.keyboard.press('Escape');await dialog.waitFor({state:'hidden'});check(await button.evaluate(el=>el===document.activeElement),`${width} ${d.name}关闭归还焦点`);
}
}
group='shared_regressions';
for(const name of ['旧工作流回退(隔离测试夹具)','空说明回退(隔离测试夹具)']){await begin(name);await loaded();check((await dialog.innerText()).includes('隔离库旧条目回退测试'),'旧/空说明回退 '+name);await page.keyboard.press('Escape');}
// Missing summary and mismatched bindings are tested with local GET fixtures, without writes.
for(const variant of ['missing-overview','mismatched','html-summary']){
const d=structuredClone(details[0]);
if(variant==='missing-overview')delete d.doc_json.fixed_version.user_overview;
if(variant==='mismatched')d.doc_json.fixed_version={matched:false,notice:'固定版本参数说明待核对:源文件、声明版本或说明依据未匹配,未采用旧定义。'};
if(variant==='html-summary')d.doc_json.fixed_version.user_overview='<img src="https://example.invalid/forbidden">仅纯文本';
await page.route(`**/api/workflows/${d.id}`,route=>{interceptions.push({variant,url:route.request().url()});return route.fulfill({json:d});});await begin(d.name);await loaded();
if(variant==='missing-overview')check((await dialog.innerText()).includes('这张图的用途和操作重点可在下方使用步骤中查看;目标环境与实际效果仍待核对。'),'缺摘要自然中文回退');
if(variant==='mismatched')check((await dialog.innerText()).includes(d.doc_json.fixed_version.notice)&&!await dialog.getByText('核对范围与来源依据',{exact:true}).count(),'错绑定提示明确且不展示旧字段');
if(variant==='html-summary')check((await dialog.innerText()).includes(d.doc_json.fixed_version.user_overview)&&await dialog.locator('img').count()===0,'摘要HTML仅纯文本不创建图像或请求');
check(!(await dialog.innerText()).includes('undefined'),'回退不暴露undefined');await page.keyboard.press('Escape');await page.unroute(`**/api/workflows/${d.id}`);
}
let release,entered,delivered;const hold=new Promise(r=>release=r),intercept=new Promise(r=>entered=r),done=new Promise(r=>delivered=r);
await page.route(`**/api/workflows/${details[0].id}`,async route=>{interceptions.push({variant:"late",url:route.request().url()});entered();await hold;await route.fulfill({json:details[0]});delivered();});
await begin(details[0].name);await intercept;await page.keyboard.press('Escape');await begin(details[1].name);await loaded();release();await done;
check((await dialog.innerText()).includes(details[1].doc_json.fixed_version.user_overview)&&await fixedCard.locator('summary').filter({hasText:/^节点 [\d:]+ · /}).count()===details[1].doc_json.fixed_version.fields.length,'迟到循环图响应不覆盖旧插帧摘要/37字段');await page.keyboard.press('Escape');await page.unroute(`**/api/workflows/${details[0].id}`);
await page.route(`**/api/workflows/${details[0].id}`,route=>{interceptions.push({variant:'failure',url:route.request().url()});return route.fulfill({status:500,json:{detail:'隔离失败夹具'}});});await begin(details[0].name);await dialog.getByRole('alert').waitFor({timeout:20000});check(await dialog.getByRole('button',{name:'重试',exact:true}).isVisible(),'GET失败显示重试');check(await dialog.getByText('用途与来源',{exact:true}).count()===0,'读取失败隐藏旧摘要');await page.unroute(`**/api/workflows/${details[0].id}`);await dialog.getByRole('button',{name:'重试',exact:true}).click();await loaded();check((await dialog.innerText()).includes(details[0].doc_json.fixed_version.user_overview),'重试恢复摘要');await page.keyboard.press('Escape');
check(errors.length===0,'无脚本错误或禁止请求 '+JSON.stringify(errors));check(requests.every(r=>r.method==='GET'&&new URL(r.url).hostname==='127.0.0.1'&&!r.url.includes('/api/view')),'全程本地GET无写/生成/目标/历史预览请求');
const polling=requests.filter(r=>['/api/jobs','/api/events'].includes(new URL(r.url).pathname));
const fixed=requests.filter(r=>!polling.includes(r));
const frequencies=rs=>Object.fromEntries([...new Set(rs.map(r=>new URL(r.url).pathname))].sort().map(p=>[p,rs.filter(r=>new URL(r.url).pathname===p).length]));
fs.writeFileSync(`${out}/browser-results.json`,JSON.stringify({request_accounting:{fixed_count:fixed.length,fixed_paths:frequencies(fixed),polling_count:polling.length,polling_paths:frequencies(polling),polling_tolerance:1,reason:'定时轮询可因浏览耗时与计时器边界相差±1;固定请求逐条保存,不忽略真实新请求,禁止请求零容忍。'},assertion_count:checks.length,assertionGroups,interceptions,checks,requests,errors,blockedFonts,viewports:[1440,390]},null,2));
} finally {await browser.close();}