gitoria

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchmain8342cd28Merge branch 'notes9-no-poll' into mainAtlasmain/tests/waiting-hybriel-390.mjs

8.7 KB

  1. // WAITING on hybriel#390: queue replacement remains a framework gap; outside GATES.
  2. // Always-on checks for notes PR #7 findings 1–3. Synthetic storage and own headless Chrome.
  3. import { spawn } from 'node:child_process';
  4. import { mkdirSync, rmSync, writeFileSync, existsSync } from 'node:fs';
  5. import { resolve, join } from 'node:path';
  6. import { fileURLToPath } from 'node:url';
  7. import { launchBrowser, sleep } from './cdp.mjs';
  8. import { startIdent } from './identkit.mjs';
  9. const app = resolve(fileURLToPath(new URL('..', import.meta.url)));
  10. 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')));
  11. const scratch = join(app, '.scratch/pr8-queue-waiting');
  12. const port = Number(process.env.NOTES_GATE_PORT || 8800);
  13. const identPort = Number(process.env.NOTES_GATE_IDENT_PORT || 8801);
  14. const base = `http://notes.test:${port}`;
  15. const api = `http://127.0.0.1:${port}`;
  16. 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}`;
  17. rmSync(scratch, { recursive: true, force: true });
  18. mkdirSync(scratch, { recursive: true });
  19. let ident, server, browser, log = '', failures = 0, passes = 0;
  20. const check = (name, ok, detail) => { console.log((ok ? 'ok ' : 'FAIL ') + name + ' ' + JSON.stringify(detail)); ok ? passes++ : failures++; };
  21. try {
  22. ident = await startIdent({ identDir, workDir: join(scratch, 'ident'), port: identPort });
  23. const alice = await ident.signIn('[email protected]');
  24. const registered = await ident.registerApp(alice, 'PR7 regressions', [base]);
  25. server = spawn(join(app, 'bin/hybriel'), ['project.hl'], {
  26. 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 },
  27. stdio: ['ignore', 'pipe', 'pipe'],
  28. });
  29. server.stdout.on('data', d => log += d); server.stderr.on('data', d => log += d);
  30. let up = false;
  31. for (const end = Date.now() + 180000; Date.now() < end && !up;) {
  32. try { up = (await fetch(api + '/')).ok; } catch {}
  33. if (!up) await sleep(250);
  34. }
  35. if (!up) throw new Error('server did not start: ' + log);
  36. const code = await ident.selectorCode(alice, registered, base);
  37. const login = await fetch(api + '/login/callback?ident_code=' + encodeURIComponent(code), { redirect: 'manual' });
  38. const cookie = login.headers.get('set-cookie')?.split(';')[0];
  39. if (login.status !== 302 || !cookie) throw new Error('login failed');
  40. const save = async (text, fields = {}) => {
  41. 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 }) });
  42. const value = await res.json();
  43. if (res.status !== 200 || !value.id) throw new Error('save failed: ' + JSON.stringify(value));
  44. return value;
  45. };
  46. const original = await save('Original note', { at: Date.now() - 10000 });
  47. const other = await save('Other note');
  48. browser = await launchBrowser({ debugPortRange: [8803, 8810] });
  49. const page = await browser.newPage();
  50. await page.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 900, deviceScaleFactor: 1, mobile: false });
  51. await page.send('Network.enable');
  52. await page.send('Network.setCookie', { name: 'notessid', value: cookie.slice('notessid='.length), url: base });
  53. const ready = async () => page.waitFor('window.__hl?.socket?.readyState === 1 && !window.__hl.navigating', { timeout: 120000 });
  54. 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 });
  55. const text = () => page.evaluate(`document.querySelector('#notetext input[name=text]')?.value`);
  56. const replaceText = async (value) => {
  57. await page.waitFor(`!!document.querySelector('#notetext md-editor article > *')`, { timeout: 30000 });
  58. await page.click('#notetext button.source-switch');
  59. await page.waitFor(`document.querySelector('#notetext textarea').getBoundingClientRect().width > 0`);
  60. await page.click('#notetext textarea');
  61. await page.send('Input.dispatchKeyEvent', { type: 'rawKeyDown', key: 'a', code: 'KeyA', windowsVirtualKeyCode: 65, modifiers: 2 });
  62. await page.send('Input.dispatchKeyEvent', { type: 'keyUp', key: 'a', code: 'KeyA', windowsVirtualKeyCode: 65, modifiers: 2 });
  63. await page.send('Input.insertText', { text: value });
  64. };
  65. const serverNote = async (id) => (await fetch(api + '/api/notes?id=' + id, { headers: { cookie } })).json();
  66. const serverList = async () => (await (await fetch(api + '/api/notes', { headers: { cookie } })).json()).notes.filter(n => !n.gone);
  67. const face = async (event, payload) => {
  68. const res = await fetch(api + '/__hl/emit', { method: 'POST', headers: { cookie, 'content-type': 'application/json' }, body: JSON.stringify({ t: 'emit', i: 1, event, payload }) });
  69. if (!res.ok) throw new Error('face ' + res.status);
  70. return res.json();
  71. };
  72. const offline = async (value) => {
  73. await page.setOffline(value);
  74. for (const target of (await browser.conn.send('Target.getTargets')).targetInfos.filter(t => t.type === 'service_worker')) {
  75. const { sessionId } = await browser.conn.send('Target.attachToTarget', { targetId: target.targetId, flatten: true });
  76. await browser.conn.send('Network.enable', {}, sessionId);
  77. await browser.conn.send('Network.emulateNetworkConditions', { offline: value, latency: 0, downloadThroughput: -1, uploadThroughput: -1 }, sessionId);
  78. }
  79. };
  80. 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')); };
  81. const size = 190000, strokes = 32;
  82. const large = await save('L'.repeat(size));
  83. await page.goto(base + '/note/' + large.id); await ready();
  84. await page.waitFor('!!navigator.serviceWorker.controller', { timeout: 120000 });
  85. await page.goto(base + '/note/' + large.id); await ready();
  86. await offline(true);
  87. await page.goto(base + '/note/' + large.id, { timeout: 120000 });
  88. await page.waitFor('window.__hl?.page?.instance.__hlOnline === false && document.querySelector("#notetext input[name=text]")?.value.length === 190000', { timeout: 30000 });
  89. await page.waitFor('!!document.querySelector("#notetext md-editor article > *")', { timeout: 30000 });
  90. await page.click('#notetext button.source-switch');
  91. await page.click('#notetext textarea');
  92. await page.send('Input.dispatchKeyEvent', { type: 'rawKeyDown', key: 'End', code: 'End', windowsVirtualKeyCode: 35, modifiers: 2 });
  93. await page.send('Input.dispatchKeyEvent', { type: 'keyUp', key: 'End', code: 'End', windowsVirtualKeyCode: 35, modifiers: 2 });
  94. let peak = 0;
  95. for (let i = 0; i < strokes; i++) {
  96. await page.send('Input.dispatchKeyEvent', { type: 'keyDown', key: 'x', text: 'x', unmodifiedText: 'x' });
  97. await page.send('Input.dispatchKeyEvent', { type: 'keyUp', key: 'x' });
  98. peak = Math.max(peak, await page.evaluate('window.__hl.page.instance.__hlQueue.length'));
  99. }
  100. await sleep(1400);
  101. const queue = await page.evaluate(`({ count: window.__hl.page.instance.__hlQueue.length, characters: window.__hl.page.instance.__hlQueue.reduce((n,q) => n + (q.text?.length || 0), 0), latest: window.__hl.page.instance.__hlQueue.some(q => q.text?.length === 190032 && q.text.endsWith('x'.repeat(32))) })`);
  102. console.log('WAITING #390 queue bound: ' + JSON.stringify({ ...queue, peak, strokes, initialSize: size }));
  103. await page.goto(base + '/note/' + large.id, { timeout: 120000 });
  104. await page.waitFor('!!window.__hl?.page?.instance && !!document.querySelector("#notetext input[name=text]")', { timeout: 30000 });
  105. check('round2: latest full input survives an immediate offline document reload', await page.evaluate('document.querySelector("#notetext input[name=text]").value.length === 190032 && document.querySelector("#notetext input[name=text]").value.endsWith("x".repeat(32))'), { length: (await text())?.length });
  106. } catch (e) { failures++; console.log('FAIL crashed ' + e.stack + '\n' + log.slice(-2000)); }
  107. finally {
  108. if (browser) await browser.close();
  109. if (server) { server.kill('SIGTERM'); await new Promise(r => { if (server.exitCode !== null || server.signalCode !== null) return r(); server.once('exit', r); }); }
  110. if (ident) await ident.stop();
  111. console.log(`${passes} passed, ${failures} failed`);
  112. process.exitCode = failures ? 1 : 0;
  113. }

Branches

Latest commits

  • 8342cd28Merge branch 'notes9-no-poll' into mainAtlas
  • 1f0457a5|||PR make provisional rejected-draft setup deterministicAtlas
  • 996768bf|||PR WIP sequence note creation before provisional-id adoptionAtlas
  • 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