gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit682a5b43682a5b43reports: calendar gate countsmre682a5b43/tests/dst.mjs

7.1 KB

  1. // tests/dst.mjs — mission 009: the reminder times of the NEW code (hl:time in the browser) equal python zoneinfo and those of the OLD code
  2. // (Intl by hand, tests/dst/old-reminders.hl) except where the old one broke the fold/gap rule (reported, one hour), for 3500 cases per device zone across the DST changes of Europe/Vienna (last
  3. // Sundays of March/October), New York, Lord Howe, UTC, Kolkata; timed and all-day events; minutes/hours/days rows.
  4. // node tests/dst.mjs env: DST_GATE_PORT (app, default 8700), DST_GATE_CHROME (debug port, default PORT+1), DST_GATE_SCRATCH
  5. // Real headless Chrome; its time zone is set to the device zones below (the all-day events are read in the device zone).
  6. import { spawn, execFileSync } from 'node:child_process';
  7. import { existsSync, mkdirSync, rmSync } from 'node:fs';
  8. import { dirname, join, resolve } from 'node:path';
  9. import { fileURLToPath } from 'node:url';
  10. const HERE = dirname(fileURLToPath(import.meta.url));
  11. const APP = resolve(HERE, '..');
  12. const PORT = Number(process.env.DST_GATE_PORT || 8700);
  13. const CPORT = Number(process.env.DST_GATE_CHROME || PORT + 1);
  14. const SCRATCH = resolve(process.env.DST_GATE_SCRATCH || join(APP, '.scratch', 'dst-gate'));
  15. rmSync(SCRATCH, { recursive: true, force: true });
  16. mkdirSync(join(SCRATCH, 'chrome'), { recursive: true });
  17. process.env.TMPDIR = join(SCRATCH, 'chrome');
  18. if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';
  19. const { launchBrowser } = await import('./cdp.mjs');
  20. let passes = 0, failures = 0;
  21. const check = (l, ok, d = '') => { console.log(`${ok ? 'ok ' : 'FAIL'} ${l}${ok ? '' : ' — ' + d}`); ok ? passes++ : failures++; };
  22. const sleep = (ms) => new Promise(r => setTimeout(r, ms));
  23. // the page is live (hl:web booted, socket open): a click before that hits a server-rendered button nobody listens to yet and is lost
  24. const hydrated = (page) => page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { timeout: 60000, label: 'page hydrated' });
  25. // python zoneinfo: the instant of a wall clock in a zone (fold = the earlier instant, gap = moved forward by its length)
  26. const py = `
  27. import sys, json
  28. from datetime import datetime, timedelta
  29. from zoneinfo import ZoneInfo
  30. def inst(y,mo,d,h,mi,zone):
  31. z = ZoneInfo(zone)
  32. dt = datetime(y,mo,d,h,mi,tzinfo=z) # fold=0: earlier; a gap reads with the offset before the change = forward
  33. t0 = int(dt.timestamp()*1000); t1 = int(dt.replace(fold=1).timestamp()*1000)
  34. AMB.append(t0 != t1)
  35. return t0
  36. def prev(dstr,n):
  37. y,m,d = map(int,dstr.split('-')); return (datetime(y,m,d)-timedelta(days=n)).strftime('%Y-%m-%d')
  38. AMB = []
  39. cases = json.load(sys.stdin); dev = sys.argv[1]; out = []
  40. for c in cases:
  41. zone = dev if c['allday'] else c['zone']
  42. st = c['startDate'] + ('T00:00' if c['allday'] else 'T' + c['startTime'])
  43. p = lambda s: inst(int(s[0:4]),int(s[5:7]),int(s[8:10]),int(s[11:13]),int(s[14:16]),zone)
  44. s = p(st)
  45. if c['unit']=='minutes': at = s - int(c['n'])*60000
  46. elif c['unit']=='hours': at = s - int(c['n'])*3600000
  47. else: at = p(prev(c['startDate'], int(c['n'])) + 'T' + c['time'])
  48. out.append([at, any(AMB)]); AMB.clear()
  49. print(json.dumps(out))
  50. `;
  51. let server = null, browser = null;
  52. async function stop() {
  53. if (browser) { try { await browser.close(); } catch {} browser = null; }
  54. if (server) { try { server.kill('SIGTERM'); } catch {} await new Promise(r => { if (server.exitCode !== null || server.signalCode !== null) return r(); server.once('exit', r); setTimeout(r, 3000); }); server = null; }
  55. }
  56. try {
  57. server = spawn(join(APP, 'bin', 'hybriel'), ['tests/dst/project.hl'], { cwd: APP, env: { ...process.env, DST_GATE_PORT: String(PORT), HL_HOST: '127.0.0.1' }, stdio: 'ignore' });
  58. let up = false;
  59. for (let i = 0; i < 100 && !up; i++) { await sleep(2000); try { up = (await fetch(`http://127.0.0.1:${PORT}/`)).ok; } catch {} }
  60. check('the test page is served', up);
  61. if (!up) throw new Error('no server');
  62. browser = await launchBrowser({ debugPortRange: [CPORT, CPORT] });
  63. const page = await browser.newPage();
  64. for (const dev of ['Europe/Vienna', 'America/New_York', 'Australia/Lord_Howe']) {
  65. await page.send('Emulation.setTimezoneOverride', { timezoneId: dev });
  66. await page.goto(`http://127.0.0.1:${PORT}/`);
  67. await page.waitForSelector('#go');
  68. await hydrated(page);
  69. await page.click('#go');
  70. let text = '';
  71. for (let i = 0; i < 120 && text.split(';').length < 3500; i++) { await sleep(1000); text = await page.evaluate("document.querySelector('#out').textContent"); }
  72. const cases = text.split(';').filter(Boolean).map(l => { const f = l.split('|'); return { id: f[0], zone: f[1], allday: f[2] == 'allday', startDate: f[3], startTime: f[4], unit: f[5], n: f[6], time: f[7], old: f[8], now: f[9] }; });
  73. check(`[device ${dev}] cases computed`, cases.length == 3500, 'got ' + cases.length);
  74. const refAmb = JSON.parse(execFileSync('python3', ['-I', '-c', py, dev], { input: JSON.stringify(cases), maxBuffer: 1 << 26 }).toString());
  75. const ref = refAmb.map(x => x[0]), amb = refAmb.map(x => x[1]);
  76. const diffOldNew = cases.filter(c => c.old !== c.now);
  77. const diffRef = cases.filter((c, i) => c.now !== String(ref[i]));
  78. const nAmb = amb.filter(Boolean).length;
  79. // the ONE intended difference: a wall clock inside a fold (autumn, the hour that repeats) or a gap (spring) — old and new disagree where
  80. // the Intl by hand picked another instant than the documented rule (fold = the earlier, gap = moved forward); hl:time (as the
  81. // server already did for Web Push) follows the rule and python zoneinfo agrees
  82. const unexplained = cases.filter((c, i) => c.old !== c.now && !amb[i]);
  83. check(`[device ${dev}] new = python zoneinfo for all ${cases.length} cases`, diffRef.length == 0, diffRef.length + ' differ, first ' + JSON.stringify(diffRef[0]) + ' ref ' + ref[cases.indexOf(diffRef[0])]);
  84. check(`[device ${dev}] new = old except in a fold/gap (${diffOldNew.length} of ${nAmb} fold/gap cases differ)`, unexplained.length == 0, unexplained.length + ' differ outside a fold/gap, first ' + JSON.stringify(unexplained[0]));
  85. const later = diffOldNew.filter(c => Number(c.now) < Number(c.old)).length, earlier = diffOldNew.length - later;
  86. check(`[device ${dev}] every difference is exactly one hour (a whole DST step; ${later} fold cases now earlier, ${earlier} gap cases now later)`, diffOldNew.every(c => Math.abs(Number(c.now) - Number(c.old)) == 3600000));
  87. console.log(' differences old→new (ms):', [...new Set(diffOldNew.map(c => Number(c.now) - Number(c.old)))].join(', '), ' zones:', [...new Set(diffOldNew.map(c => c.zone + (c.allday ? ' all-day' : '')))].join(', '));
  88. const edge = cases.filter(c => c.zone == 'Europe/Vienna' && !c.allday && (c.startDate == '2026-10-25' || c.startDate == '2026-03-29') && c.startTime == '02:30' && c.unit == 'hours' && c.n == '1');
  89. console.log(' Vienna edge, 02:30 start, 1 h before:', edge.map(c => `${c.startDate} → ${new Date(Number(c.now)).toISOString()}`).join(' ; '));
  90. }
  91. } catch (e) { check('ran', false, String(e && e.stack || e)); }
  92. await stop();
  93. console.log(`${passes} passed, ${failures} failed`);
  94. process.exit(failures ? 1 : 0);

Branches

Latest commits

  • 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
  • df2e4fa0calendar#12: test push rate limit (1 per 30 s per device), owner-only gate checksmre
  • acb957cfcalendar#12: Send a test notification on a subscribed device (one push in ~10 s, owner's own device), push gate part 4mre
  • 0b222eb8tests: e2e-theme CDP port default from E2E_THEME_CDP_PORT (8756 unchanged)mre
  • 8b8a5abare-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
  • 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