gitoria

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitc49ce093c49ce093|||PR WIP remove notes polling and use framework reachabilityAtlasc49ce093/tests/proof-notes9.mjs

7.6 KB

  1. // Confirmation in the creator's existing Chrome; one owned tab, closed in finally.
  2. import { spawn } from 'node:child_process';
  3. import { mkdirSync, rmSync, writeFileSync, existsSync } from 'node:fs';
  4. import { resolve, join } from 'node:path';
  5. import { fileURLToPath } from 'node:url';
  6. import { launchBrowser, sleep } from './cdp.mjs';
  7. import { startIdent } from './identkit.mjs';
  8. const app = resolve(fileURLToPath(new URL('..', import.meta.url)));
  9. 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')));
  10. const scratch = join(app, '.scratch/proof');
  11. const port = Number(process.env.NOTES_GATE_PORT || 8800);
  12. const identPort = Number(process.env.NOTES_GATE_IDENT_PORT || 8801);
  13. const base = `http://loreana.tailfd3886.ts.net:${port}`;
  14. const api = `http://127.0.0.1:${port}`;
  15. 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}`;
  16. rmSync(scratch, { recursive: true, force: true });
  17. mkdirSync(scratch, { recursive: true });
  18. let ident, server, browser, log = '', failures = 0, passes = 0;
  19. const check = (name, ok, detail) => { console.log((ok ? 'ok ' : 'FAIL ') + name + ' ' + JSON.stringify(detail)); ok ? passes++ : failures++; };
  20. try {
  21. ident = await startIdent({ identDir, workDir: join(scratch, 'ident'), port: identPort });
  22. const alice = await ident.signIn('[email protected]');
  23. const registered = await ident.registerApp(alice, 'PR7 regressions', [base]);
  24. server = spawn(join(app, 'bin/hybriel'), ['project.hl'], {
  25. 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 },
  26. stdio: ['ignore', 'pipe', 'pipe'],
  27. });
  28. server.stdout.on('data', d => log += d); server.stderr.on('data', d => log += d);
  29. let up = false;
  30. for (const end = Date.now() + 180000; Date.now() < end && !up;) {
  31. try { up = (await fetch(api + '/')).ok; } catch {}
  32. if (!up) await sleep(250);
  33. }
  34. if (!up) throw new Error('server did not start: ' + log);
  35. const code = await ident.selectorCode(alice, registered, base);
  36. const login = await fetch(api + '/login/callback?ident_code=' + encodeURIComponent(code), { redirect: 'manual' });
  37. const cookie = login.headers.get('set-cookie')?.split(';')[0];
  38. if (login.status !== 302 || !cookie) throw new Error('login failed');
  39. const save = async (text, fields = {}) => {
  40. 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(), ...fields }) });
  41. const value = await res.json();
  42. if (res.status !== 200 || !value.id) throw new Error('save failed: ' + JSON.stringify(value));
  43. return value;
  44. };
  45. writeFileSync(join(scratch, 'server.html'), await (await fetch(api + '/', {headers:{cookie}})).text())
  46. console.log('Processes', {ident:ident.proc.pid, server:server.pid})
  47. const original = await save('Original note', { at: Date.now() - 10000 });
  48. const other = await save('Other note');
  49. process.env.HL_CDP_URL = 'http://[::1]:9223'
  50. browser = await launchBrowser({ debugPortRange: [8803, 8810] });
  51. const page = await browser.newPage();
  52. await page.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 900, deviceScaleFactor: 1, mobile: false });
  53. await page.send('Network.enable');
  54. await page.send('Network.setCookie', { name: 'notessid', value: cookie.slice('notessid='.length), url: base });
  55. const ready = async () => page.waitFor('window.__hl?.socket?.readyState === 1 && !window.__hl.navigating', { timeout: 120000 });
  56. const standing = async (path) => page.waitFor(`location.pathname === ${JSON.stringify(path)} && !window.__hl.navigating && window.__hl.page.instance.sel === ${JSON.stringify(path === '/' ? '' : path.slice(6))}`, { timeout: 30000 });
  57. const text = () => page.evaluate(`document.querySelector('#notetext input[name=text]')?.value`);
  58. const replaceText = async (value) => {
  59. await page.waitFor(`!!document.querySelector('#notetext md-editor article > *')`, { timeout: 30000 });
  60. if (!await page.evaluate("!!document.querySelector('#notetext textarea')?.getBoundingClientRect().width")) await page.click('#notetext button.source-switch');
  61. await page.waitFor(`document.querySelector('#notetext textarea').getBoundingClientRect().width > 0`);
  62. await page.click('#notetext textarea');
  63. await page.send('Input.dispatchKeyEvent', { type: 'rawKeyDown', key: 'a', code: 'KeyA', windowsVirtualKeyCode: 65, modifiers: 2 });
  64. await page.send('Input.dispatchKeyEvent', { type: 'keyUp', key: 'a', code: 'KeyA', windowsVirtualKeyCode: 65, modifiers: 2 });
  65. await page.send('Input.insertText', { text: value });
  66. };
  67. const shot = async (name) => { const r = await page.send('Page.captureScreenshot', { format: 'png', captureBeyondViewport: true }); writeFileSync(join(scratch, name + '.png'), Buffer.from(r.data, 'base64')); };
  68. await page.captureWs()
  69. await page.goto(base + '/note/' + original.id); await ready()
  70. for (const [width, height] of [[390,844],[800,1280],[1280,800],[1280,900]]) {
  71. await page.send('Emulation.setDeviceMetricsOverride', {width,height,deviceScaleFactor:1,mobile:width<600})
  72. await replaceText('Typed at ' + width + 'x' + height)
  73. await page.waitFor('window.__hl.page.instance.edits.length === 0', {timeout:30000})
  74. check('typed text saved at ' + width + 'x' + height, await text() === 'Typed at ' + width + 'x' + height)
  75. await shot('proof-' + width + 'x' + height)
  76. }
  77. delete process.env.HL_CDP_URL
  78. const second = await launchBrowser({debugPortRange:[8803,8810]})
  79. try {
  80. const tab = await second.newPage()
  81. await tab.send('Network.enable')
  82. await tab.send('Network.setCookie', {name:'notessid',value:cookie.slice('notessid='.length),url:base})
  83. await tab.goto(base + '/note/' + original.id, {timeout:120000})
  84. await tab.waitFor('window.__hl?.socket?.readyState === 1',{timeout:120000})
  85. await tab.click('#notetext button.source-switch')
  86. await tab.click('#notetext textarea')
  87. await tab.send('Input.dispatchKeyEvent',{type:'rawKeyDown',key:'a',code:'KeyA',windowsVirtualKeyCode:65,modifiers:2})
  88. await tab.send('Input.dispatchKeyEvent',{type:'keyUp',key:'a',code:'KeyA',windowsVirtualKeyCode:65,modifiers:2})
  89. await tab.send('Input.insertText',{text:'Pushed from a second tab'})
  90. await page.waitFor("document.querySelector('#notetext input[name=text]').value === 'Pushed from a second tab'",{timeout:30000})
  91. check('second tab edit arrives by push',true)
  92. } finally { await second.close() }
  93. server.kill('SIGSTOP')
  94. try {
  95. await page.waitFor("document.querySelector('#syncstate').textContent.includes('Offline')", {timeout:90000})
  96. await shot('proof-offline')
  97. check('server stop shows offline note',true)
  98. } finally { server.kill('SIGCONT') }
  99. await page.waitFor("document.querySelector('#syncstate').textContent === ''",{timeout:120000})
  100. check('server recovery clears offline note',true)
  101. } catch (e) { failures++; console.log('FAIL crashed ' + e.stack + '\n' + log.slice(-2000)); }
  102. finally {
  103. if (browser) { for (const p of browser.pages) await p.close(); browser.conn.close(); }
  104. if (server) { server.kill('SIGTERM'); await new Promise(r => { if (server.exitCode !== null || server.signalCode !== null) return r(); server.once('exit', r); }); }
  105. if (ident) await ident.stop();
  106. console.log(`${passes} passed, ${failures} failed`);
  107. process.exitCode = failures ? 1 : 0;
  108. }

Branches

Latest commits

  • c49ce093|||PR WIP remove notes polling and use framework reachabilityAtlas
  • 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