gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit7ed2e5e57ed2e5e5deploy.sh: a gate without a 'passed,' line (check-theme) no longer ends the script silently (grep under pipefail), as gitoria/layoutsmre7ed2e5e5/tests/e2e-attachments.mjs

12.7 KB

  1. // tests/e2e-attachments.mjs (mission 020): E2E of tickets#27 in a REAL browser (lisbeth's test Chrome over CDP, ONE tab reused).
  2. // node tests/e2e-attachments.mjs <old|new> <port> <sid> <ticket path e.g. /antcolony/20> <shotdir> [targetId]
  3. // 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>.
  4. // DOM.setFileInputFiles paths are on lisbeth: /tmp/j3-files/{phone-390.png,desktop-1280.png,huge.bin}.
  5. import { writeFileSync } from 'node:fs';
  6. const [mode, port, sid, path, shotDir, tidArg] = process.argv.slice(2);
  7. const BASE = `http://127.0.0.1:${port}`, F = n => '/tmp/j3-files/' + n, sleep = ms => new Promise(r => setTimeout(r, ms));
  8. const list = await (await fetch('http://127.0.0.1:9223/json/list')).json();
  9. 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'));
  10. const ws = new WebSocket(tgt.webSocketDebuggerUrl); await new Promise(r => ws.onopen = r);
  11. let id = 0; const pend = new Map(), evs = [];
  12. 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); };
  13. const send = (method, params = {}) => new Promise((ok, bad) => { const i = ++id; pend.set(i, [ok, bad]); ws.send(JSON.stringify({ id: i, method, params })); });
  14. 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; };
  15. 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; };
  16. 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 }; })()`);
  17. 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 }); };
  18. 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 }));
  19. 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); };
  20. const results = []; const check = (n, ok, d = '') => { results.push([n, !!ok]); console.log((ok ? 'PASS ' : 'FAIL ') + n + (ok ? '' : ' ' + d)); };
  21. 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 }); };
  22. 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'))`);
  23. 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 }; })()`);
  24. 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))`);
  25. 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); })`);
  26. await send('Page.enable'); await send('Runtime.enable'); await send('DOM.enable'); await send('Network.enable');
  27. await send('Network.setCookie', { name: 'hlsid', value: sid, url: BASE, httpOnly: true });
  28. const widths = [390, 1280];
  29. for (const W of widths) {
  30. const tag = `${mode}-${W}`;
  31. if (W === 390) await send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 2, mobile: true });
  32. else { await send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 900, deviceScaleFactor: 1, mobile: false }); }
  33. await send('Page.navigate', { url: BASE + path });
  34. await waitFor(`!!document.querySelector('#commentform')`, 'comment form');
  35. await sleep(1500);
  36. const n0 = await ev(`document.querySelectorAll('#events li.comment').length`);
  37. await rect('#commentform'); await sleep(300);
  38. await shot(`${tag}-form-before`);
  39. const m0 = await metrics(); const is0 = await inputSizes();
  40. console.log(`[${tag}] form`, JSON.stringify(m0), 'inputs', JSON.stringify(is0), 'targets', JSON.stringify(await targets()));
  41. 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)); }
  42. if (mode === 'old') continue;
  43. // 1. choose two pictures
  44. await chooseFiles(['phone-390.png', 'desktop-1280.png']);
  45. 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');
  46. 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()));
  47. // 2. type text with real input, then paste a picture with real Ctrl+V
  48. await click('#commentform md-editor article'); await sleep(300);
  49. await send('Input.insertText', { text: `E2E ${tag}: two chosen, one pasted` });
  50. // CDP cannot fill lisbeth's system clipboard (navigator.clipboard.write says ok, a real Ctrl+V then pastes the user's old clipboard text),
  51. // 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.
  52. 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; } })()`);
  53. 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);
  54. const pk = await picked();
  55. 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]));
  56. await rect('#commentform files-upload'); await sleep(300); await shot(`${tag}-form-3thumbs`);
  57. // 3. remove one with the cross (first picked)
  58. await click('#commentform files-upload li.picked button.remove'); await sleep(500);
  59. const pk2 = await picked();
  60. check(`${tag}: ✕ removes one (2 left, first one gone)`, pk2.length === 2 && !pk2.some(x => x.startsWith('phone-390')), JSON.stringify(pk2));
  61. // 4. too big
  62. await chooseFiles(['huge.bin']);
  63. await waitFor(`document.querySelectorAll('#commentform files-upload li.refused').length === 1`, 'refused', 8000);
  64. const refusedTxt = await ev(`[...document.querySelectorAll('#commentform files-upload li.refused .state')].map(s => s.textContent).join()`);
  65. check(`${tag}: 11 MB file → "${refusedTxt}"`, /Too big/.test(refusedTxt) && (await picked()).length === 2, refusedTxt);
  66. const mf = await metrics(); const tg = await targets();
  67. console.log(`[${tag}] with files`, JSON.stringify(mf), 'targets', JSON.stringify(tg));
  68. await rect('#commentform files-upload'); await sleep(300); await shot(`${tag}-form-refused`);
  69. if (W === 390) {
  70. check(`${tag}: with picked + refused rows nothing wider than 390`, mf.scrollW <= 390 && mf.wide.length === 0, JSON.stringify(mf));
  71. 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));
  72. }
  73. // 5. send: Comment button at 390 (real click), Ctrl+Enter at 1280
  74. const stored0 = await ev(`document.querySelectorAll('#events li.comment').length`);
  75. if (W === 390) { await click('#commentform button.comment-post'); }
  76. else { await click('#commentform md-editor article'); await key('Enter', 'Enter', 13, 2, { text: '\r' }); }
  77. 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);
  78. await sleep(1500);
  79. 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; })()`);
  80. 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));
  81. await ev(`(() => { const li = [...document.querySelectorAll('#events li.comment')].filter(l => l.textContent.includes('E2E ${tag}')).pop(); li.scrollIntoView({ block: 'center' }); })()`); await sleep(400);
  82. await shot(`${tag}-comment-sent`);
  83. const m2 = await metrics();
  84. if (W === 390) check(`${tag}: after send nothing wider than 390`, m2.scrollW <= 390 && m2.wide.length === 0, JSON.stringify(m2));
  85. // 6. tap a thumbnail → full size in a new tab (we close that one tab ourselves)
  86. const before = new Set((await (await fetch('http://127.0.0.1:9223/json/list')).json()).map(t => t.id));
  87. 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`;
  88. const href = await ev(`document.querySelector(${JSON.stringify(sel)}).getAttribute('href') + ' target=' + document.querySelector(${JSON.stringify(sel)}).target`);
  89. await click(sel);
  90. 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'); }
  91. 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));
  92. if (opened) { await sleep(800); await fetch('http://127.0.0.1:9223/json/close/' + opened.id); }
  93. await send('Page.bringToFront');
  94. }
  95. await send('Emulation.clearDeviceMetricsOverride');
  96. const bad = results.filter(r => !r[1]);
  97. console.log(`\n${mode}: ${results.length - bad.length} passed, ${bad.length} failed`);
  98. ws.close(); process.exit(0);

Branches

Latest commits

  • 7ed2e5e5deploy.sh: a gate without a 'passed,' line (check-theme) no longer ends the script silently (grep under pipefail), as gitoria/layoutsmre
  • bf9064a3mission 022: tickets on the layouts theme (step 1): shell, styles, gates, audit, E2E; reportmre
  • f3d61711mission 022 WIP: tickets on the layouts theme (dbe3de7): AppHeader/MainMenu/UserMenu/Sidebar/ContentFirst shell, styles reduced to the app's own, check-theme in the gates, 390 audit + real-Chrome walk scriptmre
  • 31cabfccmission 021: E2E script, report, LOG, STATUSmre
  • 6aea8683editor look: .empty rule only for p.empty, files off where tickets has no upload, state note one line, events test scrolls the editor into view; synced md-editor (components d702d76+6f27ad3); gate 377/0, events 52/0mre
  • dce6ffa6Merge branch 'w28-deflake'mre
  • 536092a1tickets (mission 019): de-flake the m016 comment clicks (B: unliked) — calmClick waits until the button stops moving; test only, no app changemre
  • 9c5fd42amission 020: attachments E2E proof (lisbeth Chrome, real-data copy), reportmre
  • 1206404fREADME attachments, report 018, LOG/STATUSmre
  • 3d9e7f3ctests: m017 gate fixes (list count, waits before delete clicks); gate 373/0mre
  • dd41d5bcre-sync components 15be2ac; mission 018mre
  • 420ad1bbtickets (mission 017 WIP, tickets#27): comment attachments — lib/attachments.hl (storage/attachments, limits, type by content, members-only GET /api/attachments/:id, delete drops, edit keeps), multipart POST …/comments (lib/multipart.hl), Respond block in FilesUpload (blocks verbatim from components w27c 1f8d79d), gate m017 checks written (not yet run); report, LOG, STATUSmre
  • a7a1380dmission brief 017mre
  • f83d9c0dtickets (mission 016): report reports/016-comments-block.md, LOG, STATUS, README gate countmre
  • eef80f55tickets (mission 016): comments through the shared Comments block (layouts#2) — edit (author, earlier versions kept), delete (author, asks; leaves one line in the history), like (members, toggle) on the server (lib/comments.hl, append-only tables), faces + API …/comments/:comment/{edit,delete,like}, push commentChanged; every run of comments is a block in place in the history; Markdown fields on the Hybriel MdEditor (shared/md-editor.js retired: it took over the block's <md-editor>); blocks copied verbatim from components.hybriel 9db927d (tools/sync-components.sh); gates browser 351/0 (old 326/0), events 52/0 (old 52/0)mre
  • eb7aeeb9mission brief 016mre
  • e4c34759paths: projects moved into /media/STORAGE/projects/WorldAPI/mre
  • 26efb23freport w6-events (events test)mre
  • c6bfab04mission 015: re-vendor Hybriel 0f396652 (static build), reportmre
  • b7ec5981mission brief 015mre