aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / scripts / test-site-browser.mjs
| 1 | #!/usr/bin/env node |
| 2 | // Verification-only real-browser oracle for the Omega site cutover (PR #122). |
| 3 | // It drives Chromium over the DevTools protocol with Node's built-in WebSocket: |
| 4 | // no browser automation package. Launch is CPU-only (no GPU, no software |
| 5 | // rasterizer). Every request leaving the served origin is failed by the |
| 6 | // browser before it reaches the network; the X loader is intercepted and |
| 7 | // answered locally, so this tests consent gating, not ingestion by X. |
| 8 | // |
| 9 | // node scripts/test-site-browser.mjs --base http://127.0.0.1:8000 [--chrome PATH] [--report FILE] |
| 10 | // Serve dist with scripts/serve-like-hub.py so HTML travels gzip-compressed as on the hub; |
| 11 | // the throttled perf pass measures transfer sizes. |
| 12 | import { spawn } from 'node:child_process'; |
| 13 | import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'; |
| 14 | import { tmpdir } from 'node:os'; |
| 15 | import { join } from 'node:path'; |
| 16 | |
| 17 | const args = Object.fromEntries(process.argv.slice(2).reduce((acc, v, i, all) => (v.startsWith('--') && acc.push([v.slice(2), all[i + 1]]), acc), [])); |
| 18 | if (!args.base) { console.error('usage: test-site-browser.mjs --base URL [--chrome PATH] [--report FILE]'); process.exit(2); } |
| 19 | const BASE = new URL(args.base).origin; |
| 20 | const CHROME = args.chrome || 'google-chrome'; |
| 21 | const LOADER = 'https://static.ads-twitter.com/uwt.js'; |
| 22 | // Served by the live backend behind the edge, never by the static build; the |
| 23 | // pages must survive their absence without an exception. /now/ is the live factory |
| 24 | // floor (Drake 2026-11-08): the hub proxies all of /now/ to aien-floor.service |
| 25 | // (nginx snippets/aienos-now.conf, `location ^~ /now/`), so the floor stylesheets the |
| 26 | // homepage loads (/now/tokens.css, components.css, ...) exist only behind the edge. |
| 27 | const LIVE_ONLY = ['/aien/api/', '/hive/board/', '/now/']; |
| 28 | const liveOnly = u => { const x = new URL(u); return x.origin === BASE && LIVE_ONLY.some(p => x.pathname.startsWith(p)); }; |
| 29 | // A site navigation bar, as opposed to in-page jump lists or chat controls. |
| 30 | const TOPNAV = '.navbar, .aien-nav, nav[aria-label="Primary navigation"], body > header nav'; |
| 31 | const PAGES = ['/', '/classic/', '/omega/', '/machine/', '/discoveries/', '/learn/', '/aien/', '/engineer/', '/hive/', '/contact/', '/privacy/', '/404.html']; |
| 32 | const DESTINATIONS = ['/classic/', '/omega/', '/machine/', '/discoveries/', '/learn/']; |
| 33 | const WIDTHS = [[1365, 900], [390, 844]]; |
| 34 | // Lighthouse's simulated slow-4G mobile profile, applied as DevTools throttling: |
| 35 | // 150 ms RTT x 3.75 = 562.5 ms request latency, 1474.56 kbit/s down = 188743.68 B/s, |
| 36 | // 675 kbit/s up = 86400 B/s, CPU slowed 4x. Budgets are the web-vitals "good" limits. |
| 37 | const PERF = { latency: 562.5, down: 188743.68, up: 86400, cpu: 4, lcp: 2500, cls: 0.1 }; |
| 38 | const PERF_PAGES = ['/', '/classic/', '/omega/', '/machine/', '/discoveries/', '/learn/']; |
| 39 | const pause = ms => new Promise(r => setTimeout(r, ms)); |
| 40 | const failures = []; |
| 41 | const report = { base: BASE, pages: [], door: {}, consent: {}, perf: [] }; |
| 42 | const fail = (where, what) => { failures.push(`${where}: ${what}`); }; |
| 43 | |
| 44 | const INIT = `(() => { |
| 45 | const c = window.__chk = { csp: [], audio: 0, play: 0, lcp: 0, cls: 0 }; |
| 46 | addEventListener('securitypolicyviolation', e => c.csp.push(e.violatedDirective + ' ' + e.blockedURI)); |
| 47 | for (const k of ['AudioContext', 'webkitAudioContext']) { |
| 48 | const A = window[k]; |
| 49 | if (A) window[k] = class extends A { constructor(...a) { super(...a); c.audio++; } }; |
| 50 | } |
| 51 | const play = HTMLMediaElement.prototype.play; |
| 52 | HTMLMediaElement.prototype.play = function (...a) { c.play++; return play.apply(this, a); }; |
| 53 | try { |
| 54 | new PerformanceObserver(l => { for (const e of l.getEntries()) { c.lcp = e.startTime; const n = e.element; c.lcpEl = (n ? n.tagName.toLowerCase() + (n.id ? '#' + n.id : '') + (n.className && typeof n.className === 'string' ? '.' + n.className.trim().split(/\\s+/).join('.') : '') : '?') + ' ' + e.size + 'px ' + (e.url || ''); } }).observe({ type: 'largest-contentful-paint', buffered: true }); |
| 55 | new PerformanceObserver(l => { for (const e of l.getEntries()) if (!e.hadRecentInput) c.cls += e.value; }).observe({ type: 'layout-shift', buffered: true }); |
| 56 | } catch (_) {} |
| 57 | })();`; |
| 58 | |
| 59 | class Cdp { |
| 60 | constructor(url) { this.ws = new WebSocket(url); this.id = 0; this.pending = new Map(); this.handlers = new Map(); } |
| 61 | open() { return new Promise((res, rej) => { this.ws.onopen = res; this.ws.onerror = rej; this.ws.onmessage = e => this.recv(JSON.parse(e.data)); }); } |
| 62 | recv(m) { |
| 63 | if (m.id && this.pending.has(m.id)) { |
| 64 | const { res, rej } = this.pending.get(m.id); this.pending.delete(m.id); |
| 65 | m.error ? rej(new Error(`${m.error.message}`)) : res(m.result); |
| 66 | } else if (m.sessionId && this.handlers.has(m.sessionId)) this.handlers.get(m.sessionId)(m); |
| 67 | } |
| 68 | send(method, params = {}, sessionId) { |
| 69 | const id = ++this.id; |
| 70 | this.ws.send(JSON.stringify({ id, method, params, ...(sessionId ? { sessionId } : {}) })); |
| 71 | return new Promise((res, rej) => this.pending.set(id, { res, rej })); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | function launch() { |
| 76 | const dir = mkdtempSync(join(tmpdir(), 'site-browser-')); |
| 77 | const proc = spawn(CHROME, ['--headless=new', '--disable-gpu', '--disable-software-rasterizer', '--no-first-run', |
| 78 | '--no-default-browser-check', '--disable-extensions', '--disable-background-networking', '--disable-component-update', |
| 79 | '--disable-sync', '--metrics-recording-only', '--autoplay-policy=no-user-gesture-required', |
| 80 | `--user-data-dir=${dir}`, '--remote-debugging-port=0', 'about:blank'], { stdio: ['ignore', 'ignore', 'pipe'] }); |
| 81 | return new Promise((res, rej) => { |
| 82 | let err = ''; |
| 83 | proc.stderr.on('data', d => { err += d; const m = /DevTools listening on (ws:\S+)/.exec(err); if (m) res({ proc, dir, ws: m[1] }); }); |
| 84 | proc.on('exit', code => rej(new Error(`chrome exited ${code}: ${err.slice(-400)}`))); |
| 85 | }); |
| 86 | } |
| 87 | |
| 88 | async function page(cdp, ctx, { width = 1365, height = 900, throttle = null } = {}) { |
| 89 | const { targetId } = await cdp.send('Target.createTarget', { url: 'about:blank', browserContextId: ctx }); |
| 90 | const { sessionId } = await cdp.send('Target.attachToTarget', { targetId, flatten: true }); |
| 91 | const s = (m, p) => cdp.send(m, p, sessionId); |
| 92 | const st = { requests: [], offsite: [], errors: [], bad: [], bytes: 0, loaded: 0, loader: 0 }; |
| 93 | cdp.handlers.set(sessionId, async m => { |
| 94 | const p = m.params; |
| 95 | if (m.method === 'Fetch.requestPaused') { |
| 96 | // Same-origin requests go through; the X loader is answered with a stub |
| 97 | // that runs nothing; every other off-site request fails in the browser. |
| 98 | if (new URL(p.request.url).origin === BASE) await s('Fetch.continueRequest', { requestId: p.requestId }).catch(() => {}); |
| 99 | else if (p.request.url === LOADER) { |
| 100 | st.loader++; |
| 101 | await s('Fetch.fulfillRequest', { requestId: p.requestId, responseCode: 200, responseHeaders: [{ name: 'Content-Type', value: 'text/javascript' }], body: Buffer.from('/* intercepted by test-site-browser */').toString('base64') }).catch(() => {}); |
| 102 | } else await s('Fetch.failRequest', { requestId: p.requestId, errorReason: 'BlockedByClient' }).catch(() => {}); |
| 103 | } else if (m.method === 'Network.requestWillBeSent') { |
| 104 | const u = p.request.url; st.requests.push(u); |
| 105 | if (/^https?:/.test(u) && new URL(u).origin !== BASE) st.offsite.push(u); |
| 106 | } else if (m.method === 'Network.responseReceived') { |
| 107 | if (p.response.status >= 400 && new URL(p.response.url).origin === BASE && !liveOnly(p.response.url)) st.bad.push(`${p.response.status} ${p.response.url}`); |
| 108 | } else if (m.method === 'Network.loadingFinished') st.bytes += p.encodedDataLength; |
| 109 | else if (m.method === 'Network.loadingFailed') { |
| 110 | if (!p.canceled && p.blockedReason !== undefined) st.errors.push(`blocked ${p.blockedReason}`); |
| 111 | } else if (m.method === 'Runtime.exceptionThrown') st.errors.push(`exception ${p.exceptionDetails.exception?.description || p.exceptionDetails.text}`.slice(0, 300)); |
| 112 | else if (m.method === 'Runtime.consoleAPICalled' && p.type === 'error') st.errors.push(`console ${p.args.map(a => a.value ?? a.description).join(' ')}`.slice(0, 300)); |
| 113 | else if (m.method === 'Log.entryAdded' && p.entry.level === 'error' && !(p.entry.url && liveOnly(p.entry.url))) st.errors.push(`log ${p.entry.text} ${p.entry.url || ''}`.slice(0, 300)); |
| 114 | else if (m.method === 'Page.loadEventFired') st.loaded++; |
| 115 | }); |
| 116 | await s('Fetch.enable', { patterns: [{ urlPattern: 'http://*' }, { urlPattern: 'https://*' }] }); |
| 117 | await Promise.all([s('Page.enable'), s('Network.enable'), s('Runtime.enable'), s('Log.enable'), s('Accessibility.enable')]); |
| 118 | await s('Network.setCacheDisabled', { cacheDisabled: true }); |
| 119 | await s('Page.addScriptToEvaluateOnNewDocument', { source: INIT }); |
| 120 | await s('Emulation.setDeviceMetricsOverride', { width, height, deviceScaleFactor: 1, mobile: width < 500 }); |
| 121 | if (throttle) { |
| 122 | await s('Network.emulateNetworkConditions', { offline: false, latency: throttle.latency, downloadThroughput: throttle.down, uploadThroughput: throttle.up }); |
| 123 | await s('Emulation.setCPUThrottlingRate', { rate: throttle.cpu }); |
| 124 | } |
| 125 | const evaluate = async expr => { |
| 126 | const r = await s('Runtime.evaluate', { expression: expr, returnByValue: true, awaitPromise: true }); |
| 127 | if (r.exceptionDetails) throw new Error(`evaluate failed: ${r.exceptionDetails.exception?.description || r.exceptionDetails.text}`); |
| 128 | return r.result.value; |
| 129 | }; |
| 130 | const go = async (path, settle = 1500) => { |
| 131 | const before = st.loaded; |
| 132 | await s('Page.navigate', { url: BASE + path }); |
| 133 | for (let i = 0; i < 600 && st.loaded === before; i++) await pause(50); |
| 134 | if (st.loaded === before) throw new Error(`load timeout ${path}`); |
| 135 | await pause(settle); |
| 136 | }; |
| 137 | const reload = async (settle = 1500) => { |
| 138 | const before = st.loaded; |
| 139 | await s('Page.reload', { ignoreCache: true }); |
| 140 | for (let i = 0; i < 600 && st.loaded === before; i++) await pause(50); |
| 141 | await pause(settle); |
| 142 | }; |
| 143 | const key = async k => { |
| 144 | const code = k === 'Escape' ? 27 : 13; |
| 145 | await s('Input.dispatchKeyEvent', { type: 'rawKeyDown', key: k, code: k, windowsVirtualKeyCode: code }); |
| 146 | await s('Input.dispatchKeyEvent', { type: 'keyUp', key: k, code: k, windowsVirtualKeyCode: code }); |
| 147 | await pause(400); |
| 148 | }; |
| 149 | const click = async selector => { |
| 150 | const box = await evaluate(`(() => { const e = document.querySelector(${JSON.stringify(selector)}); if (!e) return null; e.scrollIntoView({block:'center',behavior:'instant'}); const r = e.getBoundingClientRect(); return [r.x + r.width / 2, r.y + r.height / 2]; })()`); |
| 151 | if (!box) throw new Error(`no element ${selector}`); |
| 152 | for (const type of ['mousePressed', 'mouseReleased']) await s('Input.dispatchMouseEvent', { type, x: box[0], y: box[1], button: 'left', clickCount: 1 }); |
| 153 | await pause(600); |
| 154 | }; |
| 155 | const axUnnamed = async () => { |
| 156 | const { nodes } = await s('Accessibility.getFullAXTree'); |
| 157 | return nodes.filter(n => !n.ignored && ['button', 'link', 'textbox', 'checkbox', 'combobox'].includes(n.role?.value) && !(n.name?.value || '').trim()) |
| 158 | .map(n => `${n.role.value}#${n.backendDOMNodeId}`); |
| 159 | }; |
| 160 | const close = () => cdp.send('Target.closeTarget', { targetId }); |
| 161 | return { s, st, evaluate, go, reload, key, click, axUnnamed, close }; |
| 162 | } |
| 163 | |
| 164 | const VISIBLE = `const shown = e => !!e && e.checkVisibility({ visibilityProperty: true }) && e.getBoundingClientRect().width > 0 && e.getBoundingClientRect().height > 0;`; |
| 165 | // The checks the 2026-10-22 /omega/ Lighthouse run failed (ledger L501), read from the rendered page. |
| 166 | // misnamed(): an aria-labelled link or button whose shown text, its shown text nodes joined with |
| 167 | // nothing between them as axe's label-content-name-mismatch reads it, is not inside its label. |
| 168 | // evidence(): every link in <main> is shown; a closed <details> only collapses it. Contrast stays |
| 169 | // with Lighthouse: scroll-reveal opacity and gradient backgrounds defeat a computed-style estimate. |
| 170 | const A11Y = ` |
| 171 | const squash = t => t.replace(/\\s+/g, ' ').trim().toLowerCase(); |
| 172 | const ownText = e => { let t = ''; const w = document.createTreeWalker(e, NodeFilter.SHOW_TEXT); |
| 173 | for (let n = w.nextNode(); n; n = w.nextNode()) { const p = n.parentElement; |
| 174 | if (p && shown(p) && !p.closest('[aria-hidden="true"]')) t += n.data; } |
| 175 | return squash(t); }; |
| 176 | const misnamed = () => [...document.querySelectorAll('a[aria-label], button[aria-label]')].filter(shown) |
| 177 | .filter(e => { const t = ownText(e); return t && !squash(e.getAttribute('aria-label')).includes(t); }) |
| 178 | .map(e => e.outerHTML.slice(0, 120)); |
| 179 | const evidence = () => { const links = [...document.querySelectorAll('main a[href]')]; |
| 180 | const out = { links: links.length, collapsed: 0, hidden: [] }; |
| 181 | for (const a of links) if (!shown(a)) { if (a.closest('details:not([open])')) out.collapsed++; else out.hidden.push(a.href); } |
| 182 | return out; };`; |
| 183 | |
| 184 | async function withContext(cdp, fn) { |
| 185 | const { browserContextId } = await cdp.send('Target.createBrowserContext', { disposeOnDetach: true }); |
| 186 | try { return await fn(browserContextId); } finally { await cdp.send('Target.disposeBrowserContext', { browserContextId }).catch(() => {}); } |
| 187 | } |
| 188 | |
| 189 | async function pagePass(cdp) { |
| 190 | for (const [width, height] of WIDTHS) for (const path of PAGES) await withContext(cdp, async ctx => { |
| 191 | const where = `${path} @${width}`; |
| 192 | const p = await page(cdp, ctx, { width, height }); |
| 193 | await p.go(path); |
| 194 | const dom = await p.evaluate(`(() => { ${VISIBLE} ${A11Y} |
| 195 | const nav = [...document.querySelectorAll(${JSON.stringify(TOPNAV)})].filter(shown).length; |
| 196 | return { lang: document.documentElement.lang, mains: document.querySelectorAll('main').length, |
| 197 | h1: [...document.querySelectorAll('h1')].length, overflow: document.documentElement.scrollWidth - innerWidth, |
| 198 | nav, index: !!document.querySelector('details.site-index'), |
| 199 | imgNoAlt: [...document.images].filter(i => !i.hasAttribute('alt')).map(i => i.src).slice(0, 5), |
| 200 | csp: window.__chk.csp, audio: window.__chk.audio, play: window.__chk.play, twq: typeof window.twq, |
| 201 | misnamed: misnamed(), evidence: ${JSON.stringify(path)} === '/omega/' ? evidence() : null }; |
| 202 | })()`); |
| 203 | const unnamed = await p.axUnnamed(); |
| 204 | const row = { path, width, ...dom, unnamed, offsite: p.st.offsite, bad: p.st.bad, errors: p.st.errors }; |
| 205 | report.pages.push(row); |
| 206 | if (!dom.lang) fail(where, 'html lang missing'); |
| 207 | if (dom.mains !== 1) fail(where, `${dom.mains} main elements`); |
| 208 | if (dom.h1 < 1) fail(where, 'no h1'); |
| 209 | if (dom.overflow > 1) fail(where, `horizontal overflow ${dom.overflow}px`); |
| 210 | if (dom.imgNoAlt.length) fail(where, `img without alt ${dom.imgNoAlt.join(' ')}`); |
| 211 | if (unnamed.length) fail(where, `unnamed controls ${unnamed.slice(0, 5).join(' ')}`); |
| 212 | if (dom.misnamed.length) fail(where, `aria-label without its visible text ${dom.misnamed.slice(0, 3).join(' ')}`); |
| 213 | if (dom.evidence) { |
| 214 | if (!dom.evidence.links) fail(where, 'no evidence links in main'); |
| 215 | if (dom.evidence.hidden.length) fail(where, `hidden evidence links ${dom.evidence.hidden.slice(0, 3).join(' ')}`); |
| 216 | } |
| 217 | if (dom.csp.length) fail(where, `CSP violations ${dom.csp.join('; ')}`); |
| 218 | if (dom.audio || dom.play) fail(where, `sound started on load (AudioContext ${dom.audio}, play ${dom.play})`); |
| 219 | if (dom.twq !== 'undefined') fail(where, 'window.twq defined before consent'); |
| 220 | if (p.st.offsite.length) fail(where, `off-site requests before consent ${p.st.offsite.slice(0, 3).join(' ')}`); |
| 221 | if (p.st.bad.length) fail(where, `HTTP errors ${p.st.bad.slice(0, 3).join(' ')}`); |
| 222 | if (p.st.errors.length) fail(where, `errors ${p.st.errors.slice(0, 3).join(' | ')}`); |
| 223 | if (path === '/' && !dom.nav) fail(where, 'readable homepage navigation is missing'); |
| 224 | if (DESTINATIONS.includes(path)) { |
| 225 | if (!dom.nav) fail(where, 'restored Turing navigation is missing'); |
| 226 | if (!dom.index) fail(where, 'quiet site index missing'); |
| 227 | } |
| 228 | await p.close(); |
| 229 | }); |
| 230 | } |
| 231 | |
| 232 | async function doorPass(cdp) { |
| 233 | const door = report.door; |
| 234 | const state = p => p.evaluate(`(() => { ${VISIBLE} return { door: shown(document.getElementById('site-door')), |
| 235 | seen: localStorage.getItem('aienos-intro-seen'), welcome: document.getElementById('site-welcome-status')?.textContent || '', |
| 236 | enter: !document.getElementById('site-door-enter')?.disabled, audio: window.__chk.audio, play: window.__chk.play }; })()`); |
| 237 | await withContext(cdp, async ctx => { |
| 238 | const p = await page(cdp, ctx); |
| 239 | await p.go('/aien/', 2500); |
| 240 | door.first = await state(p); |
| 241 | if (!door.first.door) fail('door', 'first visit does not show the door'); |
| 242 | if (door.first.audio || door.first.play) fail('door', 'sound before any gesture'); |
| 243 | if (door.first.seen) fail('door', 'intro marked seen before it was answered'); |
| 244 | await p.key('Escape'); |
| 245 | door.escape = await state(p); |
| 246 | if (door.escape.door || door.escape.seen !== '1' || door.escape.audio) fail('door', `Escape did not dismiss silently and remember (${JSON.stringify(door.escape)})`); |
| 247 | await p.reload(2000); |
| 248 | door.returning = await state(p); |
| 249 | if (door.returning.door) fail('door', 'returning visitor sees the door again'); |
| 250 | if (!/Welcome back/.test(door.returning.welcome)) fail('door', `returning welcome missing (${door.returning.welcome})`); |
| 251 | await p.evaluate(`document.querySelector('[data-site-replay]').click()`); |
| 252 | await pause(500); |
| 253 | door.replayClick = await state(p); |
| 254 | if (!door.replayClick.door) fail('door', 'quiet replay control does not reopen the door'); |
| 255 | await p.go('/classic/'); |
| 256 | await p.go('/aien/#site-door', 2000); |
| 257 | door.replayLink = await state(p); |
| 258 | if (!door.replayLink.door) fail('door', 'replay link from another page does not reopen the door'); |
| 259 | door.errors = p.st.errors; door.offsite = p.st.offsite; |
| 260 | if (p.st.errors.length) fail('door', `errors ${p.st.errors.slice(0, 3).join(' | ')}`); |
| 261 | await p.close(); |
| 262 | }); |
| 263 | await withContext(cdp, async ctx => { |
| 264 | const p = await page(cdp, ctx); |
| 265 | await p.go('/aien/', 2500); |
| 266 | await p.click('#site-door-skip'); |
| 267 | door.skip = await state(p); |
| 268 | if (door.skip.door || door.skip.audio) fail('door', `Skip did not dismiss silently (${JSON.stringify(door.skip)})`); |
| 269 | await p.close(); |
| 270 | }); |
| 271 | await withContext(cdp, async ctx => { |
| 272 | const p = await page(cdp, ctx); |
| 273 | await p.go('/aien/', 3000); |
| 274 | door.beforeEnter = await state(p); |
| 275 | if (!door.beforeEnter.enter) fail('door', 'Enter never became available (scene not ready)'); |
| 276 | else { |
| 277 | await p.click('#site-door-enter'); |
| 278 | door.afterEnter = await state(p); |
| 279 | if (!door.afterEnter.audio) fail('door', 'Enter with sound created no audio context'); |
| 280 | await p.key('Escape'); |
| 281 | door.afterEnterEscape = await state(p); |
| 282 | if (door.afterEnterEscape.door) fail('door', 'Escape during the intro did not end it'); |
| 283 | } |
| 284 | if (p.st.errors.length) fail('door', `errors ${p.st.errors.slice(0, 3).join(' | ')}`); |
| 285 | await p.close(); |
| 286 | }); |
| 287 | } |
| 288 | |
| 289 | async function consentPass(cdp) { |
| 290 | for (const saved of ['yes', 'no']) await withContext(cdp, async ctx => { |
| 291 | const p = await page(cdp, ctx); |
| 292 | await p.s('Page.addScriptToEvaluateOnNewDocument', {source:`localStorage.setItem('aien-allen-intro-consent',${JSON.stringify(saved)});`}); |
| 293 | for (const path of ['/','/contact/','/privacy/','/aien/']) { |
| 294 | await p.go(path); |
| 295 | const state = await p.evaluate(`({dialog:!!document.getElementById('aien-allen-intro'), loader:[...document.scripts].some(s=>s.src.endsWith('/js/allen-intro.js')), pixel:typeof window.twq})`); |
| 296 | if (state.dialog || state.loader || state.pixel !== 'undefined' || p.st.loader || p.st.offsite.length) |
| 297 | fail('removed popup '+path, JSON.stringify(state)); |
| 298 | } |
| 299 | await p.close(); |
| 300 | }); |
| 301 | } |
| 302 | |
| 303 | async function restoredHomePass(cdp) { |
| 304 | for (const scripts of [true, false]) await withContext(cdp, async ctx => { |
| 305 | const p = await page(cdp, ctx, {width:390,height:844}); |
| 306 | if (!scripts) await p.s('Emulation.setScriptExecutionDisabled', {value:true}); |
| 307 | else await p.s('Page.addScriptToEvaluateOnNewDocument', {source:`localStorage.setItem('aienos-site-mode','allen');localStorage.setItem('aienos-intro-seen','1');`}); |
| 308 | await p.go('/'); |
| 309 | if (scripts) await p.key('Escape'); |
| 310 | const state = await p.evaluate(`(() => { ${VISIBLE} |
| 311 | return {path:location.pathname, door:!!document.getElementById('site-door'), |
| 312 | main:shown(document.querySelector('main')), heading:shown(document.querySelector('main h1')), |
| 313 | menu:shown(document.querySelector('.aien-nav-more-button')), |
| 314 | engineer:!!document.querySelector('a[href="/engineer/"]')}; })()`); |
| 315 | if (state.path !== '/' || state.door || !state.main || !state.heading || !state.menu || !state.engineer) |
| 316 | fail('restored homepage scripts='+scripts, JSON.stringify(state)); |
| 317 | await p.click('.aien-nav-more-button'); |
| 318 | const menu = await p.evaluate(`(() => { const a=document.querySelector('.aien-nav-panel a[href="/engineer/"]'); const r=a.getBoundingClientRect(); return a.checkVisibility() && r.left>=0 && r.right<=innerWidth; })()`); |
| 319 | if (!menu) fail('restored homepage', 'mobile menu does not expose Meet the Engineer within the viewport'); |
| 320 | await p.close(); |
| 321 | }); |
| 322 | } |
| 323 | |
| 324 | async function engineerPass(cdp) { |
| 325 | report.engineer = []; |
| 326 | for (const width of [320,390,768]) await withContext(cdp, async ctx => { |
| 327 | const p = await page(cdp, ctx, {width,height:844}); |
| 328 | await p.go('/engineer/'); await p.key('Escape'); |
| 329 | const state = await p.evaluate(`(() => { |
| 330 | const sc=document.querySelector('.uni-scroll'); |
| 331 | const links=[...document.querySelectorAll('.planet')]; |
| 332 | return {overflow:sc.scrollWidth>sc.clientWidth+1, |
| 333 | outside:links.filter(e=>{const r=e.getBoundingClientRect();return r.left<0 || r.right>innerWidth;}).map(e=>e.textContent.trim()), |
| 334 | small:links.filter(e=>e.getBoundingClientRect().height<44).map(e=>e.textContent.trim()), |
| 335 | topics:links.map(e=>e.getAttribute('href'))}; })()`); |
| 336 | report.engineer.push({width,...state}); |
| 337 | if (state.overflow || state.outside.length || state.small.length) fail('engineer '+width, JSON.stringify(state)); |
| 338 | for (const href of state.topics) { |
| 339 | await p.click('.planet[href="'+href+'"]'); |
| 340 | const shown = await p.evaluate(`(() => {const e=document.querySelector(${JSON.stringify(href)}); const r=e.getBoundingClientRect();return e.checkVisibility() && r.left>=0 && r.right<=innerWidth;})()`); |
| 341 | if (!shown) fail('engineer '+width, href+' panel is not readable within the screen'); |
| 342 | await p.click(href+' .world-close'); |
| 343 | } |
| 344 | await p.close(); |
| 345 | }); |
| 346 | // The life map is a full-bleed galaxy on the near-black Turing ground |
| 347 | // (Drake, 2026-11-06); a boxed main or the navy palette is a regression. |
| 348 | for (const width of [1365,390]) await withContext(cdp, async ctx => { |
| 349 | const p = await page(cdp, ctx, {width,height:900}); |
| 350 | await p.go('/engineer/'); await p.key('Escape'); |
| 351 | const look = await p.evaluate(`(() => { const m=document.querySelector('main').getBoundingClientRect(); |
| 352 | return {main:Math.round(m.width), page:document.documentElement.clientWidth, ground:getComputedStyle(document.body).backgroundColor}; })()`); |
| 353 | report.engineer.push({width,...look}); |
| 354 | if (look.main !== look.page || look.ground !== 'rgb(8, 9, 12)') fail('engineer galaxy '+width, JSON.stringify(look)); |
| 355 | await p.close(); |
| 356 | }); |
| 357 | } |
| 358 | |
| 359 | async function restoredInteractions(cdp) { |
| 360 | await withContext(cdp, async ctx => { |
| 361 | const p = await page(cdp, ctx, {width:1365,height:1000}); |
| 362 | await p.s('Page.addScriptToEvaluateOnNewDocument', {source:"localStorage.setItem('aien-allen-intro-seen','1')"}); |
| 363 | // The Turing game and terminal moved, unchanged, from / to /record/ (Drake, 2026-11-09); |
| 364 | // the homepage is the live factory floor. |
| 365 | await p.go('/record/'); |
| 366 | const state = await p.evaluate("({round:document.getElementById('tg-round').textContent,closed:!!document.getElementById('tg-zero').closest('details:not([open])')})"); |
| 367 | if (state.closed) throw new Error('The restored Turing game is hidden inside a closed panel'); |
| 368 | await p.click('#tg-zero'); |
| 369 | const round = await p.evaluate("document.getElementById('tg-round').textContent"); |
| 370 | if (round === state.round) throw new Error('Turing game did not advance after a click'); |
| 371 | await p.click('[data-cmd="sys_telemetry"]'); |
| 372 | const output = await p.evaluate("document.getElementById('terminal-output').textContent"); |
| 373 | if (!output.includes('sys_telemetry')) throw new Error('Terminal did not answer its telemetry button'); |
| 374 | await p.close(); |
| 375 | }); |
| 376 | } |
| 377 | |
| 378 | async function perfPass(cdp) { |
| 379 | for (const path of PERF_PAGES) await withContext(cdp, async ctx => { |
| 380 | const p = await page(cdp, ctx, { width: 390, height: 844, throttle: PERF }); |
| 381 | await p.go(path, 4000); |
| 382 | const m = await p.evaluate(`({ lcp: window.__chk.lcp, lcpEl: window.__chk.lcpEl, cls: window.__chk.cls })`); |
| 383 | const row = { path, lcp_ms: Math.round(m.lcp), lcp_element: m.lcpEl, cls: Number(m.cls.toFixed(4)), bytes: p.st.bytes }; |
| 384 | report.perf.push(row); |
| 385 | if (!(m.lcp > 0)) fail(`perf ${path}`, 'no LCP entry'); |
| 386 | if (m.lcp > PERF.lcp) fail(`perf ${path}`, `LCP ${row.lcp_ms} ms > ${PERF.lcp} ms (${m.lcpEl})`); |
| 387 | if (m.cls > PERF.cls) fail(`perf ${path}`, `CLS ${row.cls} > ${PERF.cls}`); |
| 388 | await p.close(); |
| 389 | }); |
| 390 | } |
| 391 | |
| 392 | const chrome = await launch(); |
| 393 | let cdp; |
| 394 | try { |
| 395 | cdp = new Cdp(chrome.ws); await cdp.open(); |
| 396 | report.browser = (await cdp.send('Browser.getVersion')).product; |
| 397 | await pagePass(cdp); |
| 398 | await restoredHomePass(cdp); |
| 399 | await engineerPass(cdp); |
| 400 | await doorPass(cdp); |
| 401 | await consentPass(cdp); |
| 402 | await restoredInteractions(cdp); |
| 403 | await perfPass(cdp); |
| 404 | } catch (e) { |
| 405 | fail('harness', e.stack || String(e)); |
| 406 | } finally { |
| 407 | try { cdp?.ws.close(); } catch (_) {} |
| 408 | chrome.proc.kill('SIGTERM'); |
| 409 | await pause(500); |
| 410 | rmSync(chrome.dir, { recursive: true, force: true }); |
| 411 | } |
| 412 | report.failures = failures; |
| 413 | if (args.report) writeFileSync(args.report, JSON.stringify(report, null, 1) + '\n'); |
| 414 | for (const r of report.perf) console.log(`perf ${r.path} lcp=${r.lcp_ms}ms cls=${r.cls} bytes=${r.bytes}`); |
| 415 | for (const f of failures) console.log(`FAIL ${f}`); |
| 416 | console.log(`SITE-BROWSER ${failures.length ? 'FAIL' : 'PASS'} ${report.browser} pages=${report.pages.length} perf=${report.perf.length} failures=${failures.length}`); |
| 417 | process.exit(failures.length ? 1 : 0); |