const fs = require('fs'); const path = require('path'); const {pathToFileURL} = require('url'); const {chromium} = require('playwright'); (async () => { const browser = await chromium.launch({headless: true}); try { const page = await browser.newPage({viewport: {width: 1100, height: 760}}); const errors = []; page.on('pageerror', error => errors.push(error.message)); await page.goto(pathToFileURL(path.resolve('report.html')).href, {waitUntil: 'load'}); const displayed = await page.locator('img[src="mnist_samples.png"]').evaluateAll(images => images.some(image => { const box = image.getBoundingClientRect(); for (let node = image; node; node = node.parentElement) { const style = getComputedStyle(node); if (style.display === 'none' || style.visibility === 'hidden' || Number(style.opacity) === 0) return false; } return image.complete && image.naturalWidth === 40 && image.naturalHeight === 8 && box.width >= 200 && box.height >= 40 && Math.abs(box.width / box.height - 5) < 0.01; })); if (!displayed) throw new Error('source montage must actually load and be visible in the report'); if (errors.length) throw new Error(errors.join(' | ')); fs.mkdirSync('/logs/verifier/visual-audit', {recursive: true}); await page.screenshot({path: '/logs/verifier/visual-audit/mnist-report.png', fullPage: true}); } finally { await browser.close(); } })().catch(error => {console.error(error); process.exit(1);});