// Local-only verification of the same settled answer with baseline, // candidate, and restored stylesheet bytes. Does not modify site files. const assert = require('node:assert/strict'); const { createHash } = require('node:crypto'); const { readFileSync } = require('node:fs'); const { join } = require('node:path'); const { chromium } = require('playwright'); const documentRoot = join(__dirname, 'zenith-work.pvg9Vbpm'); const backup = join(__dirname, 'zenith-rollback.qplnpnz7', 'zenith.css.before'); const address = 'http://127.0.0.1:4177'; const seed = '9' + '0'.repeat(36); const sizes = [[320, 568], [568, 320], [844, 390], [1000, 370], [1280, 800]]; const baseline = readFileSync(backup); const candidate = readFileSync(join(documentRoot, 'zenith', 'zenith.css')); const sha = bytes => createHash('sha256').update(bytes).digest('hex'); async function inspect(browser, stage, colorScheme, stylesheet) { const context = await browser.newContext({ colorScheme, serviceWorkers: 'block' }); let served; await context.route('**/*', async route => { const url = new URL(route.request().url()); if (url.origin !== address) return route.abort(); if (url.pathname !== '/zenith/zenith.css') return route.continue(); if (stylesheet) { served = sha(stylesheet); return route.fulfill({ contentType: 'text/css', body: stylesheet }); } const response = await route.fetch(); assert.equal(response.status(), 200); served = sha(await response.body()); return route.fulfill({ response }); }); const page = await context.newPage(); page.setDefaultTimeout(7000); const errors = []; page.on('pageerror', e => errors.push(e.message)); const samples = []; try { for (const [width, height] of sizes) { served = undefined; await page.setViewportSize({ width, height }); await page.goto(`${address}/zenith/?layout-check=${width}x${height}#${seed}`); assert.equal(served, sha(stylesheet || candidate)); await page.locator('#answer[data-mode="media"] img').waitFor(); await page.locator('#loading-mark').waitFor({ state: 'hidden' }); await page.waitForFunction(() => { const img = document.querySelector('#answer[data-mode="media"] img'); return img?.complete && img.naturalWidth > 0; }); assert.equal(await page.locator('#seed-input').inputValue(), seed); const result = await page.evaluate(() => { const ids = ['special', 'soundtrack-toggle', 'soundtrack-status', 'info', 'zenith', 'media-toggle', 'hash']; const rects = ids.map(id => document.getElementById(id).getBoundingClientRect()); const overlap = []; const outside = []; for (const [i, a] of rects.entries()) { if (a.width <= 0 || a.height <= 0 || a.left < -1 || a.top < -1 || a.right > innerWidth + 1 || a.bottom > innerHeight + 1) outside.push(ids[i]); for (const [j, b] of rects.entries()) { if (i < j && a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top) overlap.push(`${ids[i]} + ${ids[j]}`); } } const foreground = document.querySelector('#answer[data-mode="media"] img').getBoundingClientRect(); const mediaOverlap = ids.filter((_, i) => { const b = rects[i]; return foreground.left < b.right - 1 && foreground.right > b.left + 1 && foreground.top < b.bottom - 1 && foreground.bottom > b.top + 1; }); return { overlap, outside, mediaOverlap, horizontal: document.documentElement.scrollWidth > innerWidth }; }); if (!result.mediaOverlap.length && stage === 'candidate' && colorScheme === 'light' && width === 844) { await page.screenshot({ path: join(__dirname, 'zenith layout verification landscape.png') }); } if (stage === 'candidate' && colorScheme === 'dark' && width === 320) { await page.screenshot({ path: join(__dirname, 'zenith layout verification portrait.png') }); } samples.push({ viewport: `${width}x${height}`, ...result }); } assert.deepEqual(errors, []); return samples; } finally { await context.close(); } } (async () => { assert.equal(sha(baseline), '48b50e8132af5f88dc07789b14959081d6abf657acdb909add9a7f0cdd9f7ce4'); assert.notEqual(sha(baseline), sha(candidate)); console.log(`sha256 baseline=${sha(baseline)} candidate=${sha(candidate)}`); const browser = await chromium.launch({ channel: 'chromium', headless: true }); try { for (const colorScheme of ['light', 'dark']) { const before = await inspect(browser, 'baseline', colorScheme, baseline); console.log(colorScheme, 'before:', JSON.stringify(before)); assert(before.every(s => s.overlap.includes('special + soundtrack-toggle'))); const after = await inspect(browser, 'candidate', colorScheme, null); console.log(colorScheme, 'candidate:', JSON.stringify(after)); assert(after.every(s => !s.overlap.length && !s.outside.length && !s.horizontal)); assert(after.every(s => !s.mediaOverlap.length), 'foreground answer behind controls'); const restored = await inspect(browser, 'restored', colorScheme, baseline); console.log(colorScheme, 'restored:', JSON.stringify(restored)); assert.deepEqual(restored, before); } console.log('pass: before / candidate / restored; site files unchanged'); } finally { await browser.close(); } })().catch(error => { console.error(error); process.exitCode = 1; });