Files
aigc-home/e2e/krea-story-newline-document.mjs
T
2026-11-01 01:22:09 +08:00

62 lines
6.1 KiB
JavaScript

// Narrow local GET-only correction: decoded LF is different from JSON escaping.
import fs from 'node:fs';
import assert from 'node:assert/strict';
import {createHash} from 'node:crypto';
const {chromium}=await import(process.env.PLAYWRIGHT_MODULE||'playwright');
const out='.local-evidence/krea-story-newline-document/browser';fs.mkdirSync(out,{recursive:true});
const checks=[],requests=[],errors=[],blockedFonts=[],interceptions=[];
const check=(v,label)=>{assert.ok(v,label);checks.push(label);console.log('PASS '+label);};
const sha=s=>createHash('sha256').update(s,'utf8').digest('hex');
const name='Krea2_turbo_文生图_4_6_8宫格故事板';
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));
requests.push({method:'GET',url:'http://127.0.0.1:8247/api/workflows'});
const records=await(await fetch('http://127.0.0.1:8247/api/workflows')).json();
const record=records.find(r=>r.name===name);assert.ok(record);
const url=`http://127.0.0.1:8247/api/workflows/${record.id}`;requests.push({method:'GET',url});
const d=await(await fetch(url)).json(),b=d.doc_json.fixed_version;
check(b.matched&&b.counts.saved_fields===62&&b.comments.length===2,'实际GET匹配62位置/两Note');
check(b.steps[2]===b.flow[185]&&b.steps[2].includes('真实换行、连续空白及末尾换行原样保留')&&!b.steps[2].includes('字面反斜杠n'),'实际GET仅更正真实换行解释及flow副本');
const expected=[['244',6918,27,'7b7d74fbd50ed3779b55126f3aa3df2271c940f966e737e81d8ab9ae4659ebea'],['76',1003,6,'903313c2c0df70bd863601c60a15646d64236aec23aa1ba98870ff0e93a56b2a']];
for(const [nid,length,lf,hash] of expected){const v=b.fields.find(f=>f.node_id===nid&&f.field==='value').value;check([...v].length===length&&v.split('\n').length-1===lf&&!v.includes('\\n')&&v.endsWith('\n')&&sha(v)===hash,`GET ${nid}全文长度/真实LF/字面序列0/尾LF/UTF8 SHA`);}
await page.goto('http://127.0.0.1:5173/connections',{waitUntil:'networkidle'});
const dialog=page.getByRole('dialog',{name:'工作流说明'});
const card=dialog.locator('.card').filter({has:page.getByText('固定版本参数说明',{exact:true})});
for(const width of [1440,390]){
await page.setViewportSize({width,height:width===390?844:1000});
const row=page.locator('.wf-row').filter({has:page.getByText(name,{exact:true})}).first();const 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)));
check((await dialog.innerText()).includes(name),'完整条目名定位 '+width);
check(!d.is_enabled&&!d.doc_completed_at&&!d.exec_verified_at,'停用与定稿实跑空时间戳 '+width);
await dialog.getByText('核对范围与来源依据',{exact:true}).click();
const corrected=card.getByText(b.flow[185],{exact:true});await corrected.scrollIntoViewIfNeeded();
check(await corrected.isVisible(),'更正解释实际可见 '+width);
await page.screenshot({path:`${out}/${width}-corrected-flow.png`});
const step=dialog.locator('li').filter({hasText:b.steps[2]});check(await step.count()===1,'使用步骤派生解释同步 '+width);
for(const [nid,length,lf,hash] of expected){
const field=b.fields.find(f=>f.node_id===nid&&f.field==='value');const summary=card.locator(`details[data-fixed-field="${field.pointer}"] > summary`);await summary.focus();await page.keyboard.press('Enter');const box=summary.locator('..');const rendered=await box.locator(':scope > pre').first().textContent();
check(rendered===field.value&&[...rendered].length===length&&sha(rendered)===hash,`${width} ${nid}界面全文与原值UTF8 SHA相等`);
check(rendered.split('\n').length-1===lf&&!rendered.includes('\\n')&&rendered.endsWith('\n'),`${width} ${nid}真实LF/无字面序列/末尾LF`);
check(await dialog.locator('.drawer-body').evaluate(el=>el.scrollWidth<=el.clientWidth),`${width} ${nid}全文无横溢`);
await summary.evaluate(el=>el.scrollIntoView({block:'start'}));await page.screenshot({path:`${out}/${width}-${nid}-full-value.png`});await summary.click();
}
check(await dialog.locator('.drawer-body').evaluate(el=>el.scrollWidth<=el.clientWidth),'更正页面无横溢 '+width);
await page.keyboard.press('Escape');await dialog.waitFor({state:'hidden'});check(await button.evaluate(el=>el===document.activeElement),'关闭归还焦点 '+width);
}
check(errors.length===0,'禁止请求/脚本错误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));const 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}/actual-get.json`,JSON.stringify(d,null,2)+'\n');
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,scope:'仅更正解释/两个完整原值,旧共享3454证据绑定f0affd5沿用,不累计',interceptions,checks,requests,errors,blockedFonts,viewports:[1440,390]},null,2)+'\n');
}finally{await browser.close();}