ident
All repositories: gitoria
8.9 KB
// tests/docs.mjs — GATE ident#45: /docs shows docs/IDENT.md, the only source of the text, in ident's shell.// 1. signed out: GET /docs is 200 and carries every heading of docs/IDENT.md; in headless Chrome at 390 px the page renders in// the shell, every heading is there, nothing makes the page wider than the screen (code blocks scroll inside themselves), the// console is clean.// 2. signed in (real sign-in with the mail sink): the main menu has ONE "Docs" entry; a real click on it opens /docs; same checks// at 390 and at 1280 px.// On code without the page the first check fails (/docs is the 404 page). Own server, own storage, real headless Chrome on loreana.// Shots go to DOCS_GATE_SHOTS when set. Run: node tests/docs.mjsimport { spawn } from 'node:child_process';import { rmSync, mkdirSync, writeFileSync, existsSync, readFileSync } from 'node:fs';import { dirname, join, resolve } from 'node:path';import { fileURLToPath } from 'node:url';import { launchBrowser } from './cdp.mjs';if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';const APP = resolve(dirname(fileURLToPath(import.meta.url)), '..');const G = join(APP, '.scratch/docs-gate');rmSync(G, { recursive: true, force: true });mkdirSync(join(G, 'sess'), { recursive: true });const PORT = Number(process.env.DOCS_GATE_PORT || 8782), BASE = `http://127.0.0.1:${PORT}`, SINK = join(G, 'mail.txt');const SHOTS = process.env.DOCS_GATE_SHOTS || '';if (SHOTS) mkdirSync(SHOTS, { recursive: true });const sleep = (ms) => new Promise((r) => setTimeout(r, ms));let passed = 0, failed = 0;const check = (n, ok, d = '') => { if (ok) { passed++; console.log('ok ' + n); } else { failed++; console.log('FAIL ' + n + (d ? ' — ' + d : '')); } };// the headings of the source, as a reader sees them (Markdown marks removed)const plain = (s) => s.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1').replace(/[*`_]/g, '').replace(/\s+/g, ' ').trim();const headings = readFileSync(join(APP, 'docs/IDENT.md'), 'utf8').split('\n').filter((l) => /^#{1,6} /.test(l)).map((l) => plain(l.replace(/^#+ /, '')));let log = '';const srv = spawn(join(APP, 'bin/hybriel'), ['project.hl'], { cwd: APP, env: { ...process.env, SMTP_HOST: '', IDENT_PORT: String(PORT), IDENT_STORAGE: join(G, 'store'), IDENT_SESSIONS: join(G, 'sess'), IDENT_MAIL_SINK: SINK, IDENT_IP_LIMIT: '1000', IDENT_IP_DAY_LIMIT: '1000', IDENT_WATCH: '0' }, stdio: ['ignore', 'pipe', 'pipe'] });srv.stdout.on('data', (d) => log += d); srv.stderr.on('data', (d) => log += d);let browser;async function finish() {try { await browser.close(); } catch {}try { process.kill(srv.pid); } catch {}writeFileSync(join(G, 'server.log'), log);console.log(`\n${passed} passed, ${failed} failed`);process.exit(failed ? 1 : 0);}const viewport = async (p, w, h) => { await p.send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: 1, mobile: w < 600 }); await sleep(300); };const shot = async (p, name, full = false) => {if (!SHOTS) return;const opts = { format: 'png' };if (full) { const m = await p.send('Page.getLayoutMetrics'); opts.captureBeyondViewport = true; opts.clip = { x: 0, y: 0, width: m.cssContentSize.width, height: Math.min(m.cssContentSize.height, 6000), scale: 1 }; }const { data } = await p.send('Page.captureScreenshot', opts); writeFileSync(join(SHOTS, name + '.png'), Buffer.from(data, 'base64'));};// what a reader of the page sees: the headings, the width, the code blocksconst pageState = (p) => p.evaluate(`(() => {const hs = [...document.querySelectorAll('main docs-page h1, main docs-page h2, main docs-page h3, main docs-page h4')].map((h) => h.textContent.replace(/\\s+/g, ' ').trim());const pres = [...document.querySelectorAll('docs-page pre')];const preBad = pres.filter((x) => { const r = x.getBoundingClientRect(); return r.right > window.innerWidth + 1 || r.left < -1 || getComputedStyle(x).overflowX !== 'auto'; }).length;return { hs, pres: pres.length, preBad, sw: document.documentElement.scrollWidth, iw: window.innerWidth, shell: !!document.querySelector('application-header') };})()`);const pageChecks = async (p, label) => {const s = await pageState(p);const missing = headings.filter((h) => !s.hs.includes(h));check(label + ': renders in the shell (header)', s.shell);check(label + ': every heading of docs/IDENT.md is on the page (' + headings.length + ')', headings.length > 5 && missing.length === 0, 'missing ' + JSON.stringify(missing) + ' page ' + JSON.stringify(s.hs.slice(0, 4)));check(label + ': the code blocks are there and scroll inside themselves', s.pres > 0 && s.preBad === 0, JSON.stringify({ pres: s.pres, bad: s.preBad }));check(label + ': nothing makes the page wider than the screen', s.sw <= s.iw, s.sw + '/' + s.iw);};try {for (let i = 0; i < 480; i++) { try { await fetch(BASE + '/'); break; } catch {} await sleep(250); }// ---- 1. signed out, plain HTTPconst r = await fetch(BASE + '/docs');const html = await r.text();check('GET /docs answers 200 signed out', r.status === 200, String(r.status));const htmlText = html.replace(/<[^>]*>/g, '').replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, "'").replace(/\s+/g, ' ');const notInHtml = headings.filter((h) => !htmlText.includes(h));check('the server HTML carries every heading of docs/IDENT.md', notInHtml.length === 0, JSON.stringify(notInHtml));browser = await launchBrowser({ debugPortRange: (process.env.DOCS_GATE_CHROME || '8783-8786').split('-').map(Number) });const p = await browser.newPage();const connected = () => p.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1');await viewport(p, 390, 844);await p.goto(BASE + '/docs'); await connected(); await sleep(800);await pageChecks(p, 'signed out 390');await shot(p, 'docs-out-390-top');await p.evaluate('document.querySelector("docs-page pre").scrollIntoView()'); await sleep(300);await shot(p, 'docs-out-390-code');check('signed out 390: console clean', p.problems().length === 0, p.dumpConsole());// ---- 2. signed in: the menu's Docs entryconst email = '[email protected]';const code = async () => { for (let i = 0; i < 30; i++) { if (existsSync(SINK)) { const l = readFileSync(SINK, 'utf8').split('\n').filter((x) => x.startsWith(email + ' ')); if (l.length) return l.at(-1).split(' ')[1]; } await sleep(100); } };await viewport(p, 1280, 900);await p.goto(BASE + '/');await p.waitForSelector('#email'); await connected();await p.type('#email', email, { clear: true });await p.click('#sendcode');await p.waitForSelector('#code'); await connected(); await sleep(300);await p.type('#code', await code(), { clear: true });await p.click('#verify');await p.waitForSelector('#menusignoutall'); await connected(); await sleep(500);await shot(p, 'header-in-1280');const entries = await p.evaluate('[...document.querySelectorAll("application-header main-menu a")].map((a) => a.textContent.trim() + " " + a.getAttribute("href"))');check('signed in 1280: the header menu has one Docs entry after Apps (and the Access entry, ident#27)', JSON.stringify(entries) === JSON.stringify(['Identities /', 'Inbox /inbox', 'Apps /apps', 'Access /access', 'Docs /docs']), JSON.stringify(entries));await p.click('application-header main-menu a[href="/docs"]');await p.waitFor('location.pathname === "/docs" && !!document.querySelector("docs-page h1")'); await sleep(800);await pageChecks(p, 'signed in 1280');await shot(p, 'docs-in-1280-top');await p.evaluate('document.querySelector("docs-page pre").scrollIntoView()'); await sleep(300);await shot(p, 'docs-in-1280-code');check('signed in 1280: the Docs entry is marked as the current page', await p.evaluate('(() => { const a = document.querySelector("application-header main-menu a[href=\\"/docs\\"]"); return !!a && (a.getAttribute("aria-current") === "page" || a.matches(".current, .active")); })()'));await viewport(p, 390, 844);await p.goto(BASE + '/docs'); await connected(); await sleep(800);await pageChecks(p, 'signed in 390');await shot(p, 'docs-in-390-top');await shot(p, 'docs-in-390-full', true);// the phone's menu (☰ → the sidebar): the same Docs entryawait p.click('application-header > button.menu-toggle');await p.waitFor('document.querySelector("#sidebar").matches(":popover-open")'); await sleep(400);await shot(p, 'menu-in-390');const side = await p.evaluate('[...document.querySelectorAll("#sidebar main-menu a")].map((a) => a.textContent.trim() + " " + a.getAttribute("href"))');check('signed in 390: the phone menu has one Docs entry after Apps (and the Access entry, ident#27)', JSON.stringify(side) === JSON.stringify(['Identities /', 'Inbox /inbox', 'Apps /apps', 'Access /access', 'Docs /docs']), JSON.stringify(side));check('signed in: console clean', p.problems().length === 0, p.dumpConsole());} catch (e) {check('no exception', false, e.stack || String(e));}await finish();
Branches
Latest commits
- 0f6d1592Merge branch 'f18b-shell-session' into mainIdent
- 19868218|||PR ident#39 shell reads its session member instead of a cross-file emitmre
- 5d1b3fedMerge branch 'v61-day61' into mainIdent
- 83faeb15|||PR ident: vendor Hybriel day61mre
- b2572b34Merge branch 'v59-day59' into mainIdent
- 67cf016d|||PR ident: vendor Hybriel day59mre
- 600c043dMerge branch 'v58-day58' into mainIdent
- 365f8c80|||PR ident: vendor Hybriel day58mre
- 585126e5Merge branch 'f16-setf' into mainIdent
- 953bf03a|||PR ident setF mirror dropped (hybriel#370)mre
- a1419d9cMerge branch 'f15-navigate' into mainIdent
- 3b3e451f|||PR ident#36 navigate to the app instead of location.assignmre
- e36f4516Merge branch 'f14-online' into mainIdent
- 2c5eac91|||PR ident#38 online state without probe timermre
- bf1980f2Merge branch 'v56-day56' into mainIdent
- 62ae0adf|||PR ident: vendor Hybriel day56mre
- 0d18abc4Merge branch 'f13-avatar' into mainIdent
- 2a99730a|||PR ident#37 avatar in hlmre
- fa4ed25bMerge branch 'f11-upsert' into mainIdent
- 8f3d9bc9|||PR ident#42 keyed upsert and removemre