gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commita69b27f9a69b27f9docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mrea69b27f9/tests/reminders-e2e.mjs

9.6 KB

  1. // tests/reminders-e2e.mjs — calendar mission 009: the reminders card and the push button in lisbeth's real Chrome, at 390 and 1280 px,
  2. // real clicks; run it against the OLD tree and the NEW tree (PREFIX names the shots). ONE tab reused, under `timeout 600 flock -o <lisbeth.lock>`.
  3. // REAL_PORT=8793 REAL_SCRATCH=<dir of tests/push-real-app.mjs> OUT=<evidence dir> PREFIX=new node tests/reminders-e2e.mjs
  4. // needs: tests/push-real-app.mjs running (outside the lock) and ssh -f -N -R <port>:127.0.0.1:<port> lisbeth
  5. // 1 sign in with a fresh ident code, grant notifications, tap "Turn on notifications" (subscribes through FCM) 2 an event 2.5 min ahead,
  6. // reminders 1 min before + 1 day before at 20:00, and an all-day event tomorrow with 12 h before 3 shots of the card at 390 and 1280
  7. // 4 the planned text; at the reminder time the page's own timer (hl:time in the new code) shows the notification: read it from the
  8. // service worker registration; its tag carries the reminder's instant = start − 60 s EXACTLY.
  9. import { launchBrowser, Page } from './cdp.mjs';
  10. import { writeFileSync, readFileSync } from 'node:fs';
  11. const PORT = process.env.REAL_PORT, SCR = process.env.REAL_SCRATCH, OUT = process.env.OUT || '.';
  12. const PREFIX = process.env.PREFIX || 'x';
  13. const BASE = `http://localhost:${PORT}`;
  14. const sleep = (ms) => new Promise(r => setTimeout(r, ms));
  15. const pad = (n) => String(n).padStart(2, '0'); const J = JSON.stringify;
  16. const browser = await launchBrowser();
  17. const { targetInfos } = await browser.conn.send('Target.getTargets');
  18. const t = targetInfos.find(x => x.type === 'page');
  19. const { sessionId } = await browser.conn.send('Target.attachToTarget', { targetId: t.targetId, flatten: true });
  20. const page = new Page(browser, t.targetId, sessionId); await page._init();
  21. const shot = async (n) => { try { await Promise.race([page.send('Page.captureScreenshot', { format: 'png' }).then(({ data }) => writeFileSync(`${OUT}/${n}.png`, Buffer.from(data, 'base64'))), sleep(20000).then(() => { throw new Error('timeout'); })]); console.log('shot', n); } catch (e) { console.log('shot', n, 'FAILED', e.message); } };
  22. const text = () => page.evaluate(`(document.querySelector('#push-state') || {}).textContent || ''`);
  23. const box = (sel) => page.evaluate(`(() => { const e = document.querySelector(${J(sel)}); if (!e || e.classList.contains('hidden')) return null; const r = e.getBoundingClientRect(); return { x: r.x + r.width / 2, y: r.y + r.height / 2, h: r.height, text: e.textContent }; })()`);
  24. await page.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 800, deviceScaleFactor: 2, mobile: true });
  25. await browser.conn.send('Target.activateTarget', { targetId: t.targetId }).catch(() => {});
  26. await page.send('Page.bringToFront').catch(() => {});
  27. await browser.conn.send('Browser.grantPermissions', { origin: BASE, permissions: ['notifications'] }).catch(e => console.log('grant:', e.message));
  28. await page.goto(BASE + '/login/callback?ident_code=' + readFileSync(`${SCR}/code.txt`, 'utf8').trim(), { timeout: 90000 });
  29. await page.waitForSelector('#logout', { timeout: 60000 });
  30. await page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { timeout: 60000, label: 'hydrated' });
  31. await page.waitFor(`navigator.serviceWorker.getRegistration().then(r => !!(r && r.active))`, { label: 'sw', timeout: 60000 }).catch(() => console.log('sw not active yet'));
  32. // a fresh run starts without the subscription an earlier run left (each run's app has its own VAPID pair)
  33. await page.evaluate(`navigator.serviceWorker.getRegistration().then(r => r && r.pushManager.getSubscription()).then(x => x && x.unsubscribe())`).catch(() => {});
  34. await page.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: 200, y: 120 });
  35. console.log('permission', await page.evaluate('Notification.permission'));
  36. const ask = await box('#notify-ask'); console.log('ask button', J(ask));
  37. if (ask) { await page.send('Input.dispatchMouseEvent', { type: 'mousePressed', x: ask.x, y: ask.y, button: 'left', clickCount: 1 }); await page.send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: ask.x, y: ask.y, button: 'left', clickCount: 1 }); }
  38. let s = ''; for (let i = 0; i < 90 && !/closed/.test(s); i++) { await sleep(1000); s = await text(); }
  39. console.log('push-state:', J(s), '\nconsole:', page.dumpConsole().slice(-800));
  40. console.log('subscription host:', await page.evaluate(`navigator.serviceWorker.getRegistration().then(r => r && r.pushManager.getSubscription()).then(x => x ? new URL(x.endpoint).host : null)`));
  41. const off = await box('#push-off'); console.log('push-off control', J(off));
  42. await shot(PREFIX + '-390-on');
  43. if (!/closed/.test(s)) { console.log('NOT SUBSCRIBED'); process.exit(2); }
  44. const now = Date.now(); const start = new Date(Math.ceil((now + 150000) / 60000) * 60000);
  45. const zone = await page.evaluate('Intl.DateTimeFormat().resolvedOptions().timeZone');
  46. const dateOf = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
  47. const fields = { title: 'Real push', allDay: false, startDate: dateOf(start), startTime: `${pad(start.getHours())}:${pad(start.getMinutes())}`, endDate: '', endTime: '', place: '', notes: '', zone, custom: true, reminders: [{ unit: 'minutes', n: '1', time: '09:00' }, { unit: 'days', n: '1', time: '20:00' }] };
  48. const cookie = (await page.cookies([BASE])).map(c => c.name + '=' + c.value).join('; ');
  49. const r = await fetch(BASE + '/__hl/emit', { method: 'POST', headers: { 'content-type': 'application/json', cookie }, body: J({ t: 'emit', i: 1, event: 'calSave', payload: [fields, dateOf(new Date(now - 259200000)), dateOf(new Date(now + 777600000))] }) });
  50. console.log('calSave', r.status);
  51. const tomorrow = new Date(now + 86400000);
  52. const f2 = { ...fields, title: 'All day tomorrow', allDay: true, startDate: dateOf(tomorrow), startTime: '', reminders: [{ unit: 'hours', n: '12', time: '09:00' }] };
  53. const r2 = await fetch(BASE + '/__hl/emit', { method: 'POST', headers: { 'content-type': 'application/json', cookie }, body: J({ t: 'emit', i: 2, event: 'calSave', payload: [f2, dateOf(new Date(now - 259200000)), dateOf(new Date(now + 777600000))] }) });
  54. console.log('calSave all-day', r2.status);
  55. await page.goto(BASE + '/', { timeout: 60000 });
  56. await page.waitForSelector('#logout', { timeout: 60000 });
  57. await page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { timeout: 60000, label: 'hydrated' });
  58. await page.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: 200, y: 120 });
  59. await sleep(2500);
  60. console.log('planned text:', J(await page.evaluate(`(document.querySelector('#notify-planned') || {}).textContent`)), 'push-state:', J(await text()));
  61. await shot(PREFIX + '-390-card');
  62. const sb = await box('#settings-open');
  63. await page.send('Input.dispatchMouseEvent', { type: 'mousePressed', x: sb.x, y: sb.y, button: 'left', clickCount: 1 }); await page.send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: sb.x, y: sb.y, button: 'left', clickCount: 1 });
  64. await sleep(1500); await shot(PREFIX + '-390-settings');
  65. await page.goto(BASE + '/', { timeout: 60000 });
  66. await page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { timeout: 60000, label: 'hydrated' });
  67. await page.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 800, deviceScaleFactor: 1, mobile: false });
  68. await sleep(2500); await shot(PREFIX + '-1280-card');
  69. const remindAt = start.getTime() - 60000;
  70. console.log('reminder at', new Date(remindAt).toTimeString().slice(0, 8), '(the calendar page stays open); expected tag suffix :' + remindAt);
  71. await sleep(Math.max(0, remindAt + 20000 - Date.now()));
  72. await page.send('Page.bringToFront').catch(() => {});
  73. const list = await page.evaluate(`navigator.serviceWorker.getRegistration().then(r => r.getNotifications()).then(l => JSON.stringify(l.map(n => [n.title, n.body, n.tag])))`);
  74. console.log('registration.getNotifications():', list);
  75. console.log('RESULT tag has exact reminder instant:', list.includes(':' + remindAt) ? 'yes' : 'NO');
  76. await shot(PREFIX + '-1280-notified');
  77. const click = async (b) => { await page.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: b.x, y: b.y }); await page.send('Input.dispatchMouseEvent', { type: 'mousePressed', x: b.x, y: b.y, button: 'left', clickCount: 1 }); await page.send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: b.x, y: b.y, button: 'left', clickCount: 1 }); };
  78. const subscribed = () => page.evaluate(`navigator.serviceWorker.getRegistration().then(r => r.pushManager.getSubscription()).then(x => !!x)`);
  79. // the push button at 1280, real clicks: off → unsubscribed and "Turn on notifications" offered; on → subscribed again
  80. const o = await box('#push-off'); console.log('1280 push-off', J(o));
  81. await click(o); await sleep(3000);
  82. const afterOff = { sub: await subscribed(), ask: await box('#notify-ask'), state: await text() };
  83. console.log('after Turn off:', J(afterOff));
  84. await shot(PREFIX + '-1280-off');
  85. console.log('RESULT off ok:', !afterOff.sub && !!afterOff.ask ? 'yes' : 'NO');
  86. await click(afterOff.ask); let s2 = ''; for (let i = 0; i < 60 && !/closed/.test(s2); i++) { await sleep(1000); s2 = await text(); }
  87. const afterOn = { sub: await subscribed(), off: await box('#push-off'), state: s2 };
  88. console.log('after Turn on:', J(afterOn));
  89. console.log('RESULT on ok:', afterOn.sub && !!afterOn.off ? 'yes' : 'NO');
  90. await shot(PREFIX + '-1280-on-again');
  91. await page.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 800, deviceScaleFactor: 2, mobile: true });
  92. await sleep(1000); await shot(PREFIX + '-390-on-again');
  93. console.log('RESULT 390 off control height:', J(await box('#push-off')));
  94. console.log('app log push lines:', readFileSync(`${SCR}/app.log`, 'utf8').split('\n').filter(l => /push/i.test(l)).join(' | '));
  95. process.exit(0);

Branches

Latest commits

  • a69b27f9docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
  • 1a97edfdcalendar mission 010: reminder rows at 390 px (the 7-column month grid no longer catches the reminder lists), gate checks, settings-shots, reportmre
  • 61b21404calendar mission 009: reminder times on hl:time in the browser (lib/push-plan.hl and the Intl code removed), DST gate tests/dst.mjs, E2E script, reportmre
  • 875353c1calendar mission 009: re-vendor Hybriel master 022a3ac1 (int 6 6b396322 hl:time browser side, int 7 65e8ec21; bin sha256 6e0f77d7, plugins whole)mre
  • ce16a4efdeploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
  • f490bc8cdeploy: Web Push gate tests/push.mjs (PUSH_GATE_PORT)mre
  • 3af29fc8calendar mission 008 (A8): report, README, LOG, push-shots.mjsmre
  • f91f3663calendar mission 008 (A8): push only asked of the browser when the app has the VAPID settings (pushAvailable); real-FCM E2E scripts (push-real-app.mjs, push-real.mjs)mre
  • bf571badcalendar mission 008 (A8): Turn off on this device (unsubscribes the browser, server drops the device, choice kept), subscribe/refresh when the app is shown again; push gate part 3mre
  • 50985708calendar mission 008 (A7): Web Push report, README, mission, LOGmre
  • ee318774calendar mission 008 (A7): push-real.mjs, push sent log linemre
  • ebda0fd1calendar mission 008 (A7): server-side reminder plan on hl:time (push-plan.hl; hl:time fromLocal in a browser static is refused: repro .scratch/hltime-client), push gate 9/9mre
  • d063dad3calendar mission 008 (A7): Web Push (WIP): lib/push.hl subscriptions + sender clock, faces calPushSave/calPushOff, button subscribes, VAPID tool, tests/push.mjs; instantOf on hl:timemre
  • cf175c80calendar mission 008 (A7): re-vendor Hybriel master 0e3c9830 (bin 9d957fed, plugins whole: hl:crypto Web Push primitives, hl:web sendPush)mre
  • 9bf3c38bcalendar mission 008: re-vendor Hybriel f9833544 (gates old = new); Web Push stopped: hl:crypto half missing on mastermre
  • 186f969bcalendar mission 007: signed-in gate for the first-pointer race (fails on 3c5604f), README theme section, reportmre
  • ba9b4955calendar mission 006: first pointer event no longer re-runs the month (stale overwrite race), gate check, e2e settings cleanup, reportmre
  • bd730759calendar mission 006: theme move (WIP): brief, report, LOG, STATUSmre
  • b117b153calendar mission 006 WIP: reminder row fields keep 44 px; e2e script flagsmre
  • 53e3b0debrowser gate: Log out through the user menu, theme colour rgb(15, 20, 25)mre