Files
aigc-home/e2e/hel732.cjs
T

83 lines
11 KiB
JavaScript

const {chromium}=require(process.env.PLAYWRIGHT_MODULE_PATH||'playwright');
const fs=require('node:fs'),http=require('node:http'),assert=require('node:assert/strict');
const API='http://127.0.0.1:8247',WEB='http://127.0.0.1:5173',out='e2e/shots/hel732';
fs.mkdirSync(out,{recursive:true});const checks=[],errors=[];
const ok=(n,v)=>{assert(v,n);checks.push(n);console.log('PASS',n)};
async function api(p,b,method){const r=await fetch(API+p,{method:method||(b?'POST':'GET'),headers:{'Content-Type':'application/json'},body:b?JSON.stringify(b):undefined});if(!r.ok)throw Error(p+' '+await r.text());return r.json()}
async function wait(fn){for(let i=0;i<120;i++){const r=await fn();if(r)return r;await new Promise(r=>setTimeout(r,150))}throw Error('condition timeout')}
(async()=>{
const b=await chromium.launch({args:['--no-sandbox','--disable-dev-shm-usage']});
const c=await b.newContext({viewport:{width:1440,height:900}});await c.tracing.start({screenshots:true,snapshots:true,sources:true});const p=await c.newPage();p.setDefaultTimeout(15000);p.on('pageerror',e=>errors.push(e.message));
const sample=http.createServer((req,res)=>{res.setHeader('Content-Type','text/html;charset=utf-8');res.end(fs.readFileSync('../evidence/reference/夜片场-多主题交互样本.html'))});await new Promise(r=>sample.listen(0,'127.0.0.1',r));
try{
const project=await api('/api/projects',{title:'B4 隔离项目',idea:'海岸与纸船'}),other=await api('/api/projects',{title:'B4 另一个项目'});
await p.goto(WEB+'/agents');await p.locator('.roster .acard').first().waitFor();
ok('首页五个真实阶段助手',await p.locator('.roster .acard').count()===5);
ok('无成果显示真实空态',(await p.locator('.outrow').innerText()).includes('暂无成果'));
await p.getByLabel('绑定项目',{exact:true}).selectOption(String(project.id));
await p.getByLabel('任务技能').selectOption({index:1});
await p.getByLabel('任务想法').fill('请调用工具查看项目,然后写一个海岸纸船的完整故事。');
await p.getByRole('button',{name:'开始任务',exact:true}).click();
const sid=await wait(async()=>Number(new URL(p.url()).searchParams.get('session'))||null);
const r=await wait(async()=>(await api('/api/results/deliverables?session_id='+sid))[0]);
ok('真实会话链路产生持久化成果',r.content.length>30);
const s=await api('/api/agent/sessions/'+sid);ok('任务摘要与状态持久化',s.task_summary.includes('海岸')&&s.task_status==='awaiting_confirm');
ok('假模型通过应用实际调用工具',s.messages.some(m=>m.role==='tool'&&m.tool_name==='get_workspace'));
ok('技能选择传入真实会话',s.messages.some(m=>m.role==='user'&&m.mentions?.some(x=>x.type==='skill')));
await p.getByLabel('成果草稿').waitFor();const edited=r.content+'【浏览器编辑并保存】';await p.getByLabel('成果草稿').fill(edited);await p.getByRole('button',{name:'保存草稿',exact:true}).click();
await wait(async()=>(await api('/api/results/deliverables?session_id='+sid))[0].revision===2);
await p.reload();await p.getByLabel('成果草稿').waitFor();ok('编辑保存刷新恢复',await p.getByLabel('成果草稿').inputValue()===edited);
await p.getByRole('button',{name:'带回项目待确认',exact:true}).click();await p.locator('[data-testid=incoming-result]').waitFor();
const wb=await api('/api/workbench/projects/'+project.id),stage=wb.stages.find(x=>x.stage_key==='script');
ok('带回指定项目阶段且仅待确认',stage.status==='awaiting_confirm'&&stage.content.text===edited&&stage.confirmed_content===null);
ok('其他项目未出现成果',!JSON.stringify(await api('/api/workbench/projects/'+other.id)).includes('浏览器编辑'));
await p.locator('[data-testid=stage-confirm-btn]').click();await wait(async()=>(await api('/api/workbench/projects/'+project.id)).stages[0].status==='confirmed');ok('真实项目页显式确认',true);
const nr=(await api('/api/results/deliverables?session_id='+sid))[0];const body={deliverable_id:nr.id,revision:nr.revision,project_id:project.id,stage_key:'script'};
ok('重复提交幂等',(await api('/api/results/store',body)).already_attached===true);
const bad=await fetch(API+'/api/results/store',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({...body,project_id:other.id})});ok('跨项目误存被拒绝',bad.status===409);
// Actual structured reply and a single image job; no GPU/paid model.
const board=await api('/api/agent/sessions',{project_id:project.id,agent_key:'storyboard',title:'B4 分镜隔离任务'});
await api('/api/agent/sessions/'+board.id+'/messages',{content:'B4_STORYBOARD 请读取工作区并给出三个镜头。'});
const br=await wait(async()=>(await api('/api/results/deliverables?session_id='+board.id))[0]);
const parsed=JSON.parse(br.content.split('```json')[1].split('```')[0]);
const saved=await api('/api/results/deliverables/'+br.id,{revision:br.revision,content:JSON.stringify(parsed,null,2),project_id:project.id,stage_key:'storyboard'},'PATCH');
await api('/api/results/store',{project_id:project.id,stage_key:'storyboard',deliverable_id:saved.id,revision:saved.revision});
await p.goto(WEB+'/agents?session='+board.id);await p.getByRole('button',{name:'重画',exact:true}).first().waitFor();
await p.getByLabel('镜头 b4-shot-1 描述').fill('逐镜编辑后的真实描述');await p.getByLabel('镜头 b4-shot-1 时长').fill('6');await p.getByRole('button',{name:'保存草稿',exact:true}).click();
await wait(async()=>(await api('/api/results/deliverables?session_id='+board.id))[0].revision===3);
await p.getByRole('button',{name:'对比上一版',exact:true}).click();await p.getByRole('dialog').waitFor();ok('成果对比读取真实上一保存版本',(await p.getByRole('dialog').innerText()).includes('隔离验证镜头 1'));await p.getByRole('dialog').getByRole('button',{name:'关闭对话框',exact:true}).click();
await p.reload();await p.getByLabel('镜头 b4-shot-1 描述').waitFor();ok('逐镜文字与时长保存刷新恢复',(await p.getByLabel('镜头 b4-shot-1 描述').inputValue())==='逐镜编辑后的真实描述'&&(await p.getByLabel('镜头 b4-shot-1 时长').inputValue())==='6');
const before=(await api('/api/jobs?project_id='+project.id)).length;
await p.getByRole('button',{name:'重画',exact:true}).nth(1).click();
const jobs=await wait(async()=>{const rows=await api('/api/jobs?project_id='+project.id);return rows.length>before?rows:null});
ok('单镜重画仅新增一个任务',jobs.length===before+1);
ok('单镜重画保留指定镜头',jobs[0].payload.target_id==='b4-shot-2');
// Independent take → chooser → specific stage draft, original flow-back stays separately covered by B3.
fs.writeFileSync('e2e/fake_mode.json',JSON.stringify({mode:'ok',delay_sec:0,videos:false,unique_filename:true}));
const f=JSON.parse(fs.readFileSync('e2e/shots/reference/fixtures.json'));
await p.goto(WEB+'/create?kind=image&wf='+f.dual);await p.locator('#desk-prompt').waitFor();await p.locator('#desk-prompt').fill('B4 isolated independent image');
const maxJob=Math.max(0,...(await api('/api/playground/jobs')).map(x=>x.id));await p.locator('.gen').click();
const job=await wait(async()=>(await api('/api/playground/jobs')).find(j=>j.id>maxJob&&j.status==='done'));
await p.getByRole('button',{name:'存入项目',exact:true}).click();await p.getByLabel('存入项目',{exact:true}).selectOption(String(other.id));await p.getByLabel('存入阶段').selectOption('assets');
await p.getByRole('button',{name:'存入待确认草稿'}).click();
const mediaStage=await wait(async()=>(await api('/api/workbench/projects/'+other.id)).stages.find(s=>s.stage_key==='assets'&&s.incoming_results?.length));
ok('独立生成经通用选择器存入指定阶段',mediaStage.incoming_results[0].paths[0]===job.output_paths[0]&&mediaStage.status==='awaiting_confirm');
await p.goto(WEB+'/agents?legacy=1');await p.locator('.agent-rail').waitFor();ok('原会话及技能管理仍可达',true);
fs.writeFileSync(out+'/fixture-state.json',JSON.stringify({project,other,sid,board:board.id,br:(await api('/api/results/deliverables?session_id='+board.id))[0]},null,2));
const sp=await c.newPage();const measures=[];
for(const [width,height] of [[1440,900],[1366,768],[1280,720]])for(const theme of ['night','day','grade','bluehour']){
await p.setViewportSize({width,height});await sp.setViewportSize({width,height});
await p.goto(WEB+'/agents');await p.evaluate(t=>{document.documentElement.dataset.theme=t;localStorage.setItem('aigc-theme',t);document.documentElement.dataset.reduce='0'},theme);await p.locator('.roster .acard').first().waitFor();
await sp.goto('http://127.0.0.1:'+sample.address().port);await sp.evaluate(t=>{go('agents');document.documentElement.dataset.theme=t;document.documentElement.dataset.reduce='0'},theme);
await p.screenshot({animations:"disabled",path:`${out}/home-${theme}-${width}-actual.png`});await sp.screenshot({animations:"disabled",path:`${out}/home-${theme}-${width}-sample.png`});
measures.push({width,height,theme,page:'home',actual:await p.locator('.ahero').evaluate(e=>({width:e.offsetWidth,padding:getComputedStyle(e).padding,title:getComputedStyle(e.querySelector('h2')).fontSize,weight:getComputedStyle(e.querySelector('h2')).fontWeight})),sample:await sp.locator('.ahero').evaluate(e=>({width:e.offsetWidth,padding:getComputedStyle(e).padding,title:getComputedStyle(e.querySelector('h2')).fontSize,weight:getComputedStyle(e.querySelector('h2')).fontWeight}))});
await p.goto(WEB+'/agents?session='+board.id);await p.locator('.shot-copy textarea').first().waitFor();await sp.evaluate(()=>go('agent-task'));
await p.screenshot({animations:"disabled",path:`${out}/task-${theme}-${width}-actual.png`});await sp.screenshot({animations:"disabled",path:`${out}/task-${theme}-${width}-sample.png`});
ok(`任务页成果底栏可见 ${theme} ${width}`,await p.locator('.art-f').evaluate(e=>{const r=e.getBoundingClientRect();return r.bottom<=innerHeight&&r.top>=0}));
measures.push({width,height,theme,page:'task',actual:await p.locator('.atask').evaluate(e=>({columns:getComputedStyle(e).gridTemplateColumns,height:e.offsetHeight})),sample:await sp.locator('.atask').evaluate(e=>({columns:getComputedStyle(e).gridTemplateColumns,height:e.offsetHeight}))});
}
fs.writeFileSync(out+'/measurements.json',JSON.stringify(measures,null,2));ok('浏览器无运行时错误',errors.length===0);
}finally{fs.writeFileSync(out+'/checks.json',JSON.stringify({checks,errors},null,2));await c.tracing.stop({path:out+'/trace.zip'});await b.close();await new Promise(r=>sample.close(r));}
})().catch(e=>{console.error(e);process.exit(1)});