gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchmainf9b8f918Merge branch 'calendar-vendor-day61' into mainAtlasmain/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. // hybriel 8f4e7ffa: wait for this page, which does not need a socket, then let its handlers attach.
  24. const hydrated = async (page) => {
  25. await page.waitFor("!!window.__hl && document.querySelector('#go') != null", { timeout: 60000, label: 'page hydrated' });
  26. await sleep(1500);
  27. };
  28. // python zoneinfo: the instant of a wall clock in a zone (fold = the earlier instant, gap = moved forward by its length)
  29. const py = `
  30. import sys, json
  31. from datetime import datetime, timedelta
  32. from zoneinfo import ZoneInfo
  33. def inst(y,mo,d,h,mi,zone):
  34. z = ZoneInfo(zone)
  35. dt = datetime(y,mo,d,h,mi,tzinfo=z) # fold=0: earlier; a gap reads with the offset before the change = forward
  36. t0 = int(dt.timestamp()*1000); t1 = int(dt.replace(fold=1).timestamp()*1000)
  37. AMB.append(t0 != t1)
  38. return t0
  39. def prev(dstr,n):
  40. y,m,d = map(int,dstr.split('-')); return (datetime(y,m,d)-timedelta(days=n)).strftime('%Y-%m-%d')
  41. AMB = []
  42. cases = json.load(sys.stdin); dev = sys.argv[1]; out = []
  43. for c in cases:
  44. zone = dev if c['allday'] else c['zone']
  45. st = c['startDate'] + ('T00:00' if c['allday'] else 'T' + c['startTime'])
  46. 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)
  47. s = p(st)
  48. if c['unit']=='minutes': at = s - int(c['n'])*60000
  49. elif c['unit']=='hours': at = s - int(c['n'])*3600000
  50. else: at = p(prev(c['startDate'], int(c['n'])) + 'T' + c['time'])
  51. out.append([at, any(AMB)]); AMB.clear()
  52. print(json.dumps(out))
  53. `;
  54. let server = null, browser = null;
  55. async function stop() {
  56. if (browser) { try { await browser.close(); } catch {} browser = null; }
  57. 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; }
  58. }
  59. try {
  60. 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' });
  61. let up = false;
  62. for (let i = 0; i < 100 && !up; i++) { await sleep(2000); try { up = (await fetch(`http://127.0.0.1:${PORT}/`)).ok; } catch {} }
  63. check('the test page is served', up);
  64. if (!up) throw new Error('no server');
  65. browser = await launchBrowser({ debugPortRange: [CPORT, CPORT] });
  66. const page = await browser.newPage();
  67. for (const dev of ['Europe/Vienna', 'America/New_York', 'Australia/Lord_Howe']) {
  68. await page.send('Emulation.setTimezoneOverride', { timezoneId: dev });
  69. await page.goto(`http://127.0.0.1:${PORT}/`);
  70. await page.waitForSelector('#go');
  71. await hydrated(page);
  72. await page.click('#go');
  73. let text = '';
  74. for (let i = 0; i < 120 && text.split(';').length < 3500; i++) { await sleep(1000); text = await page.evaluate("document.querySelector('#out').textContent"); }
  75. 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] }; });
  76. check(`[device ${dev}] cases computed`, cases.length == 3500, 'got ' + cases.length);
  77. const refAmb = JSON.parse(execFileSync('python3', ['-I', '-c', py, dev], { input: JSON.stringify(cases), maxBuffer: 1 << 26 }).toString());
  78. const ref = refAmb.map(x => x[0]), amb = refAmb.map(x => x[1]);
  79. const diffOldNew = cases.filter(c => c.old !== c.now);
  80. const diffRef = cases.filter((c, i) => c.now !== String(ref[i]));
  81. const nAmb = amb.filter(Boolean).length;
  82. // the ONE intended difference: a wall clock inside a fold (autumn, the hour that repeats) or a gap (spring) — old and new disagree where
  83. // the Intl by hand picked another instant than the documented rule (fold = the earlier, gap = moved forward); hl:time (as the
  84. // server already did for Web Push) follows the rule and python zoneinfo agrees
  85. const unexplained = cases.filter((c, i) => c.old !== c.now && !amb[i]);
  86. 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])]);
  87. 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]));
  88. const later = diffOldNew.filter(c => Number(c.now) < Number(c.old)).length, earlier = diffOldNew.length - later;
  89. 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));
  90. 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(', '));
  91. 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');
  92. console.log(' Vienna edge, 02:30 start, 1 h before:', edge.map(c => `${c.startDate} → ${new Date(Number(c.now)).toISOString()}`).join(' ; '));
  93. }
  94. } catch (e) { check('ran', false, String(e && e.stack || e)); }
  95. await stop();
  96. console.log(`${passes} passed, ${failures} failed`);
  97. process.exit(failures ? 1 : 0);

Branches

Latest commits

  • f9b8f918Merge branch 'calendar-vendor-day61' into mainAtlas
  • 66341793|||PR Vendor Hybriel day61Atlas
  • 36fc596bMerge branch 'vendor-day59' into mainAtlas
  • b37cc1da|||PR Vendor Hybriel day59Atlas
  • 05665102Merge branch 'vendor-day56' into mainAtlas
  • 687296fb|||PR Vendor Hybriel day56Atlas
  • a6166d4eMerge branch 'hl-standard-3' into mainAtlas
  • 6d0eb3b0|||PR Calendar day add buttons only when signed in (Kunibert minor)Atlas
  • add4b499|||PR Make calendar day actions keyboard accessibleAtlas
  • 79e49b4dMerge branch 'hl-standard' into mainAtlas
  • e9fec7bb|||PR HL-STANDARD clean-up: typed parameters, plain locals, by-reference cacheAtlas
  • eff166a4Re-vendor complete Hybriel plugins and runtime to day44mre
  • cef81394Wait for the DST fixture page instead of an unused socketmre
  • 42434f47Check lazy-session cookies after login with a stored anonymous fixturemre
  • 728e84e3Re-vendor complete Hybriel day41 plugin directoriesmre
  • cbd7ff43Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
  • 59d1da0acalendar: plain declarations instead of needless let in 9 files (calendar#17): 49 declarations that are never reassigned; reassigned ones and the timer closure's p stay letmre
  • f5415cf9calendar: the Style blocks in the language's nested form (calendar#16): rules named after the View's own elements with their children nested, pseudo-classes and @media nested, merged duplicate select rule; same CSS, shots identical in Chrome at 4 sizesmre
  • edb7c947calendar: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 56+4 failing → 60 passedmre
  • bf8cc0fcStyles move into their components: the shell's styles into main.hl, the events and the editors into the month view's Style block; styles.hl keeps only the theme inherit, the accent and the message line; .gitignore ignores a bin symlink too; tests/styles-shots.mjs for the before/after pixel comparemre