115 lines
9.8 KiB
JavaScript
115 lines
9.8 KiB
JavaScript
// Foreground static-build audit. All API reads use labelled, isolated inputs;
|
|
// all non-local requests and all product mutations are blocked.
|
|
import fs from 'node:fs/promises';
|
|
import http from 'node:http';
|
|
import path from 'node:path';
|
|
const { chromium } = await import(process.env.PLAYWRIGHT_MODULE || 'playwright');
|
|
const out = process.env.HEL733_OUT || '../evidence/hel733/before';
|
|
await fs.mkdir(out, { recursive: true });
|
|
const fixture = JSON.parse(await fs.readFile('../evidence/hel733/fixtures.json'));
|
|
const sample = await fs.readFile('../materials/夜片场-多主题交互样本.html');
|
|
const log = { errors: [], blocked: [], rows: [], requests: [] };
|
|
const server = http.createServer(async (req, res) => {
|
|
try {
|
|
const p = decodeURIComponent(new URL(req.url, 'http://local').pathname);
|
|
if (p === '/sample') { res.setHeader('Content-Type','text/html;charset=utf-8'); return res.end(sample); }
|
|
let file = path.join('calliope-web/build', p);
|
|
if (!path.extname(file)) file = 'calliope-web/build/index.html';
|
|
res.setHeader('Content-Type', file.endsWith('.js') ? 'text/javascript' : file.endsWith('.css') ? 'text/css' : 'text/html');
|
|
res.end(await fs.readFile(file));
|
|
} catch { res.writeHead(404); res.end(); }
|
|
});
|
|
await new Promise(r => server.listen(0,'127.0.0.1',r));
|
|
const base = `http://127.0.0.1:${server.address().port}`;
|
|
const browser = await chromium.launch({args:['--no-sandbox']});
|
|
const measure = (p, selectors) => p.evaluate(selectors => Object.fromEntries(Object.entries(selectors).map(([key,sel]) => {
|
|
const e=document.querySelector(sel); if(!e) return [key,null];
|
|
const r=e.getBoundingClientRect(),c=getComputedStyle(e);
|
|
return [key,{x:r.x,y:r.y,width:r.width,height:r.height,...Object.fromEntries(['fontSize','fontWeight','lineHeight','letterSpacing','backgroundColor','backgroundImage','borderRadius','color','padding','boxSizing','animationName','animationDuration'].map(k=>[k,c[k]]))}];
|
|
})),selectors);
|
|
try {
|
|
const c=await browser.newContext();
|
|
await c.addInitScript(()=>{
|
|
localStorage.setItem('aigc-lang','zh');localStorage.setItem('aigc-reduce-motion','1');
|
|
window.__sse=[];window.EventSource=class{constructor(){window.__sse.push(this);setTimeout(()=>this.onopen?.(),0)}addEventListener(t,f){(this.handlers??={})[t]=f}close(){}};
|
|
});
|
|
await c.route('**/*',async route=>{
|
|
const req=route.request(),u=new URL(req.url());
|
|
if(['data:','blob:'].includes(u.protocol))return route.continue();
|
|
if(u.origin!==base){log.blocked.push(req.url());return route.abort()}
|
|
if(!u.pathname.startsWith('/api/'))return route.continue();
|
|
log.requests.push([req.method(),u.pathname]);
|
|
if(req.method()!=='GET')return route.fulfill({status:403,body:'Isolated audit blocks mutations'});
|
|
const p=u.pathname;let body=[];
|
|
if(p==='/api/settings')body={comfyui_endpoints:[],llm_profiles:[],queue_concurrency:2,queue_poll_timeout_sec:1800,queue_poll_interval_sec:1,queue_max_retries:1,data_dir:'HEL733 isolated audit',dry_run:false};
|
|
if(p==='/api/jobs')body=u.searchParams.get('empty')?[]:fixture.jobs;
|
|
if(p==='/api/workflows')body=fixture.workflows;
|
|
if(p==='/api/projects')body=[{id:1,title:'雾港来信'}];
|
|
if(p==='/api/jobs/queue-status')body={paused:false};
|
|
if(p==='/api/comfyui/endpoints')body={endpoints:[],active_id:null};
|
|
if(p==='/api/agent/sessions')body=[];
|
|
if(p==='/api/agent/agents')body=[];
|
|
if(/^\/api\/workflows\/\d+$/.test(p))body={...fixture.workflows.find(x=>x.id===+p.split('/').pop()),workflow_json:{}};
|
|
if(p==='/api/file')return route.fulfill({status:404,body:'No audit media'});
|
|
return route.fulfill({json:body});
|
|
});
|
|
const a=await c.newPage(),s=await c.newPage();a.on('pageerror',e=>log.errors.push(e.message));
|
|
await s.goto(base+'/sample');await s.evaluate(()=>document.documentElement.classList.add('capture','reduce'));
|
|
const pages=process.env.HEL733_CREATE_ONLY ? [['create','create']] : process.env.HEL733_POP_ONLY ? [['settings','settings']] : process.env.HEL733_TASKS_ONLY ? [['tasks','tasks']] : [['','studio'],['create','create'],['agents','agents'],['workflows','workflows'],['connections','models'],['tasks','tasks'],['library','library'],['settings','settings']];
|
|
for(const [width,height] of [[1440,900],[1366,768],[1280,720]])for(const theme of ['night','day','grade','bluehour'])for(const [route,ref] of pages){
|
|
await a.setViewportSize({width,height});await s.setViewportSize({width,height});
|
|
await a.goto(base+'/'+route);await a.locator('aside.sidebar').waitFor();
|
|
await a.evaluate(t=>{document.documentElement.dataset.theme=t;window.dispatchEvent(new StorageEvent('storage',{key:'aigc-theme',newValue:t}));for(const es of window.__sse)for(const [id,progress] of [[1,62],[2,35]])es.handlers?.['job.progress']?.({data:JSON.stringify({type:'job.progress',data:{job_id:id,progress}})})},theme);
|
|
await s.evaluate(({ref,theme})=>{go(ref);renderTasks();document.documentElement.dataset.theme=theme;document.querySelector('#motionBtn span').textContent='动效关'},{ref,theme});
|
|
await a.waitForTimeout(400);
|
|
const as={rail:'aside.sidebar',brand:'aside.sidebar .brand',nav:'aside.sidebar nav a',divider:'aside.sidebar hr',queue:'.queue-dot',theme:'.sidebar-bottom button',settings:'.sidebar-bottom a[href="/settings"]',header:'.management-header, .studio-header, .studio-heading, .desk-head, .topbar',progress:'.task-progress',fill:'.task-progress i'};
|
|
const ss={rail:'.rail',brand:'.rail .brand',nav:'.rail>.nav',divider:'.rail hr',queue:'.rail .queue-dot',theme:'#themeBtn',settings:'.rail [data-go="settings"]',header:`#p-${ref} .ph`,progress:'#taskTable .bar',fill:'#taskTable .bar i'};
|
|
if(route==='create'){
|
|
Object.assign(as,{title:'.model-selector',primary:'.dock .gen',prompt:'#desk-prompt',workspace:'.reference-desk'});
|
|
Object.assign(ss,{title:'#hdName',primary:'#genBtn',prompt:'#posTa',workspace:'#p-create .create'});
|
|
}else if(route==='agents'){
|
|
Object.assign(as,{title:'.ahero h2',primary:'.big-input .primary',prompt:'.big-input textarea'});
|
|
Object.assign(ss,{title:'#p-agents .ahero h2',primary:'#p-agents .big-input .primary',prompt:'#p-agents .big-input textarea'});
|
|
}else if(['workflows','connections','tasks','library','settings'].includes(route)){
|
|
Object.assign(as,{title:'.management-header > b',primary:'.management-header .a-btn, .a-btn.primary',search:'.mg-search',input:'.mg-input, .field-input'});
|
|
Object.assign(ss,{title:`#p-${ref} .ph b`,primary:`#p-${ref} .ph .btn, #p-${ref} .btn.primary`,search:`#p-${ref} .ph .input`,input:`#p-${ref} .input`});
|
|
}
|
|
const name=`${route||'studio'}-${theme}-${width}`;
|
|
const row={route:route||'studio',ref,theme,width,height,actual:await measure(a,as),sample:await measure(s,ss)};
|
|
if(route==='tasks'){
|
|
row.actualTable=await a.locator('.task-table table').evaluate(e=>({columns:[...e.rows[1].cells].map(c=>({text:c.innerText,width:c.getBoundingClientRect().width,x:c.getBoundingClientRect().x,style:getComputedStyle(c).cssText})),html:e.outerHTML}));
|
|
row.sampleTable=await s.locator('#p-tasks table').evaluate(e=>({columns:[...e.rows[1].cells].map(c=>({text:c.innerText,width:c.getBoundingClientRect().width,x:c.getBoundingClientRect().x})),html:e.outerHTML}));
|
|
}
|
|
if(route==='tasks'){
|
|
const sources=await a.locator('.task-table tbody tr td:nth-child(3)').allTextContents();
|
|
await s.evaluate(sources=>{document.querySelectorAll('#taskTable tr').forEach((r,i)=>r.cells[2].textContent=sources[i])},sources);
|
|
row.sameSourceSample=await measure(s,{progress:'#taskTable .bar',fill:'#taskTable .bar i'});
|
|
}
|
|
log.rows.push(row);
|
|
if(route==='create') {
|
|
await a.evaluate(()=>document.documentElement.dataset.reduce='0');await s.evaluate(()=>document.documentElement.classList.remove('reduce'));
|
|
await a.locator('.workflow-row').first().hover({position:{x:40,y:20}});
|
|
await s.locator('#wfList .wfi').first().hover({position:{x:40,y:20}});
|
|
const pointer=await a.locator('.workflow-row').first().evaluate(e=>({x:e.style.getPropertyValue('--pointer-x'),y:e.style.getPropertyValue('--pointer-y')}));
|
|
await s.locator('#wfList .wfi').first().evaluate((e,p)=>{e.style.setProperty('--mx',p.x);e.style.setProperty('--my',p.y)},pointer);
|
|
row.hoverInput={mode:'full',pointer};
|
|
await a.waitForTimeout(350);
|
|
const pseudo=(p,sel,which)=>p.locator(sel).first().evaluate((e,which)=>{const c=getComputedStyle(e,which);return Object.fromEntries(['backgroundImage','maskImage','opacity','transitionDuration','transitionTimingFunction','zIndex'].map(k=>[k,c[k]]))},which);
|
|
row.hoverActual=await pseudo(a,'.workflow-row','::after');row.hoverSample=await pseudo(s,'#wfList .wfi','::before');
|
|
await a.mouse.move(0,0);await s.mouse.move(0,0);await a.waitForTimeout(350);await a.evaluate(()=>document.documentElement.dataset.reduce='1');await s.evaluate(()=>document.documentElement.classList.add('reduce'));
|
|
}
|
|
if(route==='settings') {
|
|
await a.locator('.sidebar-bottom button[title="主题"]').click();
|
|
await s.evaluate(()=>document.querySelector('#themePop').classList.add('on'));
|
|
await a.waitForTimeout(400);
|
|
row.themePopActual=await measure(a,{panel:'.modal-panel',row:'.choices.compact .choice',preview:'.choices.compact .preview'});
|
|
row.themePopSample=await measure(s,{panel:'#themePop',row:'.topt',preview:'.topt .tprev'});
|
|
await a.screenshot({path:`${out}/${name}-theme-pop-actual.png`});await s.screenshot({path:`${out}/${name}-theme-pop-sample.png`});
|
|
await a.keyboard.press('Escape');await s.evaluate(()=>document.querySelector('#themePop').classList.remove('on'));
|
|
}
|
|
await a.screenshot({path:`${out}/${name}-actual.png`,animations:'disabled'});await s.screenshot({path:`${out}/${name}-sample.png`,animations:'disabled'});
|
|
console.log(name);
|
|
}
|
|
await c.close();
|
|
}finally{await fs.writeFile(out+'/results.json',JSON.stringify(log,null,2));await browser.close();await new Promise(r=>server.close(r));}
|