gitoria

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit24c9543324c95433Merge branch 'notes17-ghost-note' into mainAtlas24c95433/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

  • 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
  • 3e07b1cfVendor complete Hybriel day39 plugin sources and librariesmre
  • d7366702Check session cookie flags after login and assert anonymous GET stays cookielessmre
  • 16bc8fd8Re-vendor Hybriel day38b with the mpackdb store-open race fixmre
  • d860dc2dnotes#12: the markup names its own rules instead of hand-written class strings: the selected row is `aria-current="page"` (the list-first theme rule styles it, no class), the delete question is `Style.pAsk` and follows its own `open` attribute (bound to `asking`), the error line is `Style.pMessage` (body once in lib/looks.hl, rule in notes.hl, main.hl and loginfailed.hl). The CSS declarations are the same, only selectors changed (.ask -> p.ask, .ask.open -> p.ask[open], .message -> p.message); the pages look the same (AE 0 at 4 sizes). main.hl's selectorClass in/out stays (login.js reads it).mre
  • 2e7f8664notes#13: the list and back links pass the note key from the loop (emit pick(e, r.key)) instead of writing data-note into the View and reading it back with getAttribute; the two window.history.replaceState calls and the identcode e.target.value read stay (hl:web has no replace-navigation, a bound hidden input is not adopted on a script's change event), see NO13 reportmre
  • 4dc98282notes#15: a deleted note made in this tab leaves the list at once (the delete now removes this tab's edit under every key the row has: local id, server id); gate: browser.mjs notes#15 section, red on the old codemre
  • e4e7402fnotes#11: plain declarations instead of let for variables never reassigned (components/notes.hl 3, lib/jsoncheck.hl 5, lib/util.hl 2, tools/migrate-short-ids.hl 8)mre
  • 27b6a09enotes#8: Style blocks in the nested form (note-list, note-editor, .ask with their children nested, :empty as a nested pseudo-class); the same CSS rules, the pages look the samemre
  • 71a9538bnotes: B27W report, log linemre