Files
aigc-home/e2e/director-story-override.mjs
T

93 lines
8.7 KiB
JavaScript

// Local GET-only:81 saved positions,1 complete Note; no upstream or media execution.
import fs from 'node:fs';
import assert from 'node:assert/strict';
import crypto from 'node:crypto';
const { chromium } = await import(process.env.PLAYWRIGHT_MODULE || 'playwright');
const out='.local-evidence/director-story-override/browser';fs.mkdirSync(out,{recursive:true});
const checks=[],requests=[],errors=[],blockedFonts=[],assertionGroups={},interceptions=[];let group='aggregate';
const textRenderings=[];
function check(condition,label){assert.ok(condition,label);checks.push(label);assertionGroups[group]=(assertionGroups[group]||0)+1;console.log('PASS '+label);}
function assertLocalUrl(raw){
const u=new URL(String(raw));assert.ok(u.protocol==='http:'&&['127.0.0.1','localhost'].includes(u.hostname)&&['8247','5173'].includes(u.port)&&!u.username&&!u.password,'Refused before request: '+u);return u;
}
function localFetch(raw){assertLocalUrl(raw);return fetch(raw);}
for(const raw of ['http://6.0.0.1:8247/api/workflows','http://127.0.0.1:9999/','https://example.invalid/','http://127.0.0.1:8247@evil.invalid/']){assert.throws(()=>assertLocalUrl(raw));check(true,'URL预检拒绝且未发送 '+raw);}
for(const raw of ['http://127.0.0.1:8247/api/workflows','http://127.0.0.1:5173/connections'])assertLocalUrl(raw);
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.routeWebSocket('**/*',ws=>{ws.close();}); // No HMR socket transport is needed for read-only checks.
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:''});}
try{assertLocalUrl(u);}catch(e){errors.push(String(e));return route.abort();}
if(route.request().method()!=='GET'||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 localFetch('http://127.0.0.1:8247/api/workflows')).json();
const drecord=records.find(r=>r.name==='MiniMax_H3_导演台_短剧创作-多宫格分镜参考');assert.ok(drecord);
const url=`http://127.0.0.1:8247/api/workflows/${drecord.id}`;requests.push({method:'GET',url});
const d=await(await localFetch(url)).json(), b=d.doc_json.fixed_version;
const exported=JSON.parse(fs.readFileSync(`docs/hel-892/director-story-override-correction/actual-${d.name}.json`));
assert.deepEqual(d.doc_json,exported);check(true,'完整实际GET与隔离导出全等');
fs.writeFileSync(`${out}/actual-get.json`,JSON.stringify(d,null,2)+'\n');
const dialog=page.getByRole('dialog',{name:'工作流说明'});
const fixedCard=dialog.locator('.card').filter({has:page.getByText('固定版本参数说明',{exact:true})});
for(const width of [1440,390]){
await page.setViewportSize({width,height:width===390?844:1000});
await page.goto(assertLocalUrl('http://127.0.0.1:5173/connections').href,{waitUntil:'networkidle'});
const row=page.locator('.wf-row').filter({has:page.getByText(d.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)));
const overview=dialog.locator('.card').filter({has:page.getByText('用途与来源',{exact:true})});
check((await overview.innerText()).includes(b.user_overview),`${width}默认用途完整`);
check(!(await dialog.getByText('核对范围与来源依据',{exact:true}).locator('..').evaluate(el=>el.open)),`${width}来源默认折叠`);
check(await dialog.locator('.drawer-body').evaluate(el=>el.scrollWidth<=el.clientWidth),`${width}默认无横溢`);
await page.screenshot({path:`${out}/${width}-default.png`});
await dialog.getByText('核对范围与来源依据',{exact:true}).click();
const flow=await fixedCard.innerText();
for(const i of [241,401]) check(flow.replace(/\s+/g,' ').includes(b.flow[i].replace(/\s+/g,' ')),`${width}flow/${i}准确类说明`);
check(b.steps[3].includes('只读取prompt_override而未使用')&&b.steps[3].includes('TimelineEditor')&&b.steps[3].includes('tooltip'),`${width}steps/3保留schema实现差异`);
await fixedCard.getByText(b.flow[241],{exact:true}).first().evaluate(el=>el.scrollIntoView({block:'start'}));
await page.screenshot({path:`${out}/${width}-source-correction.png`});
for(const f of b.fields.filter(f=>f.node_id==='29')){
const box=fixedCard.locator(`details[data-fixed-field="${f.pointer}"]`),summary=box.locator(':scope > summary');
await summary.focus();await page.keyboard.press('Enter');
check(await box.evaluate(el=>el.open),`${width}29.${f.field}展开`);
let text=await box.innerText();
check(text.replace(/\s+/g,' ').includes(f.effect.replace(/\s+/g,' ')),`${width}29.${f.field}更正效果全文`);
for(const part of ['只读取prompt_override而未使用','1 Store/0 Load','本类没有实际覆盖分支','TimelineEditor','tooltip','不据此推断目标环境一定不支持'])check(text.includes(part),`${width}29.${f.field} ${part}`);
const rendered=await box.locator(':scope > pre').first().textContent();
assert.equal(rendered,f.value);check(true,`${width}29.${f.field}完整原值`);
await box.getByText('来源依据',{exact:true}).click();text=await box.innerText();
check(text.includes(f.pointer)&&text.includes(f.named_pointer)&&f.evidence.every(i=>text.includes(b.sources[i].sha256)),`${width}29.${f.field}原来源与双指针`);
check(await dialog.locator('.drawer-body').evaluate(el=>el.scrollWidth<=el.clientWidth),`${width}29.${f.field}无横溢`);
await summary.evaluate(el=>el.scrollIntoView({block:'start'}));await page.screenshot({path:`${out}/${width}-29-${f.field}.png`});
if(f.field==='track_data'){
const sha=crypto.createHash('sha256').update(rendered,'utf8').digest('hex');
check(sha==='f7724df6ecd18533da9ce9229dd76a132a22d9c5720b2275d71ed8efaf3c07ae'&&rendered.length===40418,`${width}完整轨道DOM原串SHA`);
assert.deepEqual(JSON.parse(rendered),JSON.parse(fs.readFileSync('docs/hel-892/director-story-document-evidence/source-check.json')).parsed_track_data);check(true,`${width}所有轨道嵌套值冻结`);
textRenderings.push({viewport:width,kind:'track_data',sha256:sha,codepoints:rendered.length});
}
await summary.click();
}
const noteBox=dialog.locator('.card').filter({has:page.getByText('源文件注释',{exact:true})}),nd=noteBox.locator('details').first();await nd.locator('summary').click();
const rendered=await nd.locator('pre').textContent();assert.equal(rendered,JSON.stringify(d.doc_json.source_notes[0].content,null,2));check(true,`${width}完整Note JSON原文`);
const note=JSON.parse(rendered)[0],sha=crypto.createHash('sha256').update(note,'utf8').digest('hex');
check(note===b.comments[0].text&&note.length===813&&sha==='15c6be6b87e756890d954458294e2bc5f4c5becf5a4053935b6f1456675d206f',`${width}解码Note813原SHA`);
textRenderings.push({viewport:width,kind:'Note',raw_sha256:sha,rendered_json_sha256:crypto.createHash('sha256').update(rendered,'utf8').digest('hex')});
await nd.evaluate(el=>el.scrollIntoView({block:'start'}));await page.screenshot({path:`${out}/${width}-note.png`});
check(await dialog.locator('img,canvas,video,audio,iframe').count()===0,`${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 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]));
const polling=requests.filter(r=>['/api/jobs','/api/events'].includes(new URL(r.url).pathname));const fixed=requests.filter(r=>!polling.includes(r));
fs.writeFileSync(`${out}/browser-results.json`,JSON.stringify({assertion_count:checks.length,fixture_interceptions:0,checks,requests,errors,blockedFonts,text_renderings:textRenderings,viewports:[1440,390],request_accounting:{fixed_count:fixed.length,fixed_paths:frequencies(fixed),polling_count:polling.length,polling_paths:frequencies(polling)}},null,2)+'\n');
} finally {await browser.close();}