notes
All repositories: gitoria
8.4 KB
// tests/table-button.mjs (notes#7 / notes#5 reopened): the Table button's table survives "Markdown source" and back, a save, a fresh open// 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// 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// table was written as nothing). node tests/table-button.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/table-button');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, `table-button-${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; };for (const w of [390, 1280]) {await p.send('Emulation.setDeviceMetricsOverride', { width: w, height: w < 600 ? 844 : 900, deviceScaleFactor: 1, mobile: w < 600 });for (const variant of ['empty', 'typed', 'header']) {const L = `${w} ${variant}: `;const head = `TB${variant}${w}x${Date.now() % 100000}`;await p.goto(BASE + '/'); await sleep(1500);await p.click('#newnote');await p.waitFor(`location.pathname.startsWith('/note/')`, { timeout: 30000 }); await ready(); await sleep(800);await clickSel('article'); await type(head); await press('Enter'); await press('Enter');await clickSel('nav button.table');check(L + 'the Table button makes a table', (await state()).tables === 1);if (variant === 'typed') { for (const [i, s] of ['h1', 'h2', 'c1', 'c2'].entries()) { if (i) await press('Tab'); await type(s); } }if (variant === 'header') { await type('H1'); await press('Tab'); await type('H2'); }await shot(`${w}-${variant}-1-button`);await clickSel('button.source-switch');let s = await state();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));await clickSel('button.source-switch'); await sleep(500);s = await state();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));await shot(`${w}-${variant}-2-back`);const st = await stored(head);check(L + 'the stored note holds a real pipe table', !!st && /\|\n\| --- \| --- \|\n\|/.test(st.text), J(st));if (!st) continue;await p.goto(BASE + '/'); await sleep(1200);await p.click(`#notes a[href="/note/${st.id}"]`);await p.waitFor(`location.pathname === '/note/${st.id}'`, { timeout: 30000 }); await ready(); await sleep(1200);s = await state();check(L + 'opened fresh from the list: still a table', s.tables === 1 && s.th === 2 && s.td === 2, J(s));await p.send('Page.reload'); await sleep(1500); await ready(); await sleep(1500);s = await state();check(L + 'after a full reload: still a table, and the Markdown is unchanged', s.tables === 1 && s.field === st.text, J(s));await shot(`${w}-${variant}-3-reload`);}}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
- hl-standard
- hl-standard-2
- mainmain branch
- notes-pr7-kunibert
- notes13-day61
- notes17-ghost-note
- notes9-no-poll
- vendor-day56
- vendor-day59
- w7
Latest commits
- 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
- 78ba0073notes: an ident access key (Authorization: Bearer idt_…) reads and writes its identity's notes through /api/me and /api/notes; gate tests/ident-access-notes.mjs (ident#27)mre