// Real local detail GET, all 13 audio saved fields, both viewport sizes and document isolation. import fs from 'node:fs'; import assert from 'node:assert/strict'; const { chromium } = await import(process.env.PLAYWRIGHT_MODULE || 'playwright'); const out = '.local-evidence/background-reading-regression/audio-document/browser'; fs.mkdirSync(out, { recursive: true }); const checks = [], requests = [], errors = []; function check(value, text) { assert.ok(value, text); checks.push(text); console.log('PASS ' + text); } 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')return route.fulfill({contentType:'text/css',body:''}); if(u.hostname!=='127.0.0.1'||u.pathname==='/api/view') {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 list = await (await fetch('http://127.0.0.1:8247/api/workflows')).json(); const details = []; for (const name of ['音频转MP3格式', '音频人声分离', 'Minimax-H3提示词增强']) { const record = list.find(x => x.name === name); assert.ok(record); const url = `http://127.0.0.1:8247/api/workflows/${record.id}`; requests.push({ method:'GET', url }); details.push(await (await fetch(url)).json()); } check(details.map(d => d.doc_json.fixed_version.fields.length).join(',') === '5,8,18', '13新增保存定义与18旧H3定义独立'); await page.goto('http://127.0.0.1:5173/connections', { waitUntil: 'networkidle' }); const dialog = page.getByRole('dialog', { name: '工作流说明' }); async function begin(name) { const row = page.locator('.wf-row').filter({ has: page.locator('.wf-name').filter({ hasText:name }) }).first(); const button = row.getByRole('button', { name:'说明', exact:true }); await button.focus(); await page.keyboard.press('Enter'); return button; } async function loaded() { await dialog.getByText('用途与来源', {exact:true}).waitFor(); await dialog.evaluate(el => Promise.all(el.getAnimations().map(a => a.finished))); } for (const width of [1440,390]) { await page.setViewportSize({width,height:width===390?844:1000}); for (const detail of details.slice(0,2)) { const fixed = detail.doc_json.fixed_version; const button = await begin(detail.name); await loaded(); await dialog.getByText('核对范围与来源依据', {exact:true}).click(); check((await dialog.innerText()).includes(fixed.notice), `${width} ${detail.name}声明/假设提示`); for (const text of ['说明未定稿','未验证实跑','未检查']) check((await dialog.innerText()).includes(text), `${width} ${detail.name} ${text}`); check(!detail.is_enabled && detail.import_state==='needs_conversion' && !detail.doc_completed_at && !detail.exec_verified_at, `${width} ${detail.name}资格未改`); const names = fixed.fields.map(f => `节点 ${f.node_id} · ${f.label}`); for (const field of fixed.fields) { const summary = dialog.locator(`details[data-fixed-field="${field.pointer}"] > summary`); await summary.focus(); await page.keyboard.press('Enter'); const box = summary.locator('..'); check(await box.evaluate(el => el.open), `${width} ${field.node_id}.${field.field}键盘展开`); const text = await box.innerText(); check(text.includes(field.effect) && text.includes(field.limits) && text.includes(field.schema_default), `${width} ${field.node_id}.${field.field}语义/默认/限定`); check(await box.locator(':scope > pre').textContent() === (typeof field.value==='string'?field.value:JSON.stringify(field.value,null,2)), `${width} ${field.node_id}.${field.field}原值/类型/null/空值`); await box.getByText('来源依据',{exact:true}).click(); const evidence = await box.innerText(); check(evidence.includes(field.pointer) && field.evidence.every(i => { const e=fixed.sources[i]; return evidence.includes(e.commit) && evidence.includes(e.sha256) && evidence.includes(e.lines.join('~')); }), `${width} ${field.node_id}.${field.field}可回读依据`); check(!evidence.includes('undefined'), `${width} ${field.node_id}.${field.field}无伪具名指针`); check(await dialog.locator('.drawer-body').evaluate(el=>el.scrollWidth<=el.clientWidth), `${width} ${field.node_id}.${field.field}无溢出`); if (['audioUI','chunk_overlap','quality'].includes(field.field)) await page.screenshot({path:`${out}/${width}-${detail.id}-${field.field}.png`}); await summary.click(); } check(await dialog.locator('.card').filter({has:page.getByText('固定版本参数说明',{exact:true})}).locator('summary').filter({hasText:/节点 \d+ · /}).count() === names.length, `${width} ${detail.name}无跨图参数`); if (detail.name==='音频人声分离') { const text=await dialog.innerText(); check(text.includes('11槽3 Vocals → 15.audio') && text.includes('10槽0 → 18.audio') && text.includes('18槽0 → 11.audio'), `${width} 3连线/非零槽3`); check(text.includes('PreviewAudio15') && text.includes('临时目录FLAC') && text.includes('type=temp'), `${width} 无保存控件预览的临时文件副作用`); } else check((await dialog.innerText()).includes('1槽0 → 4.audio'), `${width} MP3连线`); await dialog.getByText('固定版本参数说明',{exact:true}).scrollIntoViewIfNeeded(); await page.screenshot({path:`${out}/${width}-${detail.id}-overview.png`}); await page.keyboard.press('Escape'); await dialog.waitFor({state:'hidden'}); check(await button.evaluate(el=>el===document.activeElement), `${width} ${detail.name}关闭归还焦点`); } // Return to H3 and back, ensuring definition lookup does not leak across records. for (const detail of [details[2],details[0],details[1]]) { await begin(detail.name); await loaded(); check(await dialog.locator('.card').filter({has:page.getByText('固定版本参数说明',{exact:true})}).locator('summary').filter({hasText:/节点 \d+ · /}).count()===detail.doc_json.fixed_version.fields.length, `${width}切换${detail.name}定义不串条`); await page.keyboard.press('Escape'); } } // Hold audio response, switch to another actual audio graph, then deliver the old response. let release, entered, delivered; const hold = new Promise(r=>release=r), intercept = new Promise(r=>entered=r), done = new Promise(r=>delivered=r); await page.route(`**/api/workflows/${details[0].id}`, async route=>{entered();await hold;await route.fulfill({json:details[0]});delivered();}); await begin(details[0].name); await intercept; await page.keyboard.press('Escape'); await begin(details[1].name); await loaded(); release(); await done; check(await dialog.locator('.card').filter({has:page.getByText('固定版本参数说明',{exact:true})}).locator('summary').filter({hasText:/节点 \d+ · /}).count()===8, '迟到MP3响应不覆盖人声分离8项'); await page.unroute(`**/api/workflows/${details[0].id}`); await page.keyboard.press('Escape'); check(errors.length===0,'浏览无脚本错误'); check(requests.every(r=>r.method==='GET' && new URL(r.url).hostname==='127.0.0.1'),'音频浏览全本地GET,无生成/目标机请求'); fs.writeFileSync(`${out}/browser-results.json`, JSON.stringify({checks,requests,errors,viewports:[1440,390]},null,2)); } finally { await browser.close(); }