// Narrow source-history correction: no source execution or external/media requests. 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/animate2-history-document/browser';fs.mkdirSync(out,{recursive:true}); const C='docs/hel-892/animate2-loop-document-evidence/history-correction'; const old=JSON.parse(fs.readFileSync(C+'/before/docs/hel-892/animate2-loop-document-evidence/definition-0.json')); const rows=JSON.parse(fs.readFileSync('docs/hel-892/animate2-loop-reference/sources.json')).sources; const requests=[],interceptions=[],errors=[],blockedFonts=[],checks=[],textRenderings=[]; function check(value,label){assert.ok(value,label);checks.push(label);console.log('PASS '+label);} function local(raw){const u=new URL(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 '+raw);return u;} 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(()=>local(raw));check(true,'URL拒绝未发送 '+raw);} requests.push({method:'GET',url:'http://127.0.0.1:8247/api/workflows'}); const records=await(await fetch(local('http://127.0.0.1:8247/api/workflows'))).json(); const record=records.find(r=>r.name==='Wan_Animate2_动作迁移_for循环长视频');assert.ok(record); const url=`http://127.0.0.1:8247/api/workflows/${record.id}`;requests.push({method:'GET',url});const raw=await(await fetch(local(url))).text();const d=JSON.parse(raw);fs.writeFileSync(out+'/actual-get.json',raw);const b=d.doc_json.fixed_version; for(const key of Object.keys(old).filter(k=>k!=='sources'))assert.deepEqual(b[key],old[key]); check(true,'230原值/类型/5Note/历史/边界/全部非来源内容冻结'); for(let i=0;i=80&&i<85){const e=b.sources[i];assert.deepEqual(e.prior_acquisition_records,[]);check(e.current_fetch_at.startsWith('未知:')&&e.acquisition_time===old.sources[i].acquisition_time&&e.reverified_at===old.sources[i].reverified_at&&e.sha256===old.sources[i].sha256&&e.commit===old.sources[i].commit,`五来源${i}仅修历史/未知fetch/不改原取得复核或身份`);assert.equal(e.current_fetch_at,rows[i].current_fetch_at);assert.equal(e.acquisition_basis,rows[i].acquisition_basis);} else assert.deepEqual(b.sources[i],old.sources[i]); } check(true,'其它81基础来源及全部额外类引用冻结'); 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()); 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{local(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 '+u);return route.abort();}return route.continue();}); page.on('pageerror',e=>errors.push(e.message));page.on('request',r=>{if(r.url().includes('/api/'))requests.push({method:r.method(),url:r.url()});}); await page.goto(local('http://127.0.0.1:5173/connections').href,{waitUntil:'networkidle'}); const dialog=page.getByRole('dialog',{name:'工作流说明'});const fixed=dialog.locator('.card').filter({has:page.getByText('固定版本参数说明',{exact:true})}); async function open(name){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)));return button;} for(const width of [1440,390]){ await page.setViewportSize({width,height:width===390?844:1000});const button=await open(d.name); check((await dialog.innerText()).includes(b.user_overview),`${width}用途冻结/回退可用`); await page.screenshot({path:`${out}/${width}-history-default.png`}); const f=b.fields.find(f=>f.node_id==='245'&&f.field==='fps');assert.ok(f);const field=fixed.locator(`details[data-fixed-field="${f.pointer}"]`);await field.locator(':scope > summary').click();await field.getByText('来源依据',{exact:true}).click(); for(let i=80;i<85;i++){ const e=b.sources[i];const paragraph=field.locator('p').filter({hasText:e.claim});await paragraph.waitFor();const text=await paragraph.innerText(); check(text.includes(e.file)&&text.includes(e.sha256)&&text.includes(e.commit)&&text.includes(e.acquisition_time)&&text.includes(e.reverified_at)&&text.includes(e.current_fetch_at)&&text.includes('有效旧同身份取得引用0条'),`${width}来源${i}真实GET历史/日期/身份/unknown DOM`); await paragraph.evaluate(el=>el.scrollIntoView({block:'start'}));await dialog.locator('.drawer-body').evaluate(el=>{el.scrollTop=Math.max(0,el.scrollTop-60);});await page.screenshot({path:`${out}/${width}-history-source-${i}.png`}); } await field.locator(':scope > summary').click(); const notes=dialog.locator('.card').filter({has:page.getByText('源文件注释',{exact:true})}); for(const n of b.comments){const entry=notes.locator('details').filter({has:page.getByText(`节点 ${n.node_id}`,{exact:true})});await entry.locator('summary').click();const rendered=await entry.locator('pre').textContent();assert.deepEqual(JSON.parse(rendered),[n.text]);textRenderings.push({viewport:width,kind:'Note'+n.node_id,decoded_sha256:crypto.createHash('sha256').update(n.text).digest('hex')});check(true,`${width}Note${n.node_id}原串/尾LF/DOM核准`);await entry.locator('summary').click();} const history=b.fields.find(f=>f.node_id==='585'&&f.field==='videopreview');const box=fixed.locator(`details[data-fixed-field="${history.pointer}"]`);await box.locator(':scope > summary').click();assert.deepEqual(JSON.parse(await box.locator(':scope > pre').textContent()),history.value);check(true,`${width}完整历史纯文本不预览`);await box.locator(':scope > summary').evaluate(el=>el.scrollIntoView({block:'start'}));await page.screenshot({path:`${out}/${width}-history-media-text.png`}); check(await dialog.locator('img,canvas,video,audio,iframe').count()===0&&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}关闭归还焦点`); for(const name of ['旧工作流回退(隔离测试夹具)','空说明回退(隔离测试夹具)']){await open(name);check((await dialog.innerText()).includes('隔离库旧条目回退测试'),`${width}旧/空说明回退`);await page.keyboard.press('Escape');await dialog.waitFor({state:'hidden'});} } check(errors.length===0,'无脚本错误或禁止请求');check(requests.every(r=>r.method==='GET'&&local(r.url)&&!r.url.includes('/api/view')),'全程本机只读GET'); const polling=requests.filter(r=>['/api/jobs','/api/events'].includes(new URL(r.url).pathname));const fixedRequests=requests.filter(r=>!polling.includes(r));const count=xs=>Object.fromEntries([...new Set(xs.map(r=>new URL(r.url).pathname))].map(p=>[p,xs.filter(r=>new URL(r.url).pathname===p).length])); fs.writeFileSync(out+'/browser-results.json',JSON.stringify({assertion_count:checks.length,assertionGroups:{narrow_history:checks.length},checks,errors,viewports:[1440,390],requests,interceptions,blockedFonts,text_renderings:textRenderings,request_accounting:{fixed_count:fixedRequests.length,fixed_paths:count(fixedRequests),polling_count:polling.length,polling_paths:count(polling)}},null,2)); }finally{await browser.close();}