Files
aigc-home/e2e/hel733-live.cjs
T

87 lines
10 KiB
JavaScript

// Real isolated API and fake ComfyUI; never connects to production.
const {chromium}=require(process.env.PLAYWRIGHT_MODULE_PATH||'playwright');
const fs=require('node:fs'),assert=require('node:assert/strict'),path=require('node:path');
const OUT='../evidence/hel733/live',WEB='http://127.0.0.1:5173',API='http://127.0.0.1:8247';
fs.mkdirSync(OUT,{recursive:true});
const checks=[],errors=[],ok=(name,value)=>{checks.push({name,pass:!!value});assert(value,name);console.log('PASS',name)};
const api=async p=>(await fetch(API+p)).json();
const wait=ms=>new Promise(r=>setTimeout(r,ms));
(async()=>{
const b=await chromium.launch({executablePath:process.env.CHROMIUM_EXECUTABLE_PATH,args:['--no-sandbox']});
try{
const f=JSON.parse(fs.readFileSync('e2e/shots/reference/fixtures.json'));
const state=JSON.parse(fs.readFileSync('e2e/shots/hel732/fixture-state.json'));
const c=await b.newContext({viewport:{width:1440,height:900},recordVideo:{dir:OUT+'/recordings'}});
await c.addInitScript(()=>{
window.mediaCalls=[];
for(const method of ['play','pause']){const original=HTMLMediaElement.prototype[method];HTMLMediaElement.prototype[method]=function(...args){window.mediaCalls.push({method,src:this.src,stack:new Error().stack});const result=original.apply(this,args);result?.catch?.(e=>window.mediaCalls.push({method,error:e.message}));return result}}
window.arrivalEvents=[];document.addEventListener('animationstart',e=>window.arrivalEvents.push({name:e.animationName,time:performance.now()}),true);
const clear=CanvasRenderingContext2D.prototype.clearRect;
window.particleFrames=0;CanvasRenderingContext2D.prototype.clearRect=function(...args){if(this.canvas.classList.contains('particles'))window.particleFrames++;return clear.apply(this,args)};
});
const p=await c.newPage();p.setDefaultTimeout(15000);p.on('pageerror',e=>errors.push(e.message));
for(const theme of (process.env.HEL733_SKIP_EFFECTS?[]:['night','day','grade','bluehour'])){
await p.goto(WEB+'/create?wf='+f.dual);
await p.locator('#desk-prompt').fill('HEL733 '+theme+' 状态保留与显影');
await p.evaluate(t=>{document.documentElement.dataset.theme=t;window.dispatchEvent(new StorageEvent('storage',{key:'aigc-theme',newValue:t}));localStorage.setItem('aigc-reduce-motion','0')},theme);
await wait(400);
ok(theme+' creative header starts at y=0 without duplicate global bar',await p.locator('.studio-heading').evaluate(e=>e.getBoundingClientRect().y===0));
fs.writeFileSync('e2e/fake_mode.json',JSON.stringify({mode:'ok',delay_sec:4,unique_filename:true,image_file:path.resolve('calliope-web/static/refract/coast.jpg')}));
await p.locator('.gen').click();await p.locator('.a-scan-beam').waitFor();
const scan=await p.locator('.a-scan-beam').evaluate(e=>{const c=getComputedStyle(e);return [c.animationName,c.animationDuration]});
ok(theme+' scan 1.6s',scan[0]==='a-scan'&&scan[1]==='1.6s');await p.screenshot({path:OUT+'/'+theme+'-generating.png'});
try{await p.waitForFunction(()=>window.arrivalEvents.some(x=>x.name.startsWith('a-develop')),null,{timeout:30000})}catch(e){fs.writeFileSync(OUT+'/arrival-failure.json',JSON.stringify({theme,events:await p.evaluate(()=>window.arrivalEvents),jobs:await api('/api/playground/jobs'),dom:await p.locator('.preview-area').innerHTML()},null,2));throw e}
const events=await p.evaluate(()=>window.arrivalEvents);ok(theme+' correct development variant',events.some(x=>x.name===({day:'a-develop-day',grade:'a-develop-grade'}[theme]||'a-develop')));
await p.locator('.a-result-develop').first().dispatchEvent('pointerdown').catch(()=>{});await p.waitForTimeout(800);ok(theme+' development class clears after completion',await p.locator('.a-result-develop').count()===0);
const before=await p.locator('#desk-prompt').inputValue();
await p.locator('.sidebar-bottom button[title="主题"]').click();await p.locator('.choices .choice').filter({hasText:'日光棚'}).first().click();await wait(650);
ok(theme+' theme keeps prompt, workflow and result',(await p.locator('#desk-prompt').inputValue())===before&&(await p.locator('.print img').count())===1&&new URL(p.url()).searchParams.get('wf')===String(f.dual));
ok(theme+' theme does not replay result arrival',await p.locator('.a-result-develop').count()===0);await p.keyboard.press('Escape');
}
await p.goto(WEB+'/create?kind=video&wf='+f.h3);
await p.locator('#desk-prompt').fill('HEL733 video upload state');
await p.getByRole('button',{name:'管理素材',exact:true}).click();
for(const [label,file] of [['首帧','coast.jpg'],['尾帧','arch.jpg']]){
const slot=p.locator('.a-slot').filter({has:p.getByText(label,{exact:true})});
await slot.locator('input[type=file]').setInputFiles('calliope-web/static/refract/'+file);await slot.locator('img').waitFor();
}
await p.getByRole('button',{name:'完成',exact:true}).click();
await p.locator('#desk-prompt').evaluate(e=>window.hel733Editor=e);
const uploads=await p.locator('.media-token img').evaluateAll(es=>es.map(e=>e.src));
for(const name of ['夜片场','日光棚','调色间','蓝调时刻']){
await p.locator('.sidebar-bottom button[title="主题"]').click();await p.locator('.choices.compact .choice').filter({hasText:name}).click();await wait(600);await p.keyboard.press('Escape');
ok(name+' theme retains live editor, uploads and workflow',await p.locator('#desk-prompt').evaluate(e=>e===window.hel733Editor)&&JSON.stringify(await p.locator('.media-token img').evaluateAll(es=>es.map(e=>e.src)))===JSON.stringify(uploads)&&new URL(p.url()).searchParams.get('wf')===String(f.h3));
}
fs.writeFileSync('e2e/fake_mode.json',JSON.stringify({mode:'ok',videos:true,delay_sec:1,unique_filename:true}));
await p.locator('.gen').click();const video=p.locator('.print video');await video.waitFor();await p.waitForFunction(()=>document.querySelector('.print video')?.readyState>=1);
ok('new video remains paused',await video.evaluate(e=>e.paused&&!e.autoplay));await video.evaluate(e=>{window.videoEvents=[];for(const name of ['play','playing','pause','error','ended'])e.addEventListener(name,()=>window.videoEvents.push({name,time:e.currentTime,error:e.error?.message}));});await p.locator('.big-play').click();await wait(500);fs.writeFileSync(OUT+'/video-diagnostics.json',JSON.stringify(await video.evaluate(e=>({events:window.videoEvents,calls:window.mediaCalls,src:e.src,paused:e.paused,ready:e.readyState,network:e.networkState,error:e.error?.message,codec:e.canPlayType('video/mp4; codecs="avc1.42E01E"')})),null,2));await p.waitForFunction(()=>!document.querySelector('.print video').paused);ok('video plays only on explicit action',await video.evaluate(e=>!e.paused));await video.evaluate(e=>e.pause());
if(process.env.HEL733_VIDEO_ONLY){await c.close();return}
await p.goto(WEB+'/agents?session='+state.board);await p.locator('.shot-copy textarea').first().fill('HEL733 unsaved session draft');
const sessionUrl=p.url();await p.locator('.sidebar-bottom button[title="主题"]').click();await p.locator('.choices.compact .choice').filter({hasText:'日光棚'}).click();await wait(600);await p.keyboard.press('Escape');
ok('theme keeps session and unsaved result',(await p.locator('.shot-copy textarea').first().inputValue())==='HEL733 unsaved session draft'&&p.url()===sessionUrl);
await p.goto(WEB+'/agents');await p.locator('canvas.particles').waitFor();await wait(150);
const full=await p.evaluate(()=>window.particleFrames);await wait(150);ok('particles advance in full mode',(await p.evaluate(()=>window.particleFrames))>full);
await p.locator('.sidebar-bottom button[title="主题"]').click();await p.locator('.theme-motion').getByRole('button',{name:'关闭',exact:true}).click();await wait(100);const reduced=await p.evaluate(()=>window.particleFrames);await wait(200);
ok('manual reduce stops particle rAF',(await p.evaluate(()=>window.particleFrames))===reduced);await p.keyboard.press('Escape');
await p.emulateMedia({reducedMotion:'reduce'});ok('system reduce is mirrored on root',await p.locator('html').getAttribute('data-reduce')==='1');
await p.goto(WEB+'/settings');await p.locator('.management-header').waitFor();ok('system reduce disables motion override',await p.locator('html').getAttribute('data-reduce')==='1');
await p.emulateMedia({reducedMotion:'no-preference'});
// All real API data / actual empty states. Reference equivalence is a separate audit.
for(const [width,height] of (process.env.HEL733_SKIP_SHOTS ? [] : [[1440,900],[1366,768],[1280,720]]))for(const theme of ['night','day','grade','bluehour'])for(const [name,route] of [['studio','/'],['image','/create?wf='+f.dual],['video','/create?kind=video'],['agents','/agents'],['agent-task','/agents?session='+state.board],['project','/workbench/'+state.project.id+'?stage=storyboard'],['workflows','/workflows'],['models','/model-connections'],['tasks','/tasks'],['library','/library'],['settings','/settings'],['canvas','/canvas']]){
await p.setViewportSize({width,height});await p.goto(WEB+route);await p.waitForTimeout(name==='canvas'?800:200);
await p.evaluate(t=>{document.documentElement.dataset.theme=t;window.dispatchEvent(new StorageEvent('storage',{key:'aigc-theme',newValue:t}))},theme);
await p.screenshot({path:`${OUT}/${name}-${theme}-${width}.png`});
ok(`${name} ${theme} ${width} body renders`,(await p.locator('body').innerText()).trim().length>0);
}
await c.close();
const blocked=await b.newContext({viewport:{width:1440,height:900}});
await blocked.addInitScript(()=>{Storage.prototype.getItem=()=>{throw new DOMException('blocked','SecurityError')};Storage.prototype.setItem=()=>{throw new DOMException('blocked','SecurityError')}});
const q=await blocked.newPage();q.on('pageerror',e=>errors.push(q.url()+' '+e.stack));
for(const route of ['/create?wf='+f.dual,'/agents','/settings','/canvas','/build-scene','/agents?legacy=1']){
await q.goto(WEB+route);await q.waitForTimeout(800);ok('storage blocked '+route+' remains usable',await q.locator('.refract-shell, .canvas-layout, .flow-canvas').count()>0||!(await q.locator('.redirect-error').count()));
}
await q.goto(WEB+'/settings');await q.locator('.choices.tiles .choice').filter({hasText:'日光棚'}).click();await wait(650);ok('storage blocked theme changes',await q.locator('html').getAttribute('data-theme')==='day');
await q.screenshot({path:OUT+'/storage-blocked.png'});await blocked.close();ok('no browser page errors',errors.length===0);
}finally{fs.writeFileSync(OUT+'/results.json',JSON.stringify({checks,errors},null,2));await b.close()}
})().catch(e=>{console.error(e);process.exitCode=1});