94 lines
12 KiB
JavaScript
94 lines
12 KiB
JavaScript
// HEL-774 focused repair verification. Uses only the runner's disposable real API records.
|
|
const {chromium}=require(process.env.PLAYWRIGHT_MODULE_PATH || 'playwright');
|
|
const fs=require('node:fs'),http=require('node:http'),assert=require('node:assert/strict');
|
|
const out='../evidence', WEB='http://127.0.0.1:5173', API='http://127.0.0.1:8247';
|
|
const resume=process.env.HEL774_ONLY_OPS==='1';
|
|
const previous=resume?JSON.parse(fs.readFileSync('../evidence/results.json')):{checks:[]};
|
|
const rows=resume?JSON.parse(fs.readFileSync('../evidence/measurements.json')):[],checks=previous.checks,errors=[],tags=resume?JSON.parse(fs.readFileSync('../evidence/tags.json')):[];
|
|
const ok=(name,value)=>{assert(value,name);checks.push(name);console.log('PASS',name)};
|
|
const api=async(path,body,method)=>{const r=await fetch(API+path,{method:method||(body?'POST':'GET'),headers:{'Content-Type':'application/json'},body:body?JSON.stringify(body):undefined,signal:AbortSignal.timeout(15000)});assert(r.ok,await r.clone().text());return r.json()};
|
|
const fingerprint=loc=>loc.evaluate(e=>{const s=getComputedStyle(e),r=e.getBoundingClientRect();return Object.fromEntries(['backgroundColor','borderTopColor','borderTopWidth','paddingLeft','paddingRight','fontSize','fontWeight','borderRadius','transform','opacity'].map(k=>[k,s[k]]).concat([['width',r.width],['height',r.height]]))});
|
|
const wait=ms=>new Promise(r=>setTimeout(r,ms));
|
|
(async()=>{
|
|
fs.mkdirSync(out+'/images',{recursive:true});fs.mkdirSync(out+'/closeups',{recursive:true});
|
|
const server=http.createServer((req,res)=>{res.setHeader('Content-Type','text/html;charset=utf-8');res.end(fs.readFileSync('../attachments/夜片场-多主题交互样本.html'))});
|
|
const browser=await chromium.launch({executablePath:process.env.CHROMIUM_EXECUTABLE_PATH,args:['--no-sandbox','--disable-dev-shm-usage']});
|
|
await new Promise(r=>server.listen(0,'127.0.0.1',r));
|
|
const ctx=await browser.newContext();await ctx.tracing.start({screenshots:true,snapshots:true,sources:true});
|
|
const p=await ctx.newPage(),sp=await ctx.newPage();p.on('pageerror',e=>errors.push(e.message));p.setDefaultTimeout(15000);
|
|
try{
|
|
const projects=await api('/api/projects'),proj=projects.find(x=>x.title==='隔离验证 · 海岸来信');assert(proj);
|
|
const projectPath='/workbench/'+proj.id+'?stage=storyboard';
|
|
if(!resume)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 sp.goto('http://127.0.0.1:'+server.address().port);await sp.evaluate(t=>{document.documentElement.dataset.theme=t;document.documentElement.classList.add('reduce')},theme);
|
|
await p.goto(WEB);await p.evaluate(t=>{localStorage.setItem('aigc-theme',t)},theme);
|
|
for(const page of ['studio','project']){
|
|
const name=`${page}-${theme}-${width}`;
|
|
await p.goto(WEB+(page==='studio'?'/':projectPath));await p.locator(page==='studio'?'.confirm-item':'.storyboard-card').first().waitFor();
|
|
await sp.evaluate(v=>document.querySelectorAll('.page').forEach(e=>e.classList.toggle('on',e.id==='p-'+v)),page);
|
|
await p.mouse.move(0,0);await sp.mouse.move(0,0);await wait(400);
|
|
await p.screenshot({path:`${out}/images/${name}-actual.png`});await sp.screenshot({path:`${out}/images/${name}-sample.png`});
|
|
const scope=page==='studio'?'.home':'.project-workspace';
|
|
const selectors=await p.locator(scope+' .a-btn.secondary').evaluateAll(els=>els.map((e,i)=>({i,text:e.textContent.trim(),classes:e.className,disabled:!!e.disabled,tag:e.tagName})));
|
|
ok(name+' secondary controls present',selectors.length>0);
|
|
for(const item of selectors){
|
|
const al=p.locator(scope+' .a-btn.secondary').nth(item.i);
|
|
// Same text on a sample control, preserving the original sample's class rules.
|
|
const id='hel774-reference';await sp.evaluate(({id,text,small})=>{document.getElementById(id)?.remove();const e=document.createElement('button');e.id=id;e.className='btn'+(small?' sm':'');e.textContent=text;e.style.position='fixed';e.style.left='100px';e.style.top='100px';document.querySelector('.page.on').append(e)}, {id,text:item.text,small:item.classes.split(' ').includes('sm')});
|
|
const sl=sp.locator('#'+id);
|
|
// Every actual secondary instance, including small controls. Disabled anchors are ARIA fixtures.
|
|
for(const state of ['normal','hover','active','disabled']){
|
|
await al.evaluate(e=>{e.removeAttribute('disabled');e.removeAttribute('aria-disabled')});await sl.evaluate(e=>e.disabled=false);
|
|
await p.mouse.move(0,0);await sp.mouse.move(0,0);
|
|
if(state==='disabled'){await al.evaluate(e=>e.tagName==='BUTTON'?e.disabled=true:e.setAttribute('aria-disabled','true'));await sl.evaluate(e=>e.disabled=true)}
|
|
if(state==='hover'||state==='active'){await al.hover();await sl.hover()}
|
|
if(state==='active'){await p.mouse.down();await sp.mouse.down()}
|
|
await wait(220);const actual=await fingerprint(al),sample=await fingerprint(sl);
|
|
rows.push({page,theme,width,text:item.text,classes:item.classes,state,syntheticDisabled:state==='disabled',sample,actual});
|
|
const props=['backgroundColor','borderTopColor','borderTopWidth','paddingLeft','paddingRight','fontSize','fontWeight'];
|
|
if(state==='active')props.push('transform');
|
|
for(const key of props)assert.equal(actual[key],sample[key],`${name} ${item.text} ${state} ${key}`);
|
|
if(!item.classes.includes('b3-grow'))assert(Math.abs(actual.width-sample.width)<0.05,`${name} ${item.text} ${state} width ${actual.width} vs ${sample.width}`);
|
|
if(item.i===0 && (state==='normal'||state==='hover'||state==='disabled')){await al.screenshot({path:`${out}/closeups/${name}-${state}-actual.png`});await sl.screenshot({path:`${out}/closeups/${name}-${state}-sample.png`})}
|
|
if(state==='active'){await p.mouse.move(0,0);await sp.mouse.move(0,0);await p.mouse.up();await sp.mouse.up()}
|
|
}
|
|
await al.evaluate((e,disabled)=>{e.removeAttribute('aria-disabled');if(disabled)e.setAttribute('disabled','');else e.removeAttribute('disabled')},item.disabled);await sl.evaluate(e=>e.remove());
|
|
}
|
|
await p.mouse.move(0,0);await sp.mouse.move(0,0);
|
|
if(page==='studio'){
|
|
const a=await fingerprint(p.locator('.confirm-item').first()),s=await fingerprint(sp.locator('.confirm-item').first());rows.push({page,theme,width,selector:'.confirm-item',actual:a,sample:s});ok(name+' confirmation font inherits sample 13px',a.fontSize===s.fontSize&&a.fontSize==='13px');
|
|
await p.locator('.confirm-item').first().screenshot({path:`${out}/closeups/${name}-confirm-actual.png`});await sp.locator('.confirm-item').first().screenshot({path:`${out}/closeups/${name}-confirm-sample.png`});
|
|
}
|
|
const tagRows=await p.locator(scope+' .a-tag').evaluateAll(els=>els.map(e=>{const before=e.getBoundingClientRect();const saved=e.style.columnGap;e.style.columnGap='0px';const after=e.getBoundingClientRect();e.style.columnGap=saved;return {text:e.textContent.trim(),elements:e.children.length,childNodes:[...e.childNodes].filter(n=>n.nodeType!==3||n.textContent.trim()).map(n=>n.nodeType),before:before.width,after:after.width,gap:getComputedStyle(e).columnGap}}));tags.push({page,theme,width,tags:tagRows});ok(name+' single-content tags unaffected by gap',tagRows.every(t=>t.elements===0&&t.before===t.after));
|
|
// Primary and small variants keep their own existing padding.
|
|
ok(name+' primary padding preserved',await p.locator(scope+' .a-btn.primary').first().evaluate(e=>getComputedStyle(e).paddingLeft==='12px'));
|
|
}
|
|
// Keep actual empty state evidence, without manufacturing demo projects or media.
|
|
await p.route('**/api/projects',r=>r.fulfill({json:[]}));await p.goto(WEB);await p.locator('.studio-hero').waitFor();await wait(100);await p.screenshot({path:`${out}/images/empty-${theme}-${width}.png`});ok(`empty ${theme} ${width}`,await p.locator('.studio-display').innerText().then(t=>t.includes('从一个想法开始')));await p.unroute('**/api/projects');
|
|
}
|
|
// Meaningful operation checks for the affected buttons, with actual API persistence.
|
|
await p.goto(WEB);await p.locator('.studio-hero .secondary').waitFor();const heroHref=await p.locator('.studio-hero .secondary').getAttribute('href');await Promise.all([p.waitForURL(WEB+heroHref),p.locator('.studio-hero .secondary').click()]);ok('studio secondary opens real project stage',new URL(p.url()).pathname+new URL(p.url()).search===heroHref);
|
|
await p.goto(WEB+projectPath);await p.locator('.storyboard-card').first().waitFor();await p.getByRole('button',{name:'编辑',exact:true}).click();await p.locator('.shot-edit textarea').first().fill('HEL774 次级保存按钮实际操作');ok('editing prevents stale confirmation',await p.locator('[data-testid=stage-confirm-btn]').isDisabled());await p.route('**/stages/storyboard',async route=>{if(route.request().method()==='PATCH')await wait(1000);await route.continue()});await p.locator('[data-testid=stage-save-btn]').click();await p.locator('[data-testid=stage-save-btn]:disabled').waitFor();ok('save secondary disabled while request pending',await p.locator('[data-testid=stage-save-btn]').isDisabled());await p.screenshot({path:out+'/images/operation-save-pending.png'});for(let n=0;n<50;n++){if(JSON.stringify(await api('/api/workbench/projects/'+proj.id)).includes('HEL774 次级保存按钮实际操作'))break;await wait(100)}ok('secondary saves actual edited draft',JSON.stringify(await api('/api/workbench/projects/'+proj.id)).includes('HEL774 次级保存按钮实际操作'));await p.screenshot({path:out+'/images/operation-save.png'});await p.unroute('**/stages/storyboard');
|
|
await p.goto(WEB);await Promise.all([p.waitForURL('**/workbench/**'),p.locator('.confirm-item .secondary').first().click()]);ok('pending secondary navigates to draft',p.url().includes('/workbench/'));
|
|
await p.goto(WEB);await p.locator('.studio-search').click();ok('search remains functional',await p.getByRole('dialog').isVisible());await p.keyboard.press('Escape');await p.keyboard.press('Control+k');ok('search shortcut preserved',await p.getByRole('dialog').isVisible());await p.keyboard.press('Escape');
|
|
// B1/B2: compare live shared controls with exact previous shared declarations applied via CSSOM.
|
|
const protections=[];
|
|
for(const route of ['/create','/workflows','/tasks','/settings']){
|
|
await p.goto(WEB+route);await wait(800);
|
|
ok(route+' sidebar retained',await p.locator('aside.sidebar').isVisible());
|
|
for(const theme of ['night','day','grade','bluehour']){
|
|
await p.mouse.move(0,0);await p.evaluate(t=>document.documentElement.dataset.theme=t,theme);await wait(600);
|
|
const buttons=p.locator('.a-btn:visible');const count=await buttons.count();
|
|
const baseline=await buttons.evaluateAll(es=>es.map(e=>{const s=getComputedStyle(e),b=e.getBoundingClientRect();return {text:e.textContent.trim(),bg:s.backgroundColor,border:s.borderTopColor,pad:s.paddingLeft,width:b.width,height:b.height,font:s.fontSize}}));
|
|
await p.evaluate(()=>{window.hel774Rules=[];for(const sheet of document.styleSheets){let rules;try{rules=sheet.cssRules}catch{continue}for(const r of rules){if(!r.selectorText)continue;const sel=r.selectorText;if(sel==='.a-btn'){window.hel774Rules.push([r,r.style.cssText]);r.style.padding='0 var(--sp-6)'}if(sel==='.a-btn.secondary'){window.hel774Rules.push([r,r.style.cssText]);r.style.borderColor='var(--line)';r.style.removeProperty('--button-padding');r.style.removeProperty('--button-active-transform')}}}});
|
|
const previous=await buttons.evaluateAll(es=>es.map(e=>{const s=getComputedStyle(e),b=e.getBoundingClientRect();return {text:e.textContent.trim(),bg:s.backgroundColor,border:s.borderTopColor,pad:s.paddingLeft,width:b.width,height:b.height,font:s.fontSize}}));
|
|
await p.evaluate(()=>window.hel774Rules.forEach(([r,css])=>r.style.cssText=css));assert.deepEqual(baseline,previous,route+' default controls changed');protections.push({route,theme,count,baseline,previous});
|
|
await p.screenshot({path:`${out}/images/protect-${route.slice(1)}-${theme}.png`});
|
|
}
|
|
}
|
|
fs.writeFileSync(out+'/protections.json',JSON.stringify(protections,null,2));
|
|
ok('no browser errors',errors.length===0);
|
|
}finally{fs.writeFileSync(out+'/measurements.json',JSON.stringify(rows,null,2));fs.writeFileSync(out+'/tags.json',JSON.stringify(tags,null,2));fs.writeFileSync(out+'/results.json',JSON.stringify({checks,errors},null,2));await ctx.tracing.stop({path:out+'/interaction-trace.zip'});await browser.close();await new Promise(r=>server.close(r))}
|
|
})().catch(e=>{console.error(e);process.exitCode=1});
|