// Narrow correction browser: real local GET/DOM, no fixtures, media or upstream 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/animate-time/browser'; fs.mkdirSync(out, { recursive: true }); const evidence = 'docs/hel-892/animate-time-correction'; const old = JSON.parse(fs.readFileSync('docs/hel-892/animate-document-evidence/actual-get.json')).doc_json; const expected = JSON.parse(fs.readFileSync(`${evidence}/${fs.readdirSync(evidence).find(n => n.startsWith('actual-Wan') && n.endsWith('.json'))}`)); const checks = [], requests = [], errors = [], blockedFonts = [], rendered = []; const check = (v, label) => { assert.ok(v, label); checks.push(label); console.log('PASS ' + label); }; const sha = raw => crypto.createHash('sha256').update(raw).digest('hex'); function local(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.href; } for (const u 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(u)); check(true, 'negative URL rejected before send ' + u); } async function get(url) { local(url); requests.push({ method: 'GET', url }); const r = await fetch(url); assert.equal(r.status, 200); return r; } const browser = await chromium.launch({ headless: true, executablePath: process.env.BROWSER_EXECUTABLE }); try { const page = await browser.newPage(); 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 request ' + u); return route.abort(); } return route.continue(); }); page.on('request', r => { if (new URL(r.url()).pathname.startsWith('/api/')) requests.push({ method: r.method(), url: r.url() }); }); page.on('pageerror', e => errors.push(e.message)); const records = await (await get('http://127.0.0.1:8247/api/workflows')).json(); const row = records.find(r => r.name === 'Wan2.2_Animate_SAM3-人物迁移-动作迁移-长视频循环(KJ流)'); assert.ok(row); const actualRaw = await (await get(`http://127.0.0.1:8247/api/workflows/${row.id}`)).text(); fs.writeFileSync(`${out}/actual-get.json`, actualRaw); const actual = JSON.parse(actualRaw); assert.deepEqual(actual.doc_json, expected); check(true, 'actual GET equals newly isolated doc_json'); const b = actual.doc_json.fixed_version; assert.deepEqual(b.fields, old.fixed_version.fields); assert.deepEqual(b.comments, old.fixed_version.comments); for (let i = 0; i < b.sources.length; i++) if (![116, 117, 127].includes(i)) assert.deepEqual(b.sources[i], old.fixed_version.sources[i]); check(b.fields.length === 270, 'all270 fields/type/schema/raw states frozen; other163 source records unchanged'); await page.goto(local('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 button = page.locator('.wf-row').filter({ has: page.getByText(row.name, { exact: true }) }).first().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 page.screenshot({ path: `${out}/${width}-default.png` }); for (const f of b.fields) { const box = dialog.locator(`[data-fixed-field="${f.pointer}"]`); const text = await box.locator(':scope > pre').textContent(); assert.equal(text, typeof f.value === 'string' ? f.value : JSON.stringify(f.value, null, 2)); check(true, `${width} frozen DOM ${f.pointer} ${f.json_type}`); } for (const [pointer, label, indices] of [ [b.fields.find(f => f.evidence.includes(116)).pointer, 'easy', [116, 117]], [b.fields.find(f => f.evidence.includes(127)).pointer, 'h264', [127]], ]) { const box = dialog.locator(`[data-fixed-field="${pointer}"]`); await box.locator(':scope > summary').click(); await box.getByText('来源依据', { exact: true }).click(); const text = await box.innerText(); for (const i of indices) { const e = b.sources[i]; assert.ok(Date.parse(e.reverified_at) >= Date.parse(e.acquisition_time)); check(text.includes(e.file) && text.includes(e.sha256) && text.includes(e.commit) && text.includes(e.reverified_at), `${width} source${i} actual GET time and visible DOM identity/date`); rendered.push({ viewport: width, index: i, acquisition_time: e.acquisition_time, reverified_at: e.reverified_at, claim: e.claim }); await box.locator('p').filter({ hasText: e.reverified_at }).first().evaluate(el => el.scrollIntoView({ block: 'start' })); await page.screenshot({ path: `${out}/${width}-date-${i}.png` }); } await box.locator(':scope > summary').click(); } const notes = dialog.locator('.card').filter({ has: page.getByText('源文件注释', { exact: true }) }).locator('details'); await notes.locator('summary').click(); const noteJSON = await notes.locator('pre').textContent(); const note = JSON.parse(noteJSON)[0]; check(note === b.comments[0].text && Array.from(note).length === 38 && note.endsWith('\n') && sha(note) === sha(old.fixed_version.comments[0].text), `${width} Note38/尾LF/original SHA`); await notes.evaluate(el => el.scrollIntoView({ block: 'start' })); await page.screenshot({ path: `${out}/${width}-note.png` }); for (const f of b.fields.filter(f => f.json_type === 'dict')) { const text = await dialog.locator(`[data-fixed-field="${f.pointer}"] > pre`).textContent(); assert.deepEqual(JSON.parse(text), f.value); rendered.push({ viewport: width, history_node: f.node_id, dom_sha256: sha(text) }); check(true, `${width} complete history${f.node_id} DOM SHA frozen`); } check(await dialog.locator('img,canvas,video,audio,iframe').count() === 0, `${width} no media/editor`); check(await dialog.evaluate(el => el.scrollWidth <= el.clientWidth + 2), `${width} no horizontal overflow`); await page.keyboard.press('Escape'); await dialog.waitFor({ state: 'hidden' }); check(await button.evaluate(el => el === document.activeElement), `${width} focus restored`); } check(errors.length === 0, 'no script errors/forbidden requests'); const paths = items => Object.fromEntries([...new Set(items.map(x => new URL(x.url).pathname))].map(p => [p, items.filter(x => new URL(x.url).pathname === p).length])); const poll = r => ['/api/jobs', '/api/events'].includes(new URL(r.url).pathname); fs.writeFileSync(`${out}/browser-results.json`, JSON.stringify({ assertion_count: checks.length, checks, requests, errors, blockedFonts, rendered, viewports: [1440, 390], get_text_sha256: sha(actualRaw), request_accounting: { fixed_paths: paths(requests.filter(r => !poll(r))), polling_paths: paths(requests.filter(poll)) }, inherited_full_browser_assertions: 7884, inherited_rerun: false }, null, 2)); } finally { await browser.close(); }