gitoria

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmainc028ac61Merge branch 'notes-pr7-kunibert' into mainAtlasmain/tests/waiting-hybriel-388.mjs

6.7 KB

  1. // WAITING on hybriel#388: the route assertion below is nonblocking.
  2. // Regression: an uncached note URL must select that note when a cached
  3. // document for another note supplies the offline shell. Synthetic data only.
  4. import { spawn } from 'node:child_process';
  5. import { mkdirSync, rmSync, writeFileSync, existsSync } from 'node:fs';
  6. import { resolve, join } from 'node:path';
  7. import { fileURLToPath } from 'node:url';
  8. import { launchBrowser, sleep } from './cdp.mjs';
  9. import { startIdent } from './identkit.mjs';
  10. const app = resolve(fileURLToPath(new URL('..', import.meta.url)));
  11. const identDir = process.env.NOTES_GATE_IDENT_DIR || [resolve(app, '../ident.worldapi.org'), '/media/STORAGE/projects/WorldAPI/ident.worldapi.org'].find(d => existsSync(join(d, 'project.hl')));
  12. const scratch = join(app, '.scratch/pr7-offline-route');
  13. const port = Number(process.env.NOTES_GATE_PORT || 8800);
  14. const identPort = Number(process.env.NOTES_GATE_IDENT_PORT || 8801);
  15. const base = `http://notes.test:${port}`;
  16. const api = `http://127.0.0.1:${port}`;
  17. process.env.HL_CHROME_ARGS = `--host-resolver-rules=MAP *.notes.test 127.0.0.1, MAP notes.test 127.0.0.1|--unsafely-treat-insecure-origin-as-secure=${base}`;
  18. rmSync(scratch, { recursive: true, force: true });
  19. mkdirSync(scratch, { recursive: true });
  20. let ident, server, browser, log = '', failures = 0, passes = 0;
  21. const check = (name, ok, detail) => { console.log((ok ? 'ok ' : 'FAIL ') + name + ' ' + JSON.stringify(detail)); ok ? passes++ : failures++; };
  22. try {
  23. ident = await startIdent({ identDir, workDir: join(scratch, 'ident'), port: identPort });
  24. const alice = await ident.signIn('[email protected]');
  25. const registered = await ident.registerApp(alice, 'offline route regression', [base]);
  26. server = spawn(join(app, 'bin/hybriel'), ['project.hl'], {
  27. cwd: app, env: { ...process.env, NOTES_PORT: String(port), NOTES_STORAGE: join(scratch, 'data'), NOTES_SESSIONS: join(scratch, 'sessions') + '/', NOTES_WATCH: '0', NOTES_PUBLIC_URL: base, IDENT_URL: `http://ident.notes.test:${identPort}`, IDENT_EXCHANGE_URL: ident.base, IDENT_API_KEY: registered.key, IDENT_API_SECRET: registered.secret },
  28. stdio: ['ignore', 'pipe', 'pipe'],
  29. });
  30. server.stdout.on('data', d => log += d); server.stderr.on('data', d => log += d);
  31. let up = false;
  32. for (const end = Date.now() + 180000; Date.now() < end && !up;) {
  33. try { up = (await fetch(api + '/')).ok; } catch {}
  34. if (!up) await sleep(250);
  35. }
  36. if (!up) throw new Error('server did not start: ' + log);
  37. const code = await ident.selectorCode(alice, registered, base);
  38. const login = await fetch(api + '/login/callback?ident_code=' + encodeURIComponent(code), { redirect: 'manual' });
  39. const cookie = login.headers.get('set-cookie')?.split(';')[0];
  40. if (login.status !== 302 || !cookie) throw new Error('login failed');
  41. const save = async (text) => {
  42. const res = await fetch(api + '/api/notes', { method: 'POST', headers: { cookie, 'content-type': 'application/json' }, body: JSON.stringify({ op: 'save', id: '', local: '', text, base: 0, at: Date.now() }) });
  43. const value = await res.json();
  44. if (res.status !== 200 || !value.id) throw new Error('save failed: ' + JSON.stringify(value));
  45. return value;
  46. };
  47. const a = await save('Stand-in note A');
  48. const b = await save('Requested note B');
  49. browser = await launchBrowser({ debugPortRange: [8803, 8810] });
  50. const page = await browser.newPage();
  51. await page.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 1, mobile: true });
  52. await page.send('Network.enable');
  53. await page.send('Network.setCookie', { name: 'notessid', value: cookie.slice('notessid='.length), url: base });
  54. const aPath = '/note/' + a.id, bPath = '/note/' + b.id;
  55. await page.goto(base + aPath, { timeout: 120000 });
  56. await page.waitFor('window.__hl?.socket?.readyState === 1 && !!navigator.serviceWorker.controller', { timeout: 120000 });
  57. // A second real load passes through the controlling worker and caches A.
  58. await page.goto(base + aPath, { timeout: 120000 });
  59. await page.waitFor('window.__hl?.socket?.readyState === 1 && !!document.querySelector("#notetext input[name=text]")', { timeout: 120000 });
  60. const docs = await page.evaluate(`(async () => { const paths = []; for (const name of await caches.keys()) { const cache = await caches.open(name); for (const req of await cache.keys()) { const res = await cache.match(req); if ((res.headers.get('content-type') || '').includes('text/html')) paths.push(new URL(req.url).pathname); } } return paths; })()`);
  61. check('setup: A is cached; B has never been loaded or cached', docs.includes(aPath) && !docs.includes(bPath), { aPath, bPath, docs });
  62. await page.setOffline(true);
  63. const { targetInfos } = await browser.conn.send('Target.getTargets');
  64. for (const target of targetInfos.filter(t => t.type === 'service_worker')) {
  65. const { sessionId } = await browser.conn.send('Target.attachToTarget', { targetId: target.targetId, flatten: true });
  66. await browser.conn.send('Network.enable', {}, sessionId);
  67. await browser.conn.send('Network.emulateNetworkConditions', { offline: true, latency: 0, downloadThroughput: -1, uploadThroughput: -1 }, sessionId);
  68. }
  69. await page.goto(base + bPath, { timeout: 120000 });
  70. await page.waitFor('!!window.__hl?.page?.instance && !!document.querySelector("#notetext input[name=text]")', { timeout: 120000 });
  71. await page.waitFor(`window.__hl.seed.page.params.id === ${JSON.stringify(b.id)}`, { timeout: 30000 });
  72. const state = await page.evaluate(`(() => { const p = window.__hl.page.instance; return { path: location.pathname, id: p.id, route: p.route, sel: p.sel, text: document.querySelector('#notetext input[name=text]').value, current: document.querySelector('#notes a[aria-current=page]')?.getAttribute('href'), cached: window.__hl.seed.cached }; })()`);
  73. const followsRequested = state.path === bPath && state.sel === b.id && state.current === bPath && state.text === 'Requested note B';
  74. console.log((followsRequested ? 'ok ' : 'WAITING #388 ') + 'offline stand-in must follow the requested note: ' + JSON.stringify(state));
  75. writeFileSync(join(scratch, 'result.json'), JSON.stringify({ aPath, bPath, docs, state }, null, 2));
  76. const shot = await page.send('Page.captureScreenshot', { format: 'png', captureBeyondViewport: true });
  77. writeFileSync(join(scratch, 'offline-B.png'), Buffer.from(shot.data, 'base64'));
  78. } catch (e) { failures++; console.log('FAIL crashed ' + e.stack); }
  79. finally {
  80. if (browser) await browser.close();
  81. if (server) { server.kill('SIGTERM'); await new Promise(r => { if (server.exitCode !== null || server.signalCode !== null) return r(); server.once('exit', r); }); }
  82. if (ident) await ident.stop();
  83. console.log(`${passes} passed, ${failures} failed`);
  84. process.exitCode = failures ? 1 : 0;
  85. }

Branches

Latest commits

  • c028ac61Merge branch 'notes-pr7-kunibert' into mainAtlas
  • 9cc92bdfKeep conflict and history fixes while awaiting queued save supportAtlas
  • 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