gitoria

layouts

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitb59e2ee9b59e2ee9docs/usage.md + tools/usage.sh: which app carries which component/theme/tokens copy, and whether it matches the sourcemreb59e2ee9/tests/same-output.mjs

6.5 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 = 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 > 120) 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: [8751, 8759] });
  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

  • b59e2ee9docs/usage.md + tools/usage.sh: which app carries which component/theme/tokens copy, and whether it matches the sourcemre
  • 0222f67ctheme: two corner radii only (radiusSmall 5px, radiusLarge 10px); check-theme flags any other radius; gate 76/0mre
  • 877b63acdesign rules: two radii only (5px small, 10px large)mre
  • 635234dfcomponents re-synced to components.hybriel 5a98d77 (#15 black/white base look); gate 73/0, check-theme 0, screenshots unchangedmre
  • 876b2064docs: workaround note for hybriel#130 (slot marker mid-line)mre
  • 85b56541layouts mission 002 3/3: same-output tests, letcount, shots ports, docs, reportmre
  • 0f325d3blayouts mission 002 2/3: code rules — styles.hl -> components/styles.hl, the one never-reassigned let dropped; gate 73/0, same outputmre
  • a3e74c8alayouts mission 002 1/3: components re-copied byte-verbatim from components.hybriel 3f93d71 by tools/sync-components.sh (+ --check, components/SOURCE); gate 73/0, check-theme 0mre
  • 80ce6ba9report 001 (mission 075)mre
  • 5c6e338flayouts.worldapi.org in Hybriel: WorldAPI theme (tokens, borderless elements, themed components.hybriel components), shells (header, main/user menu, sidebar overlay, content-first, list-first, three-pane), showcase, check-theme helper; gate 73/0 (mission 075)mre