gitoria

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitc49ce093c49ce093|||PR WIP remove notes polling and use framework reachabilityAtlasc49ce093/tests/table-button.mjs

8.4 KB

  1. // tests/table-button.mjs (notes#7 / notes#5 reopened): the Table button's table survives "Markdown source" and back, a save, a fresh open
  2. // from the list and a full reload — empty, with text in its cells, and with a header only. Real clicks and keys in headless Chrome at 390
  3. // and 1280 on a COPY of the newest deploy backup (a session of the creator written into the copy). Fails on 6091320 (an empty button
  4. // table was written as nothing). node tests/table-button.mjs [port=8721] [chrome-from-to=8735-8739] [backup.tgz]
  5. // N5_APP=<dir> runs another code tree (the old one, to see this gate fail). Kills only what it started; the copy is deleted.
  6. import { spawn, execFileSync } from 'node:child_process';
  7. import { writeFileSync, mkdirSync, rmSync, existsSync, readdirSync } from 'node:fs';
  8. import { createHash, randomBytes } from 'node:crypto';
  9. import { join, resolve, dirname } from 'node:path';
  10. import { fileURLToPath } from 'node:url';
  11. import { launchBrowser } from './cdp.mjs';
  12. const HERE = dirname(fileURLToPath(import.meta.url));
  13. const APP = resolve(process.env.N5_APP || join(HERE, '..'));
  14. const [portArg, chromeArg, tgzArg] = process.argv.slice(2);
  15. const PORT = Number(portArg || 8721);
  16. const [CH_FROM, CH_TO] = (chromeArg || '8735-8739').split('-').map(Number);
  17. const BK = '/media/STORAGE/deploy-backups/notes.worldapi.org';
  18. const tgz = tgzArg || join(BK, readdirSync(BK).filter(f => f.endsWith('.tgz')).sort().pop());
  19. const BASE = `http://notes.test:${PORT}`, API = `http://127.0.0.1:${PORT}`;
  20. const W = join(HERE, '..', '.scratch/table-button');
  21. const SHOTS = join(HERE, '..', '.scratch');
  22. if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';
  23. process.env.HL_CHROME_ARGS = `--host-resolver-rules=MAP notes.test 127.0.0.1|--unsafely-treat-insecure-origin-as-secure=${BASE}`;
  24. rmSync(W, { recursive: true, force: true });
  25. mkdirSync(join(W, 'data'), { recursive: true }); mkdirSync(join(W, 'sessions'), { recursive: true });
  26. execFileSync('tar', ['-xzf', resolve(tgz), '-C', join(W, 'data'), 'storage/mpackdb']);
  27. const sid = randomBytes(16).toString('hex'), now = Date.now();
  28. writeFileSync(join(W, 'sessions', createHash('sha256').update(sid).digest('hex')),
  29. JSON.stringify({ created: now, data: { tag: 'tb' }, handled: [], id: sid, seen: now, user: { id: '0muh6o5a3kkd' } }), { mode: 0o600 });
  30. let failures = 0, passes = 0;
  31. const check = (label, ok, detail = '') => { console.log(`${ok ? 'ok ' : 'FAIL'} ${label}${ok ? '' : ' — ' + detail}`); if (ok) passes++; else failures++; };
  32. const sleep = (ms) => new Promise(r => setTimeout(r, ms));
  33. const J = JSON.stringify;
  34. let log = '';
  35. const srv = spawn(join(APP, 'bin/hybriel'), ['project.hl'], { cwd: APP, stdio: ['ignore', 'pipe', 'pipe'],
  36. env: { ...process.env, NOTES_PORT: String(PORT), NOTES_PUBLIC_URL: BASE, NOTES_STORAGE: join(W, 'data/storage/mpackdb'),
  37. NOTES_SESSIONS: join(W, 'sessions') + '/', NOTES_WATCH: '0', IDENT_URL: 'http://ident.test', IDENT_API_KEY: 'pk', IDENT_API_SECRET: 'sk' } });
  38. srv.stdout.on('data', d => log += d); srv.stderr.on('data', d => log += d);
  39. const api = async (p) => (await fetch(API + p, { headers: { cookie: 'notessid=' + sid } })).json();
  40. const R = (e) => `(() => { const r = document.querySelector('#notetext md-editor'); if (!r) return null; return (${e}); })()`;
  41. let b = null;
  42. try {
  43. for (let i = 0; i < 480; i++) { try { if ((await fetch(API + '/')).ok) break; } catch {} await sleep(250); }
  44. b = await launchBrowser({ debugPortRange: [CH_FROM, CH_TO] });
  45. const p = await b.newPage();
  46. await p.send('Network.enable');
  47. await p.send('Network.setCookie', { name: 'notessid', value: sid, url: BASE + '/' });
  48. const state = () => p.evaluate(R(`({ tables: r.querySelectorAll('article table').length, th: r.querySelectorAll('article th').length, td: r.querySelectorAll('article td').length, source: r.classList.contains('source'), field: document.querySelector('#notetext input[name=text]').value })`));
  49. const clickSel = async (sel) => {
  50. const bx = await p.evaluate(R(`(() => { const e = r.querySelector(${J(sel)}); if (!e) return null; e.scrollIntoView({ block: 'center' }); const q = e.getBoundingClientRect(); return [q.left + q.width / 2, q.top + q.height / 2]; })()`));
  51. if (!bx) throw new Error('no ' + sel);
  52. const x = Math.round(bx[0]), y = Math.round(bx[1]);
  53. for (const [type, buttons] of [['mouseMoved', 0], ['mousePressed', 1], ['mouseReleased', 0]]) await p.send('Input.dispatchMouseEvent', { type, x, y, button: 'left', clickCount: 1, buttons });
  54. await sleep(250);
  55. };
  56. const type = async (s) => { for (const ch of s) { await p.send('Input.dispatchKeyEvent', { type: 'keyDown', text: ch, unmodifiedText: ch, key: ch }); await p.send('Input.dispatchKeyEvent', { type: 'keyUp', key: ch }); } await sleep(80); };
  57. const press = async (key) => { const vk = key === 'Tab' ? 9 : 13; await p.send('Input.dispatchKeyEvent', { type: key === 'Tab' ? 'rawKeyDown' : 'keyDown', key, code: key, windowsVirtualKeyCode: vk, ...(key === 'Enter' ? { text: '\r', unmodifiedText: '\r' } : {}) }); await p.send('Input.dispatchKeyEvent', { type: 'keyUp', key, code: key, windowsVirtualKeyCode: vk }); await sleep(60); };
  58. const ready = () => p.waitFor(R(`!!r.querySelector('article > *')`), { timeout: 60000 });
  59. const shot = async (n) => { const { data } = await p.send('Page.captureScreenshot', { format: 'png' }); writeFileSync(join(SHOTS, `table-button-${n}.png`), Buffer.from(data, 'base64')); };
  60. const stored = async (head) => { for (let t = 0; t < 20; t++) { for (const n of (await api('/api/notes')).notes.sort((x, y) => y.edited - x.edited).slice(0, 6)) { const d = await api('/api/notes?id=' + n.id); if (d.text.startsWith(head) && d.text.includes('|')) return { id: n.id, text: d.text }; } await sleep(500); } return null; };
  61. for (const w of [390, 1280]) {
  62. await p.send('Emulation.setDeviceMetricsOverride', { width: w, height: w < 600 ? 844 : 900, deviceScaleFactor: 1, mobile: w < 600 });
  63. for (const variant of ['empty', 'typed', 'header']) {
  64. const L = `${w} ${variant}: `;
  65. const head = `TB${variant}${w}x${Date.now() % 100000}`;
  66. await p.goto(BASE + '/'); await sleep(1500);
  67. await p.click('#newnote');
  68. await p.waitFor(`location.pathname.startsWith('/note/')`, { timeout: 30000 }); await ready(); await sleep(800);
  69. await clickSel('article'); await type(head); await press('Enter'); await press('Enter');
  70. await clickSel('nav button.table');
  71. check(L + 'the Table button makes a table', (await state()).tables === 1);
  72. if (variant === 'typed') { for (const [i, s] of ['h1', 'h2', 'c1', 'c2'].entries()) { if (i) await press('Tab'); await type(s); } }
  73. if (variant === 'header') { await type('H1'); await press('Tab'); await type('H2'); }
  74. await shot(`${w}-${variant}-1-button`);
  75. await clickSel('button.source-switch');
  76. let s = await state();
  77. check(L + 'the source view shows a real pipe table (header row, delimiter row, body row)', s.source && /\n\n\|[^\n]*\|\n\| --- \| --- \|\n\|[^\n]*\|$/.test(s.field), J(s.field));
  78. await clickSel('button.source-switch'); await sleep(500);
  79. s = await state();
  80. check(L + 'back from the source: still ONE table with 2 header cells and 2 body cells', !s.source && s.tables === 1 && s.th === 2 && s.td === 2, J(s));
  81. await shot(`${w}-${variant}-2-back`);
  82. const st = await stored(head);
  83. check(L + 'the stored note holds a real pipe table', !!st && /\|\n\| --- \| --- \|\n\|/.test(st.text), J(st));
  84. if (!st) continue;
  85. await p.goto(BASE + '/'); await sleep(1200);
  86. await p.click(`#notes a[href="/note/${st.id}"]`);
  87. await p.waitFor(`location.pathname === '/note/${st.id}'`, { timeout: 30000 }); await ready(); await sleep(1200);
  88. s = await state();
  89. check(L + 'opened fresh from the list: still a table', s.tables === 1 && s.th === 2 && s.td === 2, J(s));
  90. await p.send('Page.reload'); await sleep(1500); await ready(); await sleep(1500);
  91. s = await state();
  92. check(L + 'after a full reload: still a table, and the Markdown is unchanged', s.tables === 1 && s.field === st.text, J(s));
  93. await shot(`${w}-${variant}-3-reload`);
  94. }
  95. }
  96. await p.close();
  97. } catch (e) { check('the gate ran to its end', false, String(e && e.stack || e)); }
  98. finally {
  99. try { if (b) await b.close(); } catch {}
  100. try { srv.kill('SIGTERM'); } catch {}
  101. await sleep(1500);
  102. rmSync(W, { recursive: true, force: true });
  103. }
  104. console.log(`${passes} passed, ${failures} failed`);
  105. process.exit(failures ? 1 : 0);

Branches

Latest commits

  • c49ce093|||PR WIP remove notes polling and use framework reachabilityAtlas
  • c028ac61Merge branch 'notes-pr7-kunibert' into mainAtlas
  • 9cc92bdfKeep conflict and history fixes while awaiting queued save supportAtlas
  • a5c27cb6Allow real edits back to earlier text and honor configured identAtlas
  • 15c46ced|||PR Preserve note edits, conflict bases and visible historyAtlas
  • 4c6e0bf6Merge branch 'notes13-day61' into mainAtlas
  • eb51864f|||PR Back/Forward via navigate, server drafts, Hybriel day61Atlas
  • 3537cf7eMerge branch 'vendor-day59' into mainAtlas
  • c13d188b|||PR Vendor Hybriel day59Atlas
  • 24c95433Merge branch 'notes17-ghost-note' into mainAtlas
  • ae1075b2Preserve rejected drafts during note ID adoptionAtlas
  • 383cce23|||PR Prevent saved local edits from restoring deleted notesAtlas
  • 99ca1cf6Merge branch 'vendor-day56' into mainAtlas
  • 649cef37|||PR Vendor Hybriel day56Atlas
  • aadd0abcMerge branch 'hl-standard-2' into mainAtlas
  • 52ffac9f|||PR Keyboard and reload checks for the notes gate (HL-STANDARD F21, F5)Atlas
  • 617ee8c0Merge branch 'hl-standard' into mainAtlas
  • 452458ee|||PR Type the function parameters of notes' own .hl files (HL-STANDARD L10)Atlas
  • 23758cd6Re-vendor complete Hybriel plugins and runtime to day44mre
  • 5d7cc700Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre