tickets
All repositories: gitoria
12.7 KB
// tests/e2e-attachments.mjs (mission 020): E2E of tickets#27 in a REAL browser (lisbeth's test Chrome over CDP, ONE tab reused).// node tests/e2e-attachments.mjs <old|new> <port> <sid> <ticket path e.g. /antcolony/20> <shotdir> [targetId]// The app runs on loreana (copy of the data), reached from lisbeth's Chrome through a reverse ssh forward at 127.0.0.1:<port>.// DOM.setFileInputFiles paths are on lisbeth: /tmp/j3-files/{phone-390.png,desktop-1280.png,huge.bin}.import { writeFileSync } from 'node:fs';const [mode, port, sid, path, shotDir, tidArg] = process.argv.slice(2);const BASE = `http://127.0.0.1:${port}`, F = n => '/tmp/j3-files/' + n, sleep = ms => new Promise(r => setTimeout(r, ms));const list = await (await fetch('http://127.0.0.1:9223/json/list')).json();const tgt = tidArg ? list.find(t => t.id === tidArg) : list.find(t => t.type === 'page' && t.url.startsWith('about:blank') || t.url.startsWith('http://127.0.0.1:87'));const ws = new WebSocket(tgt.webSocketDebuggerUrl); await new Promise(r => ws.onopen = r);let id = 0; const pend = new Map(), evs = [];ws.onmessage = m => { const d = JSON.parse(m.data); if (d.id && pend.has(d.id)) { const [ok, bad] = pend.get(d.id); pend.delete(d.id); d.error ? bad(new Error(JSON.stringify(d.error))) : ok(d.result); } else evs.push(d); };const send = (method, params = {}) => new Promise((ok, bad) => { const i = ++id; pend.set(i, [ok, bad]); ws.send(JSON.stringify({ id: i, method, params })); });const ev = async x => { const r = await send('Runtime.evaluate', { expression: x, awaitPromise: true, returnByValue: true }); if (r.exceptionDetails) throw new Error(JSON.stringify(r.exceptionDetails).slice(0, 300)); return r.result.value; };const waitFor = async (x, label, t = 20000) => { for (const end = Date.now() + t; Date.now() < end;) { if (await ev(x).catch(() => false)) return true; await sleep(150); } console.log(' TIMEOUT waiting for', label); return false; };const rect = async sel => ev(`(() => { const e = document.querySelector(${JSON.stringify(sel)}); if (!e) return null; e.scrollIntoView({ block: 'center' }); const r = e.getBoundingClientRect(); return { x: r.x + r.width / 2, y: r.y + r.height / 2, w: r.width, h: r.height }; })()`);const click = async sel => { const r = await rect(sel); if (!r) throw new Error('no ' + sel); await sleep(100); const r2 = await rect(sel); for (const [type, extra] of [['mouseMoved', {}], ['mousePressed', { button: 'left', clickCount: 1 }], ['mouseReleased', { button: 'left', clickCount: 1 }]]) await send('Input.dispatchMouseEvent', { type, x: r2.x, y: r2.y, ...extra }); };const key = (k, code, vk, mod = 0, extra = {}) => send('Input.dispatchKeyEvent', { type: 'rawKeyDown', modifiers: mod, key: k, code, windowsVirtualKeyCode: vk, nativeVirtualKeyCode: vk, ...extra }).then(() => send('Input.dispatchKeyEvent', { type: 'keyUp', modifiers: mod, key: k, code, windowsVirtualKeyCode: vk, nativeVirtualKeyCode: vk }));const shot = async name => { const r = await send('Page.captureScreenshot', { format: 'png' }); writeFileSync(`${shotDir}/${name}.png`, Buffer.from(r.data, 'base64')); console.log(' shot', name); };const results = []; const check = (n, ok, d = '') => { results.push([n, !!ok]); console.log((ok ? 'PASS ' : 'FAIL ') + n + (ok ? '' : ' ' + d)); };const chooseFiles = async names => { const { root } = await send('DOM.getDocument'); const { nodeId } = await send('DOM.querySelector', { nodeId: root.nodeId, selector: '#commentform files-upload label.choose input[type=file]' }); await send('DOM.setFileInputFiles', { files: names.map(F), nodeId }); };const picked = () => ev(`[...document.querySelectorAll('#commentform files-upload li.picked')].map(li => li.querySelector('.name').textContent + ':' + (li.querySelector('img.thumb') ? li.querySelector('img.thumb').naturalWidth : 'kind'))`);const metrics = () => ev(`(() => { const W = window.innerWidth; const wide = [...document.querySelectorAll('body *')].filter(e => { const r = e.getBoundingClientRect(); return r.width > 0 && (r.right > W + 0.5 || r.left < -0.5); }).filter(e => !e.closest('[data-allow-scroll]')).slice(0, 5).map(e => e.tagName + '.' + e.className + ' ' + Math.round(e.getBoundingClientRect().right)); return { W, scrollW: document.documentElement.scrollWidth, wide }; })()`);const inputSizes = () => ev(`[...document.querySelectorAll('#commentform input:not([type=hidden]):not([type=file]), #commentform textarea, #commentform [contenteditable], #commentform md-editor article')].filter(e => e.getBoundingClientRect().width > 0).map(e => e.tagName + '.' + e.className + ' ' + parseFloat(getComputedStyle(e).fontSize))`);const targets = () => ev(`[...document.querySelectorAll('#events a.comment-thumb, #events a.comment-file, #commentform files-upload label.choose, #commentform files-upload label.camera, #commentform files-upload button.remove, #commentform button.comment-post, #commentform button[type=submit]')].filter(e => e.getBoundingClientRect().width > 0).map(el => { const r = el.getBoundingClientRect(); return el.tagName + '.' + el.className + ' ' + Math.round(r.width) + 'x' + Math.round(r.height); })`);await send('Page.enable'); await send('Runtime.enable'); await send('DOM.enable'); await send('Network.enable');await send('Network.setCookie', { name: 'hlsid', value: sid, url: BASE, httpOnly: true });const widths = [390, 1280];for (const W of widths) {const tag = `${mode}-${W}`;if (W === 390) await send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 2, mobile: true });else { await send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 900, deviceScaleFactor: 1, mobile: false }); }await send('Page.navigate', { url: BASE + path });await waitFor(`!!document.querySelector('#commentform')`, 'comment form');await sleep(1500);const n0 = await ev(`document.querySelectorAll('#events li.comment').length`);await rect('#commentform'); await sleep(300);await shot(`${tag}-form-before`);const m0 = await metrics(); const is0 = await inputSizes();console.log(`[${tag}] form`, JSON.stringify(m0), 'inputs', JSON.stringify(is0), 'targets', JSON.stringify(await targets()));if (W === 390) { check(`${tag}: nothing wider than 390 (scrollWidth ${m0.scrollW})`, m0.scrollW <= 390 && m0.wide.length === 0, JSON.stringify(m0)); check(`${tag}: inputs >= 16px`, is0.length > 0 && is0.every(s => +s.split(' ').pop() >= 16), JSON.stringify(is0)); }if (mode === 'old') continue;// 1. choose two picturesawait chooseFiles(['phone-390.png', 'desktop-1280.png']);await waitFor(`document.querySelectorAll('#commentform files-upload li.picked').length === 2 && [...document.querySelectorAll('#commentform files-upload img.thumb')].every(i => i.complete && i.naturalWidth > 0)`, 'two thumbs');check(`${tag}: two chosen pictures wait as drawn thumbnails`, JSON.stringify(await picked()) === JSON.stringify(['phone-390.png:390', 'desktop-1280.png:1280']), JSON.stringify(await picked()));// 2. type text with real input, then paste a picture with real Ctrl+Vawait click('#commentform md-editor article'); await sleep(300);await send('Input.insertText', { text: `E2E ${tag}: two chosen, one pasted` });// CDP cannot fill lisbeth's system clipboard (navigator.clipboard.write says ok, a real Ctrl+V then pastes the user's old clipboard text),// and a real Ctrl+V would paste that private text into the form. So: a paste event dispatched on the focused editor carrying a File.const put = await ev(`(async () => { try { const c = document.createElement('canvas'); c.width = 160; c.height = 100; const x = c.getContext('2d'); x.fillStyle = '#246'; x.fillRect(0, 0, 160, 100); x.fillStyle = '#fc0'; x.fillRect(20, 20, 60, 40); const bl = await new Promise(r => c.toBlob(r, 'image/png')); const dt = new DataTransfer(); dt.items.add(new File([bl], 'image.png', { type: 'image/png' })); const t = document.querySelector('#commentform md-editor article'); t.focus(); t.dispatchEvent(new ClipboardEvent('paste', { clipboardData: dt, bubbles: true, cancelable: true })); return 'synthetic paste'; } catch (e) { return 'ERR ' + e.message; } })()`);await waitFor(`document.querySelectorAll('#commentform files-upload li.picked').length === 3 && [...document.querySelectorAll('#commentform files-upload img.thumb')].every(i => i.complete && i.naturalWidth > 0)`, 'three thumbs', 8000);const pk = await picked();check(`${tag}: ${put} of a picture (real Ctrl+V impossible via CDP) adds the 3rd thumbnail (image.png:160)`, pk.length === 3 && pk[2] === 'image.png:160', JSON.stringify([put, pk]));await rect('#commentform files-upload'); await sleep(300); await shot(`${tag}-form-3thumbs`);// 3. remove one with the cross (first picked)await click('#commentform files-upload li.picked button.remove'); await sleep(500);const pk2 = await picked();check(`${tag}: ✕ removes one (2 left, first one gone)`, pk2.length === 2 && !pk2.some(x => x.startsWith('phone-390')), JSON.stringify(pk2));// 4. too bigawait chooseFiles(['huge.bin']);await waitFor(`document.querySelectorAll('#commentform files-upload li.refused').length === 1`, 'refused', 8000);const refusedTxt = await ev(`[...document.querySelectorAll('#commentform files-upload li.refused .state')].map(s => s.textContent).join()`);check(`${tag}: 11 MB file → "${refusedTxt}"`, /Too big/.test(refusedTxt) && (await picked()).length === 2, refusedTxt);const mf = await metrics(); const tg = await targets();console.log(`[${tag}] with files`, JSON.stringify(mf), 'targets', JSON.stringify(tg));await rect('#commentform files-upload'); await sleep(300); await shot(`${tag}-form-refused`);if (W === 390) {check(`${tag}: with picked + refused rows nothing wider than 390`, mf.scrollW <= 390 && mf.wide.length === 0, JSON.stringify(mf));check(`${tag}: tap targets >= 44 px (${tg.length} measured)`, tg.length >= 5 && tg.every(t => { const [w, h] = t.split(' ').pop().split('x').map(Number); return w >= 44 && h >= 44; }), JSON.stringify(tg));}// 5. send: Comment button at 390 (real click), Ctrl+Enter at 1280const stored0 = await ev(`document.querySelectorAll('#events li.comment').length`);if (W === 390) { await click('#commentform button.comment-post'); }else { await click('#commentform md-editor article'); await key('Enter', 'Enter', 13, 2, { text: '\r' }); }const sent = await waitFor(`document.querySelectorAll('#commentform files-upload li.picked').length === 0 && [...document.querySelectorAll('#events li.comment')].some(li => li.querySelectorAll('ul.comment-files img').length === 2 && li.textContent.includes('E2E ${tag}'))`, 'posted', 30000);await sleep(1500);const th = await ev(`(() => { const li = [...document.querySelectorAll('#events li.comment')].filter(l => l.textContent.includes('E2E ${tag}')).pop(); return li ? [...li.querySelectorAll('ul.comment-files img')].map(i => [i.naturalWidth, Math.round(i.getBoundingClientRect().width), Math.round(i.getBoundingClientRect().height)]) : null; })()`);check(`${tag}: sent; the comment shows 2 thumbnails drawn (${JSON.stringify(th)}); the form is empty`, sent && th && th.length === 2 && th.every(x => x[0] > 0), JSON.stringify(th));await ev(`(() => { const li = [...document.querySelectorAll('#events li.comment')].filter(l => l.textContent.includes('E2E ${tag}')).pop(); li.scrollIntoView({ block: 'center' }); })()`); await sleep(400);await shot(`${tag}-comment-sent`);const m2 = await metrics();if (W === 390) check(`${tag}: after send nothing wider than 390`, m2.scrollW <= 390 && m2.wide.length === 0, JSON.stringify(m2));// 6. tap a thumbnail → full size in a new tab (we close that one tab ourselves)const before = new Set((await (await fetch('http://127.0.0.1:9223/json/list')).json()).map(t => t.id));const sel = `#events li.comment[data-id="${await ev(`[...document.querySelectorAll('#events li.comment')].filter(l => l.textContent.includes('E2E ${tag}')).pop().dataset.id`)}"] ul.comment-files li:nth-child(1) a.comment-thumb`;const href = await ev(`document.querySelector(${JSON.stringify(sel)}).getAttribute('href') + ' target=' + document.querySelector(${JSON.stringify(sel)}).target`);await click(sel);let opened = null; for (let i = 0; i < 30 && !opened; i++) { await sleep(250); opened = (await (await fetch('http://127.0.0.1:9223/json/list')).json()).find(t => !before.has(t.id) && t.type === 'page'); }check(`${tag}: tap on a thumbnail opens the full picture in a new tab (${href}) → ${opened && opened.url}`, !!opened && opened.url.startsWith(BASE + '/api/attachments/'), JSON.stringify(opened));if (opened) { await sleep(800); await fetch('http://127.0.0.1:9223/json/close/' + opened.id); }await send('Page.bringToFront');}await send('Emulation.clearDeviceMetricsOverride');const bad = results.filter(r => !r[1]);console.log(`\n${mode}: ${results.length - bad.length} passed, ${bad.length} failed`);ws.close(); process.exit(0);
Branches
Latest commits
- d74a5482sync components.hybriel 134b4e3: MdEditor builds an editor put into the page at once, redraws a surface put in anew (F5, hybriel#211)mre
- 9d02c540sync components.hybriel 6b0936a: the 'edited' foldable drops the theme's border and marginmre
- 22751914sync components.hybriel 8d79ff7: bubble hugs its content, quiet 'edited' label; gate checksmre
- c8452453sync components 9a: shared Icon (icons/icons.hl), md-editor toolbar icons + single focus ring (components f4-icons ba96735)mre
- 52ba11e8sync-components: copy icons/icons.hl + README (F4); testsmre
- 138d198dmd-editor.hl: verbatim copy of components f3-mdvalue (an older text handed back is kept)mre
- 18d2df60md-editor.hl: verbatim copy of components f3-mdvalue (an outside value change is shown by the editor)mre
- f6764bedreports/H1-hydrate.mdmre
- 1bbbf0edtests/browser.mjs: wait for hydration before clicking the login button on / (device B)mre
- 6f503cfctests/cdp.mjs: HL_CPU_THROTTLE=<rate> optional CPU throttling for gate runsmre
- e17e2855re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
- a6ddccd2re-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
- 81e036b7docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
- 5d8d2cf6deploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
- 58e8c02cmission 024: report, LOG, STATUS, e2e fixmre
- 50778073tests/e2e-route-marker.mjs: first paint marker, comments post/edit redrawmre
- c5203298mission 024: MainMenu marks the page from the route (layouts 0bcc629 main-menu.hl); browser-side marker removed; gate: marker in the server HTMLmre
- b1a4c270re-vendor Hybriel master f9614007: bin/ (git-ignored) and plugins wholemre
- 866397a0mission 023: theme from layouts 76f99f6 (current marker, menu count badge), components from 3794c59 (MdEditor keys); Inbox count as badge, current by address; gates and E2E; reportmre
- 7ed2e5e5deploy.sh: a gate without a 'passed,' line (check-theme) no longer ends the script silently (grep under pipefail), as gitoria/layoutsmre