gitoria

components

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit9db927df9db927dfpaths: projects moved into /media/STORAGE/projects/WorldAPI/mre9db927df/tests/same-output.mjs

8.0 KB

  1. // tests/same-output.mjs (components mission 002): same-output baseline of a CODE-ONLY COPY of a components tree.
  2. // node tests/same-output.mjs <tree copy> <outdir> (README "Test" → "Same output"; refuses a tree with .git: it wipes <tree>/storage)
  3. // Server on 8750 (cwd = tree, its own storage/), Chrome 8751-8759. Saves every HTTP answer (pages, READMEs, icons, css,
  4. // manifest, worker, every browser module a page loads), the hydrated DOM of every page, and a file upload (drop) on
  5. // /file-upload + a md-editor drop: the component's DOM afterwards and the sha256 of every stored file. Stops all by PID.
  6. import { spawn } from 'node:child_process';
  7. import { writeFileSync, mkdirSync, rmSync, readdirSync, readFileSync, existsSync } from 'node:fs';
  8. import { join, resolve } from 'node:path';
  9. import { createHash } from 'node:crypto';
  10. import { launchBrowser } from './cdp.mjs';
  11. if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';
  12. const TREE = resolve(process.argv[2]), OUT = resolve(process.argv[3]);
  13. if (existsSync(join(TREE, '.git'))) { console.log('refused: ' + TREE + ' has .git — run it on a code-only copy (its storage/ is wiped)'); process.exit(2); }
  14. const PORT = Number(process.env.SO_PORT || 8750), BASE = `http://127.0.0.1:${PORT}`;
  15. rmSync(OUT, { recursive: true, force: true }); mkdirSync(OUT, { recursive: true });
  16. rmSync(join(TREE, 'storage'), { recursive: true, force: true });
  17. const SES = join(OUT, '..', 'sessions-' + process.pid); rmSync(SES, { recursive: true, force: true }); mkdirSync(SES, { 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, COMPONENTS_PORT: String(PORT), COMPONENTS_SESSIONS: SES + '/', COMPONENTS_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. // a new Hybriel compiles the app at its first start (cold 18–41 s, hybriel#148): up to COMPONENTS_COLD_MS (default 120 s)
  27. for (const t0 = Date.now(); ; ) { try { if ((await fetch(BASE + '/')).ok) break; } catch {} if (Date.now() - t0 > Number(process.env.COMPONENTS_COLD_MS || 120000)) throw new Error('no server\n' + log); await sleep(250); }
  28. const names = ['month-view', 'date-picker', 'range-picker', 'pagination', 'md-editor', 'code-editor', 'file-upload', 'modal'];
  29. const pages = ['/', ...names.map(c => '/' + c)];
  30. const urls = [...pages, ...names.map(c => `/${c}/README.md`), '/favicon.ico', '/icons/icon-192.png', '/icons/icon-512.png', '/icons/apple-touch-icon.png', '/icons/favicon.svg', '/__hl/manifest.webmanifest', '/__hl/sw.js', '/nope', '/md-editor/files/nope.png'];
  31. const seen = new Set();
  32. const get = async (u) => {
  33. if (seen.has(u)) return; seen.add(u);
  34. const r = await fetch(BASE + u); const b = Buffer.from(await r.arrayBuffer());
  35. const ct = r.headers.get('content-type') || '';
  36. const body = /text|json|javascript|svg|markdown|css|manifest/.test(ct) ? b.toString('utf8') : 'sha256 ' + createHash('sha256').update(b).digest('hex');
  37. save('http', u, `${r.status} ${ct} ${r.headers.get('cache-control') || ''}\n${body}`);
  38. if (/text\/html|javascript/.test(ct)) for (const m of body.matchAll(/["'(](\/(?:__hl\/[\w./-]+|components\/[\w./-]+\.hl)(?:\?v=\w+)?)/g)) await get(m[1]);
  39. };
  40. for (const u of urls) await get(u);
  41. browser = await launchBrowser({ debugPortRange: (process.env.SO_CHROME || "8751-8759").split("-").map(Number) });
  42. const page = await browser.newPage();
  43. await page.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 900, deviceScaleFactor: 1, mobile: false });
  44. const ev = (e) => page.evaluate(e);
  45. const hydrated = () => page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { timeout: 30000, label: 'hydrated' });
  46. const dom = `(() => { const c = document.body.cloneNode(true); c.querySelectorAll('script').forEach(s => s.remove()); return c.outerHTML; })()`;
  47. for (const p of pages) { await page.goto(BASE + p, { timeout: 45000 }); await hydrated(); await sleep(700); save('dom', p, await ev(dom)); }
  48. // file upload: drop a 300 KB file, then choose one through the input
  49. await page.goto(BASE + '/file-upload', { timeout: 45000 }); await hydrated(); await sleep(600);
  50. 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 })); })()`);
  51. await page.waitFor(`document.querySelector('file-upload .state').textContent === 'Uploaded'`, { timeout: 30000, label: 'uploaded' });
  52. await sleep(300); save('dom', 'upload-drop', await ev(`document.querySelector('file-upload').outerHTML`));
  53. writeFileSync(join(OUT, '..', 'pick.txt'), 'hello m002');
  54. const { root } = await page.send('DOM.getDocument');
  55. const { nodeId } = await page.send('DOM.querySelector', { nodeId: root.nodeId, selector: 'file-upload input[type=file]' });
  56. await page.send('DOM.setFileInputFiles', { files: [join(OUT, '..', 'pick.txt')], nodeId });
  57. await page.waitFor(`document.querySelectorAll('file-upload ul.uploaded li').length === 2`, { timeout: 30000, label: 'chosen' });
  58. await sleep(300); save('dom', 'upload-choose', await ev(`document.querySelector('file-upload').outerHTML`));
  59. // md-editor: drop a png and a .exe-named file (stored as .bin) into the second editor
  60. await page.goto(BASE + '/md-editor', { timeout: 45000 }); await hydrated(); await sleep(600);
  61. const PNG = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==';
  62. 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 })); })()`);
  63. await page.waitFor(`document.querySelectorAll('md-editor')[1].querySelector('input.value').value.includes('run.exe')`, { timeout: 30000, label: 'md uploaded' });
  64. await sleep(500);
  65. save('dom', 'md-upload', await ev(`document.querySelector('md-editor-demo').outerHTML`));
  66. const fileUrl = await ev(`document.querySelectorAll('md-editor')[1].querySelector('input.value').value.match(/\\((\\/md-editor\\/files\\/[^)]+\\.png)\\)/)[1]`);
  67. const fr = await fetch(BASE + fileUrl);
  68. save('http', 'stored-png-served', `${fr.status} ${fr.headers.get('content-type')} ${fr.headers.get('content-security-policy')} ${createHash('sha256').update(Buffer.from(await fr.arrayBuffer())).digest('hex')}`);
  69. const st = [];
  70. for (const d of ['uploads', 'md-files']) for (const f of readdirSync(join(TREE, 'storage', d)).sort()) st.push(`${d} ${f.replace(/^\d+-[0-9a-f]+/, 'T-R')} ${createHash('sha256').update(readFileSync(join(TREE, 'storage', d, f))).digest('hex')}`);
  71. save('http', 'storage-listing', st.sort().join('\n'));
  72. const probs = page.problems().filter(m => !/favicon|Failed to load resource/.test(m.text));
  73. save('dom', 'console-problems', probs.map(m => m.text).join('\n'));
  74. console.log(`saved http ${n.http}, dom ${n.dom} -> ${OUT}`);
  75. } catch (e) { console.log('BASELINE FAILED', e.stack || e, '\n', log.slice(-2000)); process.exitCode = 1; }
  76. finally {
  77. if (browser) { try { await browser.close(); } catch {} }
  78. server.kill('SIGTERM'); await new Promise(r => { if (server.exitCode !== null) return r(); server.once('exit', r); setTimeout(r, 3000); });
  79. rmSync(SES, { recursive: true, force: true });
  80. }

Branches

Latest commits

  • 9db927dfpaths: projects moved into /media/STORAGE/projects/WorldAPI/mre
  • 00a95329components (mission 007): re-vendor Hybriel to the shared static build 0f396652 (plugins; bin/ git-ignored), gate 324/0 old and new, real-data copy unchanged, report 007, same-output.mjs ports overridablemre
  • fe50766bmission brief 007mre
  • 2dce51b8components (mission 006) 4/4: docs (README comments + gate 324, STATUS, LOG), report reports/006-comments.mdmre
  • 9ec7273ecomponents layouts#2 (mission 006) 3/4: comments — each text is MdEditor readonly directly in its row (hl:web builds a composed child anew when a bound value changes, so the keyed one-row list was not needed); demo 'bob edits his comment elsewhere (a push)' + gate check that a text the host changes from outside is drawn anew; theme radii (var(--radius-small/large) with 5px/10px fallbacks: layouts' check-theme 0 problems with comments.hl copied in); README 'How it is built'; gate 324/0 (34 comments checks)mre
  • fd57c18bcomponents layouts#2 (mission 006) 2/3: comments block (components/comments, demo /comments) — pure Hybriel: '1 comment' / 'n comments', avatar initial, bubble with name, time, 'edited' (<details> with the earlier versions), the text drawn by MdEditor readonly (one-row list keyed by id + text, so an edit redraws), like ♥ n (aria-pressed), Edit / Delete (asks first) only where author == user, the form below in MdEditor (Comment button or Ctrl+Enter; a fresh editor after a post). Host passes comments + user and hands onPost / onEdit / onDelete / onLike (hybriel#87); demo keeps a mock thread from lib/comments.hl in the page, switches alice / bob / nobody. Home entry, routes, map line, README; base-look gate covers comments; 33 gate checks with real clicks / keysmre
  • 850a376bcomponents (mission 006) 1/3: MdEditor readonly = "true" — the Markdown shown formatted and nothing else (no toolbar, link form, file rows, placeholder, source view or switch; article contenteditable false, tabindex -1, role document; no field background or focus ring); the mount only loads the value. For the comments block, which draws every comment with the editor's own renderermre
  • ee9f1b57mission brief w6mre
  • fe691586components (mission 005) 4/4: docs (README components + gate 290, STATUS, LOG), report reports/005-fixes-16-17-5.mdmre
  • f1ebab53components #5 (mission 005) 3/4: file upload for several files (components/files-upload, demo /files-upload) — pure Hybriel, each file through emit server uploadFile (hybriel#94), drop or choose many, a row per file with live progress, one after the other in order, a drop during an upload waits, a file over uploadMax fails in its row and the next goes, 'n of m uploaded'; home entry, routes, map line, README; pagination keyboard focus ring #555 (Chrome painted its own orange one); docker-compose init: true (hybriel#156); gate 290/0 (17 #5 checks with real file drops, 1 #16 focus check)mre
  • 3b73ae5bcomponents #16 (mission 005) 2/4: Pagination tells the host the target page — the host hands onPage (hybriel#87: a function, not emit), called on every click that changes the page (pointer, Enter/Space, script click; Previous/Next/numbers/first/last; not … or the current page) with the target read from the clicked button's data-page before the rebuild; demo shows what the page was told; README Data out; 15 gate checks (14 fail on the old pagination)mre
  • 6b27c0f0components #17 (mission 005) 1/4: md-editor keeps backslash + r — parseInto dropped the two characters '\r' (C:\root -> C:oot) instead of a real carriage return; CR now decoded from JSON (String.fromCharCode does not parse in a member), real CRs also go from pasted plain text; 5 gate checks (3 fail on the old md-editor.hl)mre
  • 1a5dc327mission brief w5mre
  • a567b579components (mission 004) 3/3: docs (README Hybriel a832f73b + tables, STATUS, LOG), report reports/004-md-editor-tables.mdmre
  • 70fe7ab5components (mission 004) 2/3: GitHub pipe tables in the Hybriel MdEditor (creator notes#5; behaviour of notes md-editor.js 9acc27f, no JavaScript) — parse/render (header, :--/:-:/--: alignment, \| in cells and code, inline Markdown in cells, outer pipes optional), padded writer, unchanged table byte for byte, typing | a | b | Enter |---|---| Enter makes a table, Tab/Shift+Tab, Enter new row, Enter in empty last row leaves, Backspace/Delete never merge, selection across a table empties cells, pasted HTML table -> table, thin #999 lines, wide table scrolls in its box; demo third editor 'plan'; gate 252/0 (22 new table checks, 20 fail on the old md-editor.hl)mre
  • f2adb3f3components (mission 004) 1/3: Hybriel master a832f73b (incremental build cache, HL_CACHE_DIR, #151) — bin/hybriel sha256 e1b53f7ce687f5afbe3db34bcda69958f56e730571e4841923c9c8eb3d272db9 built from git archive a832f73b (HL_NO_PLUGINS=1 native/build.sh), the same nine plugins; container: HL_CACHE_DIR=/cache on volume hybriel-cache, /tmp tmpfs; tests wait COMPONENTS_COLD_MS (120 s) for every start; deploy.sh DEPLOY_URL_WAIT 120 s; gate 230/0 coldmre
  • 91bd8a0dmission brief (w4)mre
  • 3bc905c5components #15 (mission 003) 2/2: docs (README Look, STATUS, LOG), reportmre
  • 5a98d77ecomponents #15 (mission 003) 1/2: black/white base look — greys for nuances, no WorldAPI fallbacks, no decorative frames; site + icon black/white; gate 230/0mre
  • 3f93d716components code order (mission 002) 4/4: docs, tests/letcount.py, tests/same-output*, reportmre