components
All repositories: gitoria
8.0 KB
// tests/same-output.mjs (components mission 002): same-output baseline of a CODE-ONLY COPY of a components tree.// node tests/same-output.mjs <tree copy> <outdir> (README "Test" → "Same output"; refuses a tree with .git: it wipes <tree>/storage)// Server on 8750 (cwd = tree, its own storage/), Chrome 8751-8759. Saves every HTTP answer (pages, READMEs, icons, css,// manifest, worker, every browser module a page loads), the hydrated DOM of every page, and a file upload (drop) on// /file-upload + a md-editor drop: the component's DOM afterwards and the sha256 of every stored file. Stops all by PID.import { spawn } from 'node:child_process';import { writeFileSync, mkdirSync, rmSync, readdirSync, readFileSync, 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 (its storage/ is wiped)'); process.exit(2); }const PORT = Number(process.env.SO_PORT || 8750), BASE = `http://127.0.0.1:${PORT}`;rmSync(OUT, { recursive: true, force: true }); mkdirSync(OUT, { recursive: true });rmSync(join(TREE, 'storage'), { recursive: true, force: true });const SES = join(OUT, '..', 'sessions-' + process.pid); rmSync(SES, { recursive: true, force: true }); mkdirSync(SES, { 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, COMPONENTS_PORT: String(PORT), COMPONENTS_SESSIONS: SES + '/', COMPONENTS_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 {// a new Hybriel compiles the app at its first start (cold 18–41 s, hybriel#148): up to COMPONENTS_COLD_MS (default 120 s)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); }const names = ['month-view', 'date-picker', 'range-picker', 'pagination', 'md-editor', 'code-editor', 'file-upload', 'modal'];const pages = ['/', ...names.map(c => '/' + c)];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'];const seen = new Set();const get = async (u) => {if (seen.has(u)) return; seen.add(u);const r = await fetch(BASE + u); 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') || ''}\n${body}`);if (/text\/html|javascript/.test(ct)) for (const m of body.matchAll(/["'(](\/(?:__hl\/[\w./-]+|components\/[\w./-]+\.hl)(?:\?v=\w+)?)/g)) await get(m[1]);};for (const u of urls) await get(u);browser = await launchBrowser({ debugPortRange: (process.env.SO_CHROME || "8751-8759").split("-").map(Number) });const page = await browser.newPage();await page.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 900, deviceScaleFactor: 1, mobile: false });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 p of pages) { await page.goto(BASE + p, { timeout: 45000 }); await hydrated(); await sleep(700); save('dom', p, await ev(dom)); }// file upload: drop a 300 KB file, then choose one through the inputawait page.goto(BASE + '/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`));writeFileSync(join(OUT, '..', 'pick.txt'), 'hello m002');const { root } = await page.send('DOM.getDocument');const { nodeId } = await page.send('DOM.querySelector', { nodeId: root.nodeId, selector: 'file-upload input[type=file]' });await page.send('DOM.setFileInputFiles', { files: [join(OUT, '..', 'pick.txt')], nodeId });await page.waitFor(`document.querySelectorAll('file-upload ul.uploaded li').length === 2`, { timeout: 30000, label: 'chosen' });await sleep(300); save('dom', 'upload-choose', await ev(`document.querySelector('file-upload').outerHTML`));// md-editor: drop a png and a .exe-named file (stored as .bin) into the second editorawait page.goto(BASE + '/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('md-editor-demo').outerHTML`));const fileUrl = await ev(`document.querySelectorAll('md-editor')[1].querySelector('input.value').value.match(/\\((\\/md-editor\\/files\\/[^)]+\\.png)\\)/)[1]`);const fr = await fetch(BASE + fileUrl);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')}`);const st = [];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')}`);save('http', 'storage-listing', st.sort().join('\n'));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} -> ${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); });rmSync(SES, { recursive: true, force: true });}
Branches
Latest commits
- b0f1ec28MdEditor: a clipboard with text always pastes the text, also when a picture is on it too (a spreadsheet or office app), files on or off; a picture alone still goes to the files; real Ctrl+V gate tests/md-paste-files.mjs (tickets#49)mre
- 4bd11128MdEditor: the Table button's empty table is written as a real pipe table (empty cells), so it survives the source switch, a save and a reload (notes#7)mre
- 7437e32bMdEditor draws its surface at once when claimed from server HTML: 1 ms mount animation, the first editor mounts all editors of the pagemre
- 5de0264cRe-vendor onto Hybriel master acaceaf3 (set-day27b): binary, lib and plugins; exit 1 on a startup fault; .gitignore binmre
- 79c77e7dMerge sb3-standby: components deploys through its standbymre
- c5442043components: no jobs switch needed in the standbymre
- 8d2fb24ccomponents: a standby container (port 45016, profile standby); deploy hands over through standby-swap.sh without a gapmre
- c2834dd3Merge mr-fixes: media player state after a queue pick, Range handling, cover-less audio, accessibility labelsmre
- 354fe3c6Media player: audio without a cover starts and shows its time (the mount tick sits on the seek bar, which every item has); the speed button names the current speed, the seek slider says its time in words; a gate page for the first render on cover-less audio and a fourth demo queue item without a covermre
- ee4aee1eMedia player: a new queue item shows its own speed, mute, play state and time and starts when asked, also for two videos in a row; the media route reads suffix ranges and ignores range lists and garbage instead of answering 500; stronger gate checks (the 10 percent drag, the played bar, the queue tap)mre
- 9a4f9b31Merge mp-player: media served from the committed filesmre
- ab96e686Media route: serve the demo's media from the committed files in components/media-player (storage/ is not in git, the deploy gate found no files)mre
- b2980734Merge mp-player: the media player (components/media-player), its demo and the media iconsmre
- 1c41293eMediaPlayer: back / forward 10 s as replay / forward 10 icons (circular arrow with a 10), the play button keeps its surface background on audio and video, the media route's range end is a letmre
- 9e1ab228MP: report, LOG line, STATUS entrymre
- dd003e5dMediaPlayer: audio and video in one phone-first player (components/media-player), its demo /media-player with a queue, the media icons in components/icons, the demo's media files served with ranges (lib/media.hl), 35 gate checksmre
- e54f83adMdEditor: text typed before the editor is built is kept (the build takes it in once, the input handler no longer writes it to the field first), tickets#35mre
- 8c920932gate: the 11 old drop-zone checks now test the one-box pick mode (drop anywhere in the box, Choose files button inside it, no drop zone)mre
- 626de199MdEditor: copy and cut put the selection's Markdown on the clipboard, a clipboard with HTML only pastes its text, gate checks for copy, cut and paste (components#20)mre
- 5228126dUX: components synced from the tickets/layouts UX mission (comments: State select in the footer and button words; files-upload: one-box pick mode; modal: footer rule for its own footer). WIP: the gate's #18 pick-mode checks still expect the old drop zone (11 fail), see the UX2 reportmre