gitoria

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit98bd6a9898bd6a98N5b: pipe rows without a delimiter row are a table (MdEditor ad4e929, plain copy); gate tests/dashboard-table.mjs; reportmre98bd6a98/tests/dashboard-table.mjs

8.9 KB

  1. // tests/dashboard-table.mjs (notes#5, his "Yes"): his DASHBOARD note (a header row and a row of pipes, NO | --- | line) is a table after opening it,
  2. // after Markdown source and back, after a full reload and after editing a cell (written back without an invented | --- | line). Real clicks and keys
  3. // in headless Chrome at 390 and 1280 on a COPY of the newest deploy backup (a creator session written into the copy). Fails on main dbf9331.
  4. // node tests/dashboard-table.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/dashboard-table');
  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, `dashboard-table-${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. const DASH = 'DASHBOARD\n\n| name | device | local | tailscale |\n| termuplex | loreana | |';
  62. const post = async (o) => (await fetch(API + '/api/notes', { method: 'POST', headers: { cookie: 'notessid=' + sid, 'content-type': 'application/json', origin: BASE }, body: J(o) })).json();
  63. const shape = (s) => s.tables === 1 && s.th === 4 && s.td === 4;
  64. for (const w of [390, 1280]) {
  65. await p.send('Emulation.setDeviceMetricsOverride', { width: w, height: w < 600 ? 844 : 900, deviceScaleFactor: 1, mobile: w < 600 });
  66. const L = `${w}: `;
  67. const text = DASH + ' '.repeat(0) + '\n\nid' + w + 'x' + (Date.now() % 100000);
  68. const note = await post({ op: 'save', id: '', local: 'dash' + w, text, base: 0, at: Date.now() });
  69. await p.goto(BASE + '/'); await sleep(1200);
  70. await p.click(`#notes a[href="/note/${note.id}"]`);
  71. await p.waitFor(`location.pathname === '/note/${note.id}'`, { timeout: 30000 }); await ready(); await sleep(1200);
  72. let s = await state();
  73. check(L + 'DASHBOARD note (pipe rows, no | --- | line): shown as ONE table of 4 columns, 2 rows', shape(s), J(s));
  74. check(L + 'the Markdown is untouched by just opening it (no | --- | invented)', s.field === text, J(s.field));
  75. await shot(`dash-${w}-1-open`);
  76. await clickSel('button.source-switch'); s = await state();
  77. check(L + 'source view shows the pipe rows as written', s.source && s.field === text, J(s));
  78. await clickSel('button.source-switch'); await sleep(500); s = await state();
  79. check(L + 'source and back: still the table', !s.source && shape(s) && s.field === text, J(s));
  80. await shot(`dash-${w}-2-back`);
  81. await p.send('Page.reload'); await sleep(1500); await ready(); await sleep(1500); s = await state();
  82. check(L + 'after a full reload: still the table', shape(s) && s.field === text, J(s));
  83. // edit a cell with real keys: the table is written back without a | --- | line
  84. const tdBox = await p.evaluate(R(`(() => { const e = r.querySelectorAll('article td')[1]; e.scrollIntoView({ block: 'center' }); const q = e.getBoundingClientRect(); return [q.left + q.width / 2, q.top + q.height / 2]; })()`));
  85. for (const [type, buttons] of [['mouseMoved', 0], ['mousePressed', 1], ['mouseReleased', 0]]) await p.send('Input.dispatchMouseEvent', { type, x: Math.round(tdBox[0]), y: Math.round(tdBox[1]), button: 'left', clickCount: 1, buttons });
  86. await type('Z'); await sleep(300); s = await state();
  87. check(L + 'a cell edited: the written Markdown has no invented | --- | line and holds the edit', !/\| ?-{3,}/.test(s.field) && s.field.includes('Z') && s.field.split('\n').filter(l => l.startsWith('|')).length === 2, J(s.field));
  88. await sleep(3500);
  89. await p.send('Page.reload'); await sleep(1500); await ready(); await sleep(1500); s = await state();
  90. check(L + 'edited and reloaded: still the table with the edit', shape(s) && s.field.includes('Z'), J(s));
  91. await shot(`dash-${w}-3-edited`);
  92. }
  93. await p.close();
  94. } catch (e) { check('the gate ran to its end', false, String(e && e.stack || e)); }
  95. finally {
  96. try { if (b) await b.close(); } catch {}
  97. try { srv.kill('SIGTERM'); } catch {}
  98. await sleep(1500);
  99. rmSync(W, { recursive: true, force: true });
  100. }
  101. console.log(`${passes} passed, ${failures} failed`);
  102. process.exit(failures ? 1 : 0);

Branches

Latest commits

  • 98bd6a98N5b: pipe rows without a delimiter row are a table (MdEditor ad4e929, plain copy); gate tests/dashboard-table.mjs; reportmre
  • dbf93319N5 report: components gate rerun 613 passed, 0 failedmre
  • 3a8bc0d2N5: empty Table-button table is written as a real pipe table (MdEditor 4bd1112, plain copy); gate tests/table-button.mjs; reportmre
  • c16bd443N5: step 1 report (tables pass locally; his DASHBOARD note has no delimiter row)mre
  • 6091320anotes: MdEditor 7437e32 (surface drawn at once when the page is claimed); gate measures claim-to-text on 5 note loads at 1280 and 390mre
  • 0aa9277enotes: move each component's styles into its own Style block (shell and header selector in main.hl, list, editor frame and delete question in notes.hl); styles.hl keeps the theme inherit, the accent and the message colour; .gitignore ignores a bin symlink too; tests/shots.mjs for the pixel comparemre
  • 9ba01de3notes: write the standby service out in full so the boot gate can read the main servicemre
  • 98cab40anotes: standby service on its port plus 10 and a deploy that hands over through it without a gapmre
  • 1fadb473notes gate: the editor table now has 1 px cell lines from the notes thememre
  • 8762115cnotes: take the components e54f83a (paste as Markdown, text typed before the editor is built is kept, Table button); table lines come from the notes thememre
  • ac23e194ident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
  • 2804f0d3Merge branch 'iw-ident-widget'mre
  • 52d8d242notes: e2e script checks Log out and the selector in the header instead of the user menumre
  • e5abf7b7notes header: the selector alone top right plus Log out as before the theme missions; the user icon is gonemre
  • a2e343aeident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
  • 7a889b82notes: MdEditor with the Table button, typed pipe rows and the theme's table look (components mt-tables); a table note is named by its header words; gate checks that fail on mainmre
  • b96c7f70theme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
  • 6140e6a0sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • cb7e6469deploy: security gate (tests/security.mjs)mre
  • 774bf34bnotes security: CSRF guard on /api/notes, new session at login, Secure cookie, uploadMax 0, login rate limit, nosniff, face payload check; tests/security.mjs; SN reportmre