cmvr-visual/qa/browser-v2.cjs

53 lines
4.7 KiB
JavaScript
Raw Normal View History

const fs=require('fs');const path=require('path');
const {chromium}=require('C:/Users/Administrator/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright');
const root=path.resolve(__dirname,'..'),base=process.env.CMVR_BASE_URL||'http://127.0.0.1:8000';
const env=Object.fromEntries(fs.readFileSync(path.join(root,'.env.server'),'utf8').split(/\r?\n/).filter(x=>x&&!x.startsWith('#')).map(x=>{const i=x.indexOf('=');return[x.slice(0,i),x.slice(i+1)]}));
(async()=>{let browser;try{
browser=await chromium.launch({channel:'chrome',headless:true});
const context=await browser.newContext({viewport:{width:1440,height:1000}}),page=await context.newPage(),errors=[];
page.on('pageerror',e=>errors.push(e.message));
await page.goto(base+'/login',{waitUntil:'domcontentloaded'});
await page.getByPlaceholder('输入你的账号').fill(env.ADMIN_USERNAME);
await page.getByPlaceholder('输入密码',{exact:true}).fill(env.ADMIN_PASSWORD);
await page.getByRole('button',{name:'进入工作空间'}).click();
await page.waitForURL('**/create/image',{timeout:30000});
await page.goto(base+'/workflow',{waitUntil:'domcontentloaded'});
await page.getByRole('heading',{name:'把三个瞬间,连成一个故事。'}).waitFor();
const name='V2验收-三分镜-20261110';
await page.getByPlaceholder('故事名称').fill(name);
const prompts=[
'A calm cinematic wide shot of a modern industrial inspection room, clean metal components on a conveyor belt, cool blue lighting, slow camera dolly, realistic, no text.',
'A cinematic close-up of a polished metal bearing rotating slowly, an engineer gloved hand holding it, consistent blue industrial lighting, realistic, no text.',
'A cinematic tracking shot of a clean factory conveyor moving smoothly toward a bright quality inspection station, blue industrial lighting, realistic, no text.'
];
const fields=page.getByPlaceholder('描述这个镜头的画面、动作和光线');
for(let i=0;i<3;i++)await fields.nth(i).fill(prompts[i]);
await page.getByRole('button',{name:'添加字幕',exact:true}).click();
await page.getByPlaceholder('字幕文字').fill('CMVR Visual · 三镜头验证');
const draftResponse=page.waitForResponse(r=>r.request().method()==='POST'&&new URL(r.url()).pathname==='/api/workflows');
await page.getByRole('button',{name:'保存草稿',exact:true}).click();
const saved=await draftResponse;if(saved.status()!==201)throw new Error('Draft save failed: '+saved.status());
const draft=await saved.json();
await page.reload({waitUntil:'domcontentloaded'});
await page.getByRole('heading',{name:'把三个瞬间,连成一个故事。'}).waitFor();
if(await page.getByPlaceholder('故事名称').inputValue()!==name)throw new Error('Draft name lost on reload');
for(let i=0;i<3;i++)if(await page.getByPlaceholder('描述这个镜头的画面、动作和光线').nth(i).inputValue()!==prompts[i])throw new Error('Shot draft lost on reload');
const runResponse=page.waitForResponse(r=>r.request().method()==='POST'&&new URL(r.url()).pathname.endsWith('/runs'));
await page.getByRole('button',{name:'保存并运行',exact:true}).click();
const accepted=await runResponse;if(accepted.status()!==202)throw new Error('Run rejected: '+accepted.status()+' '+await accepted.text());
const snapshot=await accepted.json();
const report={base,draft_id:draft.id,run_id:snapshot.run.id,name,accepted_at:new Date().toISOString(),draft_reload:true,errors};
fs.writeFileSync(path.join(root,'qa/v2-browser.json'),JSON.stringify(report,null,2));
await page.screenshot({path:path.join(root,'qa/v2-workflow-desktop.png'),fullPage:true});
await page.goto(base+'/tasks',{waitUntil:'domcontentloaded'});await page.getByText(snapshot.run.id.slice(0,8),{exact:false}).first().waitFor({timeout:15000});
await page.screenshot({path:path.join(root,'qa/v2-tasks-desktop.png'),fullPage:true});
await page.goto(base+'/account',{waitUntil:'domcontentloaded'});await page.getByRole('heading',{name:'账户与访问。'}).waitFor();
await page.getByRole('heading',{name:'用户管理',exact:true}).waitFor();
await page.screenshot({path:path.join(root,'qa/v2-account-desktop.png'),fullPage:true});
await page.setViewportSize({width:390,height:844});await page.goto(base+'/workflow',{waitUntil:'domcontentloaded'});await page.getByRole('heading',{name:'把三个瞬间,连成一个故事。'}).waitFor();
report.mobile_overflow=await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth+2);
await page.screenshot({path:path.join(root,'qa/v2-workflow-mobile.png'),fullPage:true});
fs.writeFileSync(path.join(root,'qa/v2-browser.json'),JSON.stringify(report,null,2));
console.log(JSON.stringify(report));
}finally{if(browser)await browser.close()}})().catch(e=>{console.error(e.message);process.exitCode=1});