51 lines
5.3 KiB
JavaScript
51 lines
5.3 KiB
JavaScript
// Narrow actual GET and two viewport check for the Note163 count correction.
|
|
import fs from 'node:fs';
|
|
import assert from 'node:assert/strict';
|
|
const {chromium}=await import(process.env.PLAYWRIGHT_MODULE||'playwright');
|
|
const out='.local-evidence/zimage-upscale-note-correction-document/browser';
|
|
fs.mkdirSync(out,{recursive:true});
|
|
const requests=[],errors=[],blockedFonts=[],checks=[],interceptions=[];
|
|
const check=(ok,label)=>{assert.ok(ok,label);checks.push(label);console.log('PASS '+label);};
|
|
const browser=await chromium.launch({headless:true,executablePath:process.env.BROWSER_EXECUTABLE});
|
|
try{
|
|
const page=await browser.newPage({viewport:{width:1440,height:1000}});
|
|
await page.route('**/*',route=>{const u=new URL(route.request().url());if(u.hostname==='fonts.googleapis.com'){blockedFonts.push(String(u));return route.fulfill({contentType:'text/css',body:''});}if(route.request().method()!=='GET'||u.hostname!=='127.0.0.1'||u.pathname==='/api/view'||(/\.(mp4|png|wav|mp3|webm)$/i.test(u.pathname)&&u.pathname!=='/favicon.png')){errors.push('Forbidden request '+u);return route.abort();}return route.continue();});
|
|
page.on('request',r=>{if(r.url().includes('/api/'))requests.push({method:r.method(),url:r.url()});});
|
|
page.on('pageerror',e=>errors.push(e.message));
|
|
const get=async url=>{requests.push({method:'GET',url});const response=await fetch(url);assert.equal(response.status,200);return response.json();};
|
|
const records=await get('http://127.0.0.1:8247/api/workflows');
|
|
const record=records.find(r=>r.name==='11_Z_Image_Turbo+模型放大_图像4K高清放大');assert.ok(record);
|
|
const d=await get(`http://127.0.0.1:8247/api/workflows/${record.id}`),b=d.doc_json.fixed_version;
|
|
fs.writeFileSync(`${out}/actual-get.json`,JSON.stringify(d,null,2)+'\n');
|
|
const expected=JSON.parse(fs.readFileSync('docs/hel-892/zimage-upscale-note-correction-evidence/actual-11_Z_Image_Turbo+模型放大_图像4K高清放大.json'));
|
|
check(JSON.stringify(d.doc_json)===JSON.stringify(expected),'实际GET与隔离库更正doc一致');
|
|
const note=b.comments.find(n=>n.node_id==='162:163'),line='注释162:163 中文核对:'+note.meaning;
|
|
const raw=JSON.parse(fs.readFileSync(d.source_repo_path)).definitions.subgraphs[0].nodes[13].widgets_values[0];
|
|
check(note.text===raw&&raw.includes('1. ')&&raw.includes('2. ')&&!raw.includes('3. '),'原Note两条编号/空白/字面反斜杠n不变');
|
|
check(note.meaning.includes('两条编号建议')&&!JSON.stringify(b).includes('三步原文'),'GET只采用正确中文计数');
|
|
check(b.fields.length===25&&b.comments.length===6&&b.matched,'25位置六注释及摘要绑定保持');
|
|
await page.goto('http://127.0.0.1:5173/connections',{waitUntil:'networkidle'});
|
|
const dialog=page.getByRole('dialog',{name:'工作流说明'});
|
|
for(const width of [1440,390]){
|
|
await page.setViewportSize({width,height:width===390?844:1000});
|
|
const row=page.locator('.wf-row').filter({has:page.locator('.wf-name').filter({hasText:d.name})}).first(),button=row.getByRole('button',{name:'说明',exact:true});
|
|
await button.focus();await page.keyboard.press('Enter');await dialog.getByText('用途与来源',{exact:true}).waitFor();await dialog.evaluate(el=>Promise.all(el.getAnimations().map(a=>a.finished)));
|
|
await dialog.getByText('核对范围与来源依据',{exact:true}).click();
|
|
const text=await dialog.innerText();check(text.includes(note.meaning)&&!text.includes('三步原文'),`${width}显示两条编号建议且无错误计数`);
|
|
check(note.meaning.includes('最长边目标缩放、模型放大、0.5图像缩放、编码后采样'),`${width}实际处理链解释保留`);
|
|
await dialog.getByText(line,{exact:true}).scrollIntoViewIfNeeded();
|
|
check(await dialog.locator('.drawer-body').evaluate(el=>el.scrollWidth<=el.clientWidth),`${width}更正文案无横溢`);
|
|
await page.screenshot({path:`${out}/${width}-note163-correction.png`});
|
|
const sourceNote=d.doc_json.source_notes.find(n=>String(n.node_id).endsWith('/163'));
|
|
const summary=dialog.getByText(`节点 ${sourceNote.node_id}`,{exact:true});await summary.click();await summary.scrollIntoViewIfNeeded();
|
|
check(await summary.locator('..').locator('pre').textContent()===JSON.stringify(sourceNote.content,null,2),`${width}原注释全文不变`);
|
|
await page.screenshot({path:`${out}/${width}-note163-original.png`});
|
|
await page.keyboard.press('Escape');await dialog.waitFor({state:'hidden'});check(await button.evaluate(el=>el===document.activeElement),`${width}关闭归还焦点`);
|
|
}
|
|
check(errors.length===0,'无脚本错误或禁止请求');
|
|
check(requests.every(r=>r.method==='GET'&&new URL(r.url).hostname==='127.0.0.1'&&!r.url.includes('/api/view')),'全程本地GET无模型/媒体/目标请求');
|
|
const polling=requests.filter(r=>['/api/jobs','/api/events'].includes(new URL(r.url).pathname)),fixed=requests.filter(r=>!polling.includes(r));
|
|
const frequencies=rs=>Object.fromEntries([...new Set(rs.map(r=>new URL(r.url).pathname))].sort().map(p=>[p,rs.filter(r=>new URL(r.url).pathname===p).length]));
|
|
fs.writeFileSync(`${out}/browser-results.json`,JSON.stringify({request_accounting:{fixed_count:fixed.length,fixed_paths:frequencies(fixed),polling_count:polling.length,polling_paths:frequencies(polling),polling_tolerance:1},assertion_count:checks.length,assertionGroups:{narrow_note_correction:checks.length},interceptions,checks,requests,errors,blockedFonts,viewports:[1440,390]},null,2)+'\n');
|
|
}finally{await browser.close();}
|