notes
All repositories: gitoria
8.9 KB
// 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,// after Markdown source and back, after a full reload and after editing a cell (written back without an invented | --- | line). Real clicks and keys// 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.// node tests/dashboard-table.mjs [port=8721] [chrome-from-to=8735-8739] [backup.tgz]// N5_APP=<dir> runs another code tree (the old one, to see this gate fail). Kills only what it started; the copy is deleted.import { spawn, execFileSync } from 'node:child_process';import { writeFileSync, mkdirSync, rmSync, existsSync, readdirSync } from 'node:fs';import { createHash, randomBytes } from 'node:crypto';import { join, resolve, dirname } from 'node:path';import { fileURLToPath } from 'node:url';import { launchBrowser } from './cdp.mjs';const HERE = dirname(fileURLToPath(import.meta.url));const APP = resolve(process.env.N5_APP || join(HERE, '..'));const [portArg, chromeArg, tgzArg] = process.argv.slice(2);const PORT = Number(portArg || 8721);const [CH_FROM, CH_TO] = (chromeArg || '8735-8739').split('-').map(Number);const BK = '/media/STORAGE/deploy-backups/notes.worldapi.org';const tgz = tgzArg || join(BK, readdirSync(BK).filter(f => f.endsWith('.tgz')).sort().pop());const BASE = `http://notes.test:${PORT}`, API = `http://127.0.0.1:${PORT}`;const W = join(HERE, '..', '.scratch/dashboard-table');const SHOTS = join(HERE, '..', '.scratch');if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';process.env.HL_CHROME_ARGS = `--host-resolver-rules=MAP notes.test 127.0.0.1|--unsafely-treat-insecure-origin-as-secure=${BASE}`;rmSync(W, { recursive: true, force: true });mkdirSync(join(W, 'data'), { recursive: true }); mkdirSync(join(W, 'sessions'), { recursive: true });execFileSync('tar', ['-xzf', resolve(tgz), '-C', join(W, 'data'), 'storage/mpackdb']);const sid = randomBytes(16).toString('hex'), now = Date.now();writeFileSync(join(W, 'sessions', createHash('sha256').update(sid).digest('hex')),JSON.stringify({ created: now, data: { tag: 'tb' }, handled: [], id: sid, seen: now, user: { id: '0muh6o5a3kkd' } }), { mode: 0o600 });let failures = 0, passes = 0;const check = (label, ok, detail = '') => { console.log(`${ok ? 'ok ' : 'FAIL'} ${label}${ok ? '' : ' — ' + detail}`); if (ok) passes++; else failures++; };const sleep = (ms) => new Promise(r => setTimeout(r, ms));const J = JSON.stringify;let log = '';const srv = spawn(join(APP, 'bin/hybriel'), ['project.hl'], { cwd: APP, stdio: ['ignore', 'pipe', 'pipe'],env: { ...process.env, NOTES_PORT: String(PORT), NOTES_PUBLIC_URL: BASE, NOTES_STORAGE: join(W, 'data/storage/mpackdb'),NOTES_SESSIONS: join(W, 'sessions') + '/', NOTES_WATCH: '0', IDENT_URL: 'http://ident.test', IDENT_API_KEY: 'pk', IDENT_API_SECRET: 'sk' } });srv.stdout.on('data', d => log += d); srv.stderr.on('data', d => log += d);const api = async (p) => (await fetch(API + p, { headers: { cookie: 'notessid=' + sid } })).json();const R = (e) => `(() => { const r = document.querySelector('#notetext md-editor'); if (!r) return null; return (${e}); })()`;let b = null;try {for (let i = 0; i < 480; i++) { try { if ((await fetch(API + '/')).ok) break; } catch {} await sleep(250); }b = await launchBrowser({ debugPortRange: [CH_FROM, CH_TO] });const p = await b.newPage();await p.send('Network.enable');await p.send('Network.setCookie', { name: 'notessid', value: sid, url: BASE + '/' });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 })`));const clickSel = async (sel) => {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]; })()`));if (!bx) throw new Error('no ' + sel);const x = Math.round(bx[0]), y = Math.round(bx[1]);for (const [type, buttons] of [['mouseMoved', 0], ['mousePressed', 1], ['mouseReleased', 0]]) await p.send('Input.dispatchMouseEvent', { type, x, y, button: 'left', clickCount: 1, buttons });await sleep(250);};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); };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); };const ready = () => p.waitFor(R(`!!r.querySelector('article > *')`), { timeout: 60000 });const shot = async (n) => { const { data } = await p.send('Page.captureScreenshot', { format: 'png' }); writeFileSync(join(SHOTS, `dashboard-table-${n}.png`), Buffer.from(data, 'base64')); };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; };const DASH = 'DASHBOARD\n\n| name | device | local | tailscale |\n| termuplex | loreana | |';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();const shape = (s) => s.tables === 1 && s.th === 4 && s.td === 4;for (const w of [390, 1280]) {await p.send('Emulation.setDeviceMetricsOverride', { width: w, height: w < 600 ? 844 : 900, deviceScaleFactor: 1, mobile: w < 600 });const L = `${w}: `;const text = DASH + ' '.repeat(0) + '\n\nid' + w + 'x' + (Date.now() % 100000);const note = await post({ op: 'save', id: '', local: 'dash' + w, text, base: 0, at: Date.now() });await p.goto(BASE + '/'); await sleep(1200);await p.click(`#notes a[href="/note/${note.id}"]`);await p.waitFor(`location.pathname === '/note/${note.id}'`, { timeout: 30000 }); await ready(); await sleep(1200);let s = await state();check(L + 'DASHBOARD note (pipe rows, no | --- | line): shown as ONE table of 4 columns, 2 rows', shape(s), J(s));check(L + 'the Markdown is untouched by just opening it (no | --- | invented)', s.field === text, J(s.field));await shot(`dash-${w}-1-open`);await clickSel('button.source-switch'); s = await state();check(L + 'source view shows the pipe rows as written', s.source && s.field === text, J(s));await clickSel('button.source-switch'); await sleep(500); s = await state();check(L + 'source and back: still the table', !s.source && shape(s) && s.field === text, J(s));await shot(`dash-${w}-2-back`);await p.send('Page.reload'); await sleep(1500); await ready(); await sleep(1500); s = await state();check(L + 'after a full reload: still the table', shape(s) && s.field === text, J(s));// edit a cell with real keys: the table is written back without a | --- | lineconst 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]; })()`));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 });await type('Z'); await sleep(300); s = await state();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));await sleep(3500);await p.send('Page.reload'); await sleep(1500); await ready(); await sleep(1500); s = await state();check(L + 'edited and reloaded: still the table with the edit', shape(s) && s.field.includes('Z'), J(s));await shot(`dash-${w}-3-edited`);}await p.close();} catch (e) { check('the gate ran to its end', false, String(e && e.stack || e)); }finally {try { if (b) await b.close(); } catch {}try { srv.kill('SIGTERM'); } catch {}await sleep(1500);rmSync(W, { recursive: true, force: true });}console.log(`${passes} passed, ${failures} failed`);process.exit(failures ? 1 : 0);
Branches
Latest commits
- 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
- 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