layouts
All repositories: gitoria
6.6 KB
// tests/same-output.mjs (layouts mission 002, from components.hybriel's): same-output baseline of a CODE-ONLY COPY of this tree.// node tests/same-output.mjs <tree copy> <outdir> (README "Run, test, deploy" → "Same output"; refuses a tree with .git)// Server on 8750 (cwd = tree), Chrome 8751-8759. Saves every HTTP answer of the site (crawled from / and the seeds below// over every same-origin link: pages, READMEs, docs, icons, css, manifest, worker, every browser module a page loads,// a 404, the search redirect), the hydrated DOM of every page at 1280 and 390, a file-upload drop on// /components/file-upload and a md-editor drop on /components/md-editor (the component's DOM afterwards), and the console// problems. Compare two runs with tests/same-output-compare.py (+ same-output-modules.py). Stops all by PID.import { spawn } from 'node:child_process';import { writeFileSync, mkdirSync, rmSync, existsSync } from 'node:fs';import { join, resolve } from 'node:path';import { createHash } from 'node:crypto';import { launchBrowser } from './cdp.mjs';if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';const TREE = resolve(process.argv[2]), OUT = resolve(process.argv[3]);if (existsSync(join(TREE, '.git'))) { console.log('refused: ' + TREE + ' has .git — run it on a code-only copy'); process.exit(2); }const PORT = Number(process.env.SAME_OUTPUT_PORT || 8750), BASE = `http://127.0.0.1:${PORT}`;rmSync(OUT, { recursive: true, force: true }); mkdirSync(OUT, { recursive: true });const sleep = (ms) => new Promise(r => setTimeout(r, ms));let log = '';const server = spawn(join(TREE, 'bin/hybriel'), ['project.hl'], { cwd: TREE, env: { ...process.env, LAYOUTS_PORT: String(PORT), LAYOUTS_WATCH: '0' }, stdio: ['ignore', 'pipe', 'pipe'] });server.stdout.on('data', d => log += d); server.stderr.on('data', d => log += d);let browser = null;const n = { http: 0, dom: 0 };const save = (kind, key, text) => { writeFileSync(join(OUT, kind + '__' + key.replace(/\?v=\w+/, '').replace(/[^\w.-]+/g, '_')), text); n[kind === 'http' ? 'http' : 'dom']++; };try {for (let i = 0; ; i++) { try { if ((await fetch(BASE + '/')).ok) break; } catch {} if (i > 480) throw new Error('no server\n' + log); await sleep(250); }const seeds = ['/', '/search/modal', '/search?q=date+picker', '/favicon.ico', '/__hl/manifest.webmanifest', '/__hl/sw.js', '/theme/check-theme.mjs', '/nope', '/docs/nope.md'];const seen = new Set(), pages = [];const get = async (u) => {if (seen.has(u)) return; seen.add(u);const r = await fetch(BASE + u, { redirect: 'manual' }); const b = Buffer.from(await r.arrayBuffer());const ct = r.headers.get('content-type') || '';const body = /text|json|javascript|svg|markdown|css|manifest/.test(ct) ? b.toString('utf8') : 'sha256 ' + createHash('sha256').update(b).digest('hex');save('http', u, `${r.status} ${ct} ${r.headers.get('cache-control') || ''} ${r.headers.get('location') || ''}\n${body}`);if (r.status === 200 && /text\/html/.test(ct)) pages.push(u);if (/text\/html|javascript/.test(ct)) for (const m of body.matchAll(/["'(](\/(?:__hl\/[\w./-]+|[\w./-]+\.hl|icons\/[\w./-]+)(?:\?v=\w+)?)/g)) await get(m[1]);if (/text\/html/.test(ct)) for (const m of body.matchAll(/href="(\/[^"#?]*)"/g)) await get(m[1]);};for (const u of seeds) await get(u);browser = await launchBrowser({ debugPortRange: (process.env.SAME_OUTPUT_CHROME || "8751-8759").split("-").map(Number) });const page = await browser.newPage();const ev = (e) => page.evaluate(e);const hydrated = () => page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { timeout: 30000, label: 'hydrated' });const dom = `(() => { const c = document.body.cloneNode(true); c.querySelectorAll('script').forEach(s => s.remove()); return c.outerHTML; })()`;for (const w of [1280, 390]) {await page.send('Emulation.setDeviceMetricsOverride', { width: w, height: w < 600 ? 844 : 900, deviceScaleFactor: 1, mobile: w < 600 });for (const p of pages) { await page.goto(BASE + p, { timeout: 45000 }); await hydrated(); await sleep(500); save('dom', w + p, await ev(dom)); }}await page.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 900, deviceScaleFactor: 1, mobile: false });// file upload: drop a 300 KB file (the showcase answers done, keeps nothing)await page.goto(BASE + '/components/file-upload', { timeout: 45000 }); await hydrated(); await sleep(600);await ev(`(() => { const dt = new DataTransfer(); dt.items.add(new File([new Uint8Array(307200).map((_, i) => i % 251)], 'data.bin', { type: 'application/octet-stream' })); document.querySelector('file-upload drop-zone').dispatchEvent(new DragEvent('drop', { dataTransfer: dt, bubbles: true, cancelable: true })); })()`);await page.waitFor(`document.querySelector('file-upload .state').textContent === 'Uploaded'`, { timeout: 30000, label: 'uploaded' });await sleep(300); save('dom', 'upload-drop', await ev(`document.querySelector('file-upload').outerHTML`));// md-editor: drop a png and a .exe-named file into the second editor (the showcase answers /not-kept/<size>)await page.goto(BASE + '/components/md-editor', { timeout: 45000 }); await hydrated(); await sleep(600);const PNG = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==';await ev(`(() => { const ed = document.querySelectorAll('md-editor')[1]; const a = ed.querySelector('article'); a.focus(); const png = Uint8Array.from(atob('${PNG}'), c => c.charCodeAt(0)); const dt = new DataTransfer(); dt.items.add(new File([png], 'one.png', { type: 'image/png' })); dt.items.add(new File(['MZ'], 'run.exe', { type: 'application/octet-stream' })); a.dispatchEvent(new DragEvent('drop', { dataTransfer: dt, bubbles: true, cancelable: true, clientX: 50, clientY: 50 })); })()`);await page.waitFor(`document.querySelectorAll('md-editor')[1].querySelector('input.value').value.includes('run.exe')`, { timeout: 30000, label: 'md uploaded' });await sleep(500); save('dom', 'md-upload', await ev(`document.querySelector('show-md-editor').outerHTML`));const probs = page.problems().filter(m => !/favicon|Failed to load resource/.test(m.text));save('dom', 'console-problems', probs.map(m => m.text).join('\n'));console.log(`saved http ${n.http}, dom ${n.dom} (${pages.length} pages) -> ${OUT}`);} catch (e) { console.log('BASELINE FAILED', e.stack || e, '\n', log.slice(-2000)); process.exitCode = 1; }finally {if (browser) { try { await browser.close(); } catch {} }server.kill('SIGTERM'); await new Promise(r => { if (server.exitCode !== null) return r(); server.once('exit', r); setTimeout(r, 3000); });}
Branches
Latest commits
- 4099e64aMerge branch 'font-segoe-ui' into mainAtlas
- e14fb795|||PR Theme font: Segoe UI first (his choice 2026-11-19)Atlas
- 44071d2cMerge branch 'hl-standard-5' into mainAtlas
- 5ea64202|||PR Gate: count the new-tab check's console errors tooAtlas
- 2752ceddMerge branch 'hl-standard-4' into mainAtlas
- ac552b81|||PR Gate: keyboard (Tab/Enter/Space) and Back/Forward/reload/new-tab checks (HL-STANDARD F5, F21)Atlas
- 8cddcaa9Merge branch 'hl-standard-2' into mainAtlas
- 2b480a64|||PR Type the route parameter of main-menu build (HL-STANDARD L10)Atlas
- ab54a39dMerge branch 'hl-standard' into mainAtlas
- 04d36fcf|||PR Type function parameters and drop unneeded let (HL-STANDARD L2, L10)Atlas
- 220c8fa4Merge branch 'readme-audit' into mainAtlas
- b78fb85a|||PR README matches the codemre
- 9f351699Preserve comments and nest supported selectors without changing rendered outputmre
- 97110ad9WIP: nest accepted layout selectors; stopped at startup parse failuremre
- ce4a0baeKeep caller slot styles whole so minimal shell apps startmre
- 12cd3992Re-vendor complete Hybriel plugins and runtime to day44mre
- b05c20feBackup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
- 8d9ed0b8Re-vendor complete Hybriel plugins and runtime to day39mre
- ebd00b6cNest caller slot styles in three-panemre
- 009991efNest caller slot styles in list-firstmre