calendar
All repositories: gitoria
5.7 KB
// tests/push-real.mjs — calendar#9 part 2, the REAL push service (FCM) and a VISIBLE notification, in lisbeth's LLM Chrome// (HL_CDP_URL / CDP tunnel -L 9223; ONE tab reused, the calendar page stays open on it; run under `timeout 600 flock -o <lisbeth.lock>`).// REAL_PORT=8789 REAL_SCRATCH=<dir of tests/push-real-app.mjs> OUT=<evidence dir> node tests/push-real.mjs// needs: tests/push-real-app.mjs running, and ssh -f -N -R <port>:127.0.0.1:<port> lisbeth (the page is http://localhost:<port> on lisbeth)// 1 sign in (fresh ident code), grant notifications, first pointer; the page subscribes through FCM 2 an event 2.5 min ahead with a// reminder 1 min before 3 the page stays on the calendar; at the reminder time read registration.getNotifications() from the page// and screenshot the page. The app's log shows `push sent (201)` (read from <scratch>/app.log).import { launchBrowser, Page } from './cdp.mjs';import { writeFileSync, readFileSync } from 'node:fs';const PORT = process.env.REAL_PORT, SCR = process.env.REAL_SCRATCH, OUT = process.env.OUT || '.';const BASE = `http://localhost:${PORT}`;const sleep = (ms) => new Promise(r => setTimeout(r, ms));const pad = (n) => String(n).padStart(2, '0'); const J = JSON.stringify;const browser = await launchBrowser();const { targetInfos } = await browser.conn.send('Target.getTargets');const t = targetInfos.find(x => x.type === 'page');const { sessionId } = await browser.conn.send('Target.attachToTarget', { targetId: t.targetId, flatten: true });const page = new Page(browser, t.targetId, sessionId); await page._init();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); } };const text = () => page.evaluate(`(document.querySelector('#push-state') || {}).textContent || ''`);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 }; })()`);await page.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 800, deviceScaleFactor: 2, mobile: true });await browser.conn.send('Target.activateTarget', { targetId: t.targetId }).catch(() => {});await page.send('Page.bringToFront').catch(() => {});await browser.conn.send('Browser.grantPermissions', { origin: BASE, permissions: ['notifications'] }).catch(e => console.log('grant:', e.message));await page.goto(BASE + '/login/callback?ident_code=' + readFileSync(`${SCR}/code.txt`, 'utf8').trim(), { timeout: 90000 });await page.waitForSelector('#logout', { timeout: 60000 });await page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { timeout: 60000, label: 'hydrated' });await page.waitFor(`navigator.serviceWorker.getRegistration().then(r => !!(r && r.active))`, { label: 'sw', timeout: 60000 }).catch(() => console.log('sw not active yet'));await page.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: 200, y: 120 });console.log('permission', await page.evaluate('Notification.permission'));const ask = await box('#notify-ask'); console.log('ask button', J(ask));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 }); }let s = ''; for (let i = 0; i < 90 && !/closed/.test(s); i++) { await sleep(1000); s = await text(); }console.log('push-state:', J(s), '\nconsole:', page.dumpConsole().slice(-800));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)`));const off = await box('#push-off'); console.log('push-off control', J(off));await shot('real-3-on');if (!/closed/.test(s)) { console.log('NOT SUBSCRIBED'); process.exit(2); }const now = Date.now(); const start = new Date(Math.ceil((now + 150000) / 60000) * 60000);const zone = await page.evaluate('Intl.DateTimeFormat().resolvedOptions().timeZone');const dateOf = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;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' }] };const cookie = (await page.cookies([BASE])).map(c => c.name + '=' + c.value).join('; ');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))] }) });console.log('calSave', r.status);const remindAt = start.getTime() - 60000;console.log('reminder at', new Date(remindAt).toTimeString().slice(0, 8), '(the calendar page stays open)');await sleep(Math.max(0, remindAt + 20000 - Date.now()));await page.send('Page.bringToFront').catch(() => {});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])))`);console.log('registration.getNotifications():', list);await shot('real-4-notified');console.log('app log push lines:', readFileSync(`${SCR}/app.log`, 'utf8').split('\n').filter(l => /push/i.test(l)).join(' | '));process.exit(0);
Branches
Latest commits
- 490c658aident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
- 18095868calendar: Reminder settings button opens its dialog again (the dialog's open handler still closed the removed user menu and stopped); old e2e and gate scripts use the new headermre
- 6eee4b5acalendar header: the selector alone top right plus Log out as before the theme missions; Reminder settings back on the month page (WIP: the settings test still fails)mre
- 0b909decident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
- 0c8f9364Merge branch 'sy-sync'mre
- 9fab1c8fsync components.hybriel 4922f9c into the month view: prev / next 44 px targets, names formatted in UTC (a UTC+12 zone showed the wrong first weekday); the calendar keeps its own language handling (Accept-Language / browser) and the P1/C13 reminder code; gate: 44 px check (SY)mre
- 27d3e294theme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
- 2ac9c1bbdeploy: security gate (tests/security.mjs)mre
- 6b0a2571merge sc-sec (calendar security) with 99-year sessionsmre
- 92001e52sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
- 0f76c99dSecurity audit SC: push endpoint SSRF guard, uploadMax 0, Secure cookie, login session rotation + rate limit, event cap, nosniff, security gatemre
- 2dd53dccP1: one reminder shows once: arm() one at a time, the page skips reminders the server already pushed; push-twice gatemre
- 3a29760aC13 report (handoff)mre
- 33ab66ffCalendar: notification controls move from the month view into Reminder settings (user menu), one consistent state, state read when the dialog opensmre
- 682a5b43reports: calendar gate countsmre
- 876d22b2reports/H1-hydrate.mdmre
- ef0cae45tests/dst.mjs: wait for hydration instead of a fixed 2.5 s sleep before clicking #gomre
- d9cadecatests/cdp.mjs: HL_CPU_THROTTLE=<rate> optional CPU throttling for gate runsmre
- efa61227re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
- 7808adbecalendar#12: report 011, LOG, STATUS, push-shots-testmre