gitoria

layouts

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmain4099e64aMerge branch 'font-segoe-ui' into mainAtlasmain/tests/same-output.mjs

6.6 KB

  1. // tests/same-output.mjs (layouts mission 002, from components.hybriel's): same-output baseline of a CODE-ONLY COPY of this tree.
  2. // node tests/same-output.mjs <tree copy> <outdir> (README "Run, test, deploy" → "Same output"; refuses a tree with .git)
  3. // Server on 8750 (cwd = tree), Chrome 8751-8759. Saves every HTTP answer of the site (crawled from / and the seeds below
  4. // over every same-origin link: pages, READMEs, docs, icons, css, manifest, worker, every browser module a page loads,
  5. // a 404, the search redirect), the hydrated DOM of every page at 1280 and 390, a file-upload drop on
  6. // /components/file-upload and a md-editor drop on /components/md-editor (the component's DOM afterwards), and the console
  7. // problems. Compare two runs with tests/same-output-compare.py (+ same-output-modules.py). Stops all by PID.
  8. import { spawn } from 'node:child_process';
  9. import { writeFileSync, mkdirSync, rmSync, existsSync } from 'node:fs';
  10. import { join, resolve } from 'node:path';
  11. import { createHash } from 'node:crypto';
  12. import { launchBrowser } from './cdp.mjs';
  13. if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';
  14. const TREE = resolve(process.argv[2]), OUT = resolve(process.argv[3]);
  15. if (existsSync(join(TREE, '.git'))) { console.log('refused: ' + TREE + ' has .git — run it on a code-only copy'); process.exit(2); }
  16. const PORT = Number(process.env.SAME_OUTPUT_PORT || 8750), BASE = `http://127.0.0.1:${PORT}`;
  17. rmSync(OUT, { recursive: true, force: true }); mkdirSync(OUT, { recursive: true });
  18. const sleep = (ms) => new Promise(r => setTimeout(r, ms));
  19. let log = '';
  20. 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'] });
  21. server.stdout.on('data', d => log += d); server.stderr.on('data', d => log += d);
  22. let browser = null;
  23. const n = { http: 0, dom: 0 };
  24. const save = (kind, key, text) => { writeFileSync(join(OUT, kind + '__' + key.replace(/\?v=\w+/, '').replace(/[^\w.-]+/g, '_')), text); n[kind === 'http' ? 'http' : 'dom']++; };
  25. try {
  26. 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); }
  27. const seeds = ['/', '/search/modal', '/search?q=date+picker', '/favicon.ico', '/__hl/manifest.webmanifest', '/__hl/sw.js', '/theme/check-theme.mjs', '/nope', '/docs/nope.md'];
  28. const seen = new Set(), pages = [];
  29. const get = async (u) => {
  30. if (seen.has(u)) return; seen.add(u);
  31. const r = await fetch(BASE + u, { redirect: 'manual' }); const b = Buffer.from(await r.arrayBuffer());
  32. const ct = r.headers.get('content-type') || '';
  33. const body = /text|json|javascript|svg|markdown|css|manifest/.test(ct) ? b.toString('utf8') : 'sha256 ' + createHash('sha256').update(b).digest('hex');
  34. save('http', u, `${r.status} ${ct} ${r.headers.get('cache-control') || ''} ${r.headers.get('location') || ''}\n${body}`);
  35. if (r.status === 200 && /text\/html/.test(ct)) pages.push(u);
  36. 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]);
  37. if (/text\/html/.test(ct)) for (const m of body.matchAll(/href="(\/[^"#?]*)"/g)) await get(m[1]);
  38. };
  39. for (const u of seeds) await get(u);
  40. browser = await launchBrowser({ debugPortRange: (process.env.SAME_OUTPUT_CHROME || "8751-8759").split("-").map(Number) });
  41. const page = await browser.newPage();
  42. const ev = (e) => page.evaluate(e);
  43. const hydrated = () => page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { timeout: 30000, label: 'hydrated' });
  44. const dom = `(() => { const c = document.body.cloneNode(true); c.querySelectorAll('script').forEach(s => s.remove()); return c.outerHTML; })()`;
  45. for (const w of [1280, 390]) {
  46. await page.send('Emulation.setDeviceMetricsOverride', { width: w, height: w < 600 ? 844 : 900, deviceScaleFactor: 1, mobile: w < 600 });
  47. for (const p of pages) { await page.goto(BASE + p, { timeout: 45000 }); await hydrated(); await sleep(500); save('dom', w + p, await ev(dom)); }
  48. }
  49. await page.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 900, deviceScaleFactor: 1, mobile: false });
  50. // file upload: drop a 300 KB file (the showcase answers done, keeps nothing)
  51. await page.goto(BASE + '/components/file-upload', { timeout: 45000 }); await hydrated(); await sleep(600);
  52. 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 })); })()`);
  53. await page.waitFor(`document.querySelector('file-upload .state').textContent === 'Uploaded'`, { timeout: 30000, label: 'uploaded' });
  54. await sleep(300); save('dom', 'upload-drop', await ev(`document.querySelector('file-upload').outerHTML`));
  55. // md-editor: drop a png and a .exe-named file into the second editor (the showcase answers /not-kept/<size>)
  56. await page.goto(BASE + '/components/md-editor', { timeout: 45000 }); await hydrated(); await sleep(600);
  57. const PNG = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==';
  58. 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 })); })()`);
  59. await page.waitFor(`document.querySelectorAll('md-editor')[1].querySelector('input.value').value.includes('run.exe')`, { timeout: 30000, label: 'md uploaded' });
  60. await sleep(500); save('dom', 'md-upload', await ev(`document.querySelector('show-md-editor').outerHTML`));
  61. const probs = page.problems().filter(m => !/favicon|Failed to load resource/.test(m.text));
  62. save('dom', 'console-problems', probs.map(m => m.text).join('\n'));
  63. console.log(`saved http ${n.http}, dom ${n.dom} (${pages.length} pages) -> ${OUT}`);
  64. } catch (e) { console.log('BASELINE FAILED', e.stack || e, '\n', log.slice(-2000)); process.exitCode = 1; }
  65. finally {
  66. if (browser) { try { await browser.close(); } catch {} }
  67. server.kill('SIGTERM'); await new Promise(r => { if (server.exitCode !== null) return r(); server.once('exit', r); setTimeout(r, 3000); });
  68. }

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