gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmain0f6d1592Merge branch 'f18b-shell-session' into mainIdentmain/tests/delivery.mjs

25.3 KB

  1. // tests/delivery.mjs — THE GATE OF PIECE 5 (ticket ident#7, mission 011): the daily mail at 17:00 in the user's time
  2. // zone, urgent at once. A FAKE CLOCK: the server runs with IDENT_TEST_CLOCK = a file holding an epoch-ms instant that
  3. // delivery takes as "now" (lib/delivery-helpers.hl clockNow) and IDENT_DIGEST_EVERY=0.2 (a round every 200 ms); this
  4. // script moves that instant. Real headless Chrome (tests/cdp.mjs) for what users do (sign in with the browser's
  5. // emulated zone, switch mail off on the per-app page, change the zone on `/`); this script plays the APP'S SERVER.
  6. // users: vienna (Europe/Vienna), newyork (America/New_York), tokyo (Asia/Tokyo), off (Europe/Vienna, switches the
  7. // app's mail off), utc (signs in with a zone nobody knows → UTC).
  8. // checks: nothing before anyone's 17:00; urgent arrives at once (and not again in the digest); each user's digest at
  9. // THEIR 17:00 (16:59 = nothing), exactly once, only their own notifications, name/app/identity/text/link; "off" gets
  10. // nothing (switched off before AND after arrival); one arriving after 17:00 waits for tomorrow; a server that was
  11. // down at 17:00 sends at its first round after it; a restart sends nothing twice; DST days (Vienna 25 Oct 2026,
  12. // New York 1 Nov 2026: 17:00 is an hour later in UTC); a zone changed on `/` moves the hour (Australia/Adelaide, +10:30).
  13. // Own servers only, NEVER real mail: ident :8700 (IDENT_MAIL_SINK; notification mails = <sink>.mail, JSON lines).
  14. // Own storage .scratch/delivery-gate/ (wiped at start). Chrome debug ports 8706-8719.
  15. // Screenshots .scratch/delivery-account-{390,1280}.png — look at them.
  16. // Run: node tests/delivery.mjs (exit 0 = all passed)
  17. import { spawn, execFileSync } from 'node:child_process';
  18. import { readFileSync, writeFileSync, rmSync, mkdirSync, existsSync, cpSync } from 'node:fs';
  19. import { dirname, join } from 'node:path';
  20. import { fileURLToPath } from 'node:url';
  21. import { launchBrowser, sleep } from './cdp.mjs';
  22. // H2: a server-rendered page can be clicked before the client mounted — the click is lost (or a native form GET). Every goto() on a Hybriel
  23. // page (the SSR HTML carries #hl-seed) therefore waits until the page is live (socket open) before the test touches it.
  24. function live(page) {
  25. const goto = page.goto.bind(page);
  26. page.goto = async (url, o) => {
  27. const r = await goto(url, o);
  28. await page.waitFor("!document.getElementById('hl-seed') || (!!window.__hl && !!window.__hl.socket && window.__hl.socket.readyState === 1)", { label: 'page hydrated ' + url });
  29. return r;
  30. };
  31. return page;
  32. }
  33. if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';
  34. const APP = join(dirname(fileURLToPath(import.meta.url)), '..');
  35. const G = join(APP, '.scratch/delivery-gate');
  36. const SHOTS = join(APP, '.scratch');
  37. const PORT = Number(process.env.DELIVERY_GATE_PORT || 8700); // deploy gates run beside workers: give it a free slot
  38. const ID = 'http://127.0.0.1:' + PORT;
  39. const SITE = 'http://127.0.0.1:' + (PORT + 1); // the app's origin (only in URLs: nothing listens there)
  40. const CHROME_PORTS = (process.env.DELIVERY_GATE_CHROME || '8706-8719').split('-').map(Number);
  41. const J = JSON.stringify;
  42. const STORE = join(G, 'ident'), SINK = join(G, 'mail.txt'), MAILS = SINK + '.mail', CLOCK = join(G, 'clock');
  43. let passed = 0, failed = 0;
  44. const check = (name, ok, detail = '') => {
  45. if (ok) { passed++; console.log(' ok ' + name); }
  46. else { failed++; console.log(' FAIL ' + name + (detail ? ' — ' + detail : '')); }
  47. };
  48. // ---- the server and its clock ----------------------------------------------------------
  49. let proc = null, log = '';
  50. function startServer() {
  51. log = '';
  52. proc = spawn(join(APP, 'bin/hybriel'), ['project.hl'], {
  53. cwd: APP, stdio: ['ignore', 'pipe', 'pipe'],
  54. env: { ...process.env, SMTP_HOST: '', SMTP_USER: '', SMTP_PASSWORD: '', IDENT_PORT: String(PORT), IDENT_STORAGE: STORE,
  55. IDENT_SESSIONS: join(G, 'sess') + '/', IDENT_MAIL_SINK: SINK, IDENT_IP_LIMIT: '1000', IDENT_IP_DAY_LIMIT: '1000',
  56. IDENT_TEST_CLOCK: CLOCK, IDENT_DIGEST_EVERY: '0.2', IDENT_WATCH: '0' },
  57. });
  58. proc.stdout.on('data', d => { log += d; }); proc.stderr.on('data', d => { log += d; });
  59. }
  60. async function up() { // a cold start compiles the app first (18-41 s): wait up to 150 s
  61. for (let i = 0; i < 600; i++) { try { await fetch(ID + '/', { redirect: 'manual' }); return; } catch {} await sleep(250); }
  62. throw new Error('server did not come up');
  63. }
  64. async function stopServer() {
  65. const p = proc; proc = null;
  66. writeFileSync(join(G, 'ident-' + Date.now() + '.log'), log);
  67. await new Promise(r => { p.on('exit', r); p.kill(); });
  68. }
  69. const at = (iso) => Date.parse(iso);
  70. function setClock(iso) { writeFileSync(CLOCK, String(at(iso))); }
  71. const ROUNDS = 1500; // ≥ 7 rounds of 200 ms
  72. // ---- the mail sink -----------------------------------------------------------------------
  73. const mails = () => existsSync(MAILS) ? readFileSync(MAILS, 'utf8').trim().split('\n').filter(Boolean).map(l => JSON.parse(l)) : [];
  74. const mailsTo = (email) => mails().filter(m => m.to === email);
  75. async function waitMails(n, ms = 5000) { const t0 = Date.now(); while (Date.now() - t0 < ms) { if (mails().length >= n) return; await sleep(100); } }
  76. const lastCode = (email) => {
  77. const lines = readFileSync(SINK, 'utf8').trim().split('\n').filter(l => l.startsWith(email + ' '));
  78. return lines.length ? lines[lines.length - 1].split(' ')[1] : null;
  79. };
  80. // ---- HTTP helpers (as tests/notify.mjs) ---------------------------------------------------
  81. let emitI = 0;
  82. async function emit(event, payload, cookie) {
  83. const r = await fetch(ID + '/__hl/emit', { method: 'POST', headers: { 'content-type': 'application/json', ...(cookie ? { cookie } : {}) }, body: J({ t: 'emit', i: ++emitI, event, payload }) });
  84. const t = await r.text();
  85. let j = null; try { j = JSON.parse(t); } catch {}
  86. return { status: r.status, cookie: (r.headers.get('set-cookie') || '').split(';')[0], value: j && j.value, raw: t };
  87. }
  88. async function api(path, body) {
  89. const r = await fetch(ID + path, { method: 'POST', headers: { 'content-type': 'application/json' }, body: J(body) });
  90. const t = await r.text();
  91. let j = null; try { j = JSON.parse(t); } catch {}
  92. return { status: r.status, j, t };
  93. }
  94. async function apiLogin(email, zone) {
  95. const q = await fetch(ID + '/api/code', { method: 'POST', headers: { 'content-type': 'application/json' }, body: J({ email }) });
  96. if (q.status !== 200) throw new Error('code request failed: ' + q.status);
  97. const v = await emit('verifyCode', [email, lastCode(email), zone]);
  98. if (!v.value || !v.value.account || !v.cookie) throw new Error('api login failed: ' + v.raw);
  99. return { cookie: v.cookie, identity: v.value.identities[0].id };
  100. }
  101. async function appIdentity(cookie, app, identity) {
  102. const l = await fetch(ID + '/login?key=' + app.key + '&return=' + encodeURIComponent(SITE + '/callback'), { redirect: 'manual' });
  103. const rid = (l.headers.get('location') || '').split('/').pop();
  104. const c = await emit('chooseIdentity', [rid, identity], cookie);
  105. const code = new URL(c.value.url).searchParams.get('ident_code');
  106. const x = await api('/api/exchange', { key: app.key, secret: app.secret, code });
  107. if (x.status !== 200) throw new Error('exchange failed: ' + x.t);
  108. return x.j.identity;
  109. }
  110. let copyN = 0;
  111. function store() {
  112. const copy = join(G, 'copy-' + (++copyN));
  113. cpSync(STORE, copy, { recursive: true });
  114. const out = execFileSync(join(APP, 'bin/hybriel'), ['tools/dump-store.hl'], { cwd: APP, env: { ...process.env, IDENT_STORAGE: copy }, encoding: 'utf8' });
  115. rmSync(copy, { recursive: true, force: true });
  116. return JSON.parse(out.split('\n').find(l => l.startsWith('{')));
  117. }
  118. // ---- browser helpers -------------------------------------------------------------------------
  119. const pages = [];
  120. async function ready(p) { await p.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { label: 'hydrated' }); }
  121. async function viewport(p, w) { await p.send('Emulation.setDeviceMetricsOverride', { width: w, height: w < 500 ? 844 : 900, deviceScaleFactor: 1, mobile: w < 500 }); }
  122. const txt = (p, sel) => p.evaluate(`(document.querySelector(${J(sel)}) || {}).textContent || ''`);
  123. const attr = (p, sel, a) => p.evaluate(`(document.querySelector(${J(sel)}) || { getAttribute: () => null }).getAttribute(${J(a)})`);
  124. // a user in their own Chrome, the browser's zone emulated: email → code → Skip. Answers { page, cookie, identity }
  125. async function browserUser(email, zone) {
  126. const br = await launchBrowser({ debugPortRange: CHROME_PORTS }); browsers.push(br);
  127. const p = live(await br.newPage()); pages.push(p);
  128. await viewport(p, 1280);
  129. await p.send('Emulation.setTimezoneOverride', { timezoneId: zone });
  130. await p.goto(ID + '/');
  131. await p.waitForSelector('#email'); await ready(p);
  132. await p.type('#email', email);
  133. await p.click('#sendcode');
  134. await p.waitFor('/\\/code$/.test(location.pathname) && !!document.querySelector("#code")', { label: 'code page' });
  135. await ready(p);
  136. await p.type('#code', lastCode(email));
  137. await p.click('#verify');
  138. await p.waitForSelector('#skip');
  139. await p.click('#skip');
  140. await p.waitFor('!document.querySelector("#identityform") && !!document.querySelector("#timezone")', { label: 'signed in' });
  141. const { cookies } = await p.send('Network.getCookies', { urls: [ID + '/'] });
  142. const c = cookies.find(x => x.name === 'identsid');
  143. const st = store();
  144. const account = st.accounts.find(a => a.email === email);
  145. return { page: p, cookie: 'identsid=' + c.value, identity: st.identities.find(i => i.account === account.id).id };
  146. }
  147. const browsers = [];
  148. let clean = [];
  149. rmSync(G, { recursive: true, force: true });
  150. mkdirSync(G, { recursive: true });
  151. try {
  152. setClock('2026-10-21T05:00:00Z'); // Vienna 07:00, New York 01:00, Tokyo 14:00 — before 17:00 everywhere
  153. startServer();
  154. await up();
  155. // ==== 0. users, the app, per-app ids ====================================================
  156. console.log('# setup: users in Vienna, New York, Tokyo, one who switches mail off, one without a known zone');
  157. const V = '[email protected]', NY = '[email protected]', T = '[email protected]', OFF = '[email protected]', U = '[email protected]';
  158. const vienna = await browserUser(V, 'Europe/Vienna');
  159. check('vienna: the browser\'s zone stored at the first login, the page says when the daily mail comes', (await txt(vienna.page, '#timezone')) === 'Europe/Vienna' && /daily mail .* 17:00 in this time zone/.test(await txt(vienna.page, '#digestnote')), await txt(vienna.page, '#timezonesection'));
  160. for (const w of [390, 1280]) {
  161. await viewport(vienna.page, w); await sleep(200);
  162. const over = await vienna.page.evaluate('document.documentElement.scrollWidth > window.innerWidth');
  163. check(`account page @${w}px: no horizontal overflow`, !over);
  164. await vienna.page.evaluate('document.querySelector("#timezonesection").scrollIntoView()');
  165. const { data } = await vienna.page.send('Page.captureScreenshot', { format: 'png' });
  166. writeFileSync(join(SHOTS, `delivery-account-${w}.png`), Buffer.from(data, 'base64'));
  167. }
  168. await viewport(vienna.page, 1280);
  169. const newyork = await browserUser(NY, 'America/New_York');
  170. check('newyork: zone America/New_York', (await txt(newyork.page, '#timezone')) === 'America/New_York', await txt(newyork.page, '#timezone'));
  171. const off = await browserUser(OFF, 'Europe/Vienna');
  172. const tokyo = await apiLogin(T, 'Asia/Tokyo');
  173. const utc = await apiLogin(U, 'Mars/Olympus_Mons');
  174. let s = store();
  175. const acct = (e) => s.accounts.find(a => a.email === e);
  176. check('a zone the database does not know is stored as UTC at the first login', acct(U).timeZone === 'UTC' && acct(T).timeZone === 'Asia/Tokyo', J([acct(U).timeZone, acct(T).timeZone]));
  177. let e = await emit('changeTimeZone', ['Mars/Olympus_Mons'], tokyo.cookie);
  178. check('changeTimeZone: an unknown zone of the right shape is refused by the SERVER (hl:time isZone)', e.value && /unknown time zone/.test(e.value.error), e.raw);
  179. e = await emit('changeTimeZone', ['Asia/Tokyo'], tokyo.cookie);
  180. check('changeTimeZone: a known zone is taken', e.value && e.value.timeZone === 'Asia/Tokyo', e.raw);
  181. const appV = (await emit('appCreate', [{ name: 'Chat app', origins: [SITE] }], tokyo.cookie)).value;
  182. const A = { key: appV.app.apiKey, secret: appV.secret };
  183. const idV = await appIdentity(vienna.cookie, A, vienna.identity);
  184. const idNY = await appIdentity(newyork.cookie, A, newyork.identity);
  185. const idOff = await appIdentity(off.cookie, A, off.identity);
  186. const idT = await appIdentity(tokyo.cookie, A, tokyo.identity);
  187. const idU = await appIdentity(utc.cookie, A, utc.identity);
  188. let r = await api('/api/kinds', { key: A.key, secret: A.secret, kinds: [{ name: 'Comment', push: false, email: true }, { name: 'Alert', push: true, email: false }] });
  189. check('the app registers Comment (mail) and Alert (push)', r.status === 200, r.t);
  190. const send = async (identity, body) => { const x = await api('/api/notify', { key: A.key, secret: A.secret, identity, ...body }); if (x.status !== 200) throw new Error('send failed: ' + x.t); return x.j.id; };
  191. // ==== 1. notifications arrive; nothing is mailed before 17:00 ===========================
  192. console.log('# before 17:00');
  193. const T1 = await send(idT, { name: 'Comment', text: 'TOKYO-ONE: Bea commented', link: SITE + '/post/1' });
  194. const T2 = await send(idT, { name: 'Comment', text: 'TOKYO-TWO first line\nsecond line' });
  195. const V1 = await send(idV, { name: 'Comment', text: 'VIENNA-ONE', link: SITE + '/post/2' });
  196. const V2 = await send(idV, { name: 'Mention', text: 'VIENNA-TWO (an unregistered name: daily mail)' });
  197. const N1 = await send(idNY, { name: 'Comment', text: 'NEWYORK-ONE' });
  198. const O1 = await send(idOff, { name: 'Comment', text: 'OFF-ONE (arrived while mail was on)' });
  199. const U1 = await send(idU, { name: 'Comment', text: 'UTC-ONE' });
  200. // "off" switches the app's mail off on the per-app page: override all → on, email → off
  201. s = store();
  202. const connOff = s.connections.find(c => c.identity === off.identity);
  203. await off.page.goto(ID + '/inbox/' + connOff.id); await off.page.waitForSelector('#ovactive'); await ready(off.page);
  204. await off.page.click('#ovactive');
  205. await off.page.waitFor('document.querySelector("#ovactive").getAttribute("aria-checked") === "true"', { label: 'override on' });
  206. await off.page.click('#ovemail');
  207. await off.page.waitFor('document.querySelector("#ovemail").getAttribute("aria-checked") === "false"', { label: 'email off' });
  208. check('off: the per-app page shows mail off for every kind', (await attr(off.page, '#ovemail', 'aria-checked')) === 'false');
  209. const O2 = await send(idOff, { name: 'Comment', text: 'OFF-TWO (arrived with mail off)' });
  210. await sleep(ROUNDS);
  211. check('05:00 UTC: no mail yet (before 17:00 in every zone)', mails().length === 0, J(mails()));
  212. // ==== 2. urgent: at once ====================================================================
  213. console.log('# urgent');
  214. const VU = await send(idV, { name: 'Alert', text: 'VIENNA-URGENT server down', link: SITE + '/status', urgent: true });
  215. let m = mails();
  216. check('urgent: mailed AT ONCE (before the answer), to vienna only', m.length === 1 && m[0].to === V, J(m));
  217. check('urgent mail: subject "<app>: <name>", text + link', m[0] && m[0].subject === 'Chat app: Alert' && m[0].text.includes('VIENNA-URGENT server down') && m[0].text.includes(SITE + '/status'), J(m[0]));
  218. const OU = await send(idOff, { name: 'Alert', text: 'OFF-URGENT', urgent: true });
  219. await sleep(300);
  220. check('urgent for a user with mail AND push off: no mail', mails().length === 1, J(mails().map(x => x.to)));
  221. s = store();
  222. const note = (id) => s.notifications.find(n => n.id === id);
  223. check('stored: the urgent one is mailed (mailSent, mailedAt), the off one is mail none, unsent', note(VU).mailSent === true && note(VU).mailedAt > 0 && note(OU).mail === 'none' && note(OU).mailSent === false, J([note(VU), note(OU)]));
  224. // ==== 3. Tokyo's 17:00 (08:00 UTC) =========================================================
  225. console.log('# Tokyo 17:00 = 08:00 UTC');
  226. setClock('2026-10-21T07:59:00Z'); await sleep(ROUNDS);
  227. check('Tokyo 16:59: no daily mail', mails().length === 1, J(mails().map(x => x.subject)));
  228. setClock('2026-10-21T08:00:00Z'); await waitMails(2); await sleep(ROUNDS);
  229. m = mailsTo(T);
  230. check('Tokyo 17:00: ONE daily mail to tokyo, nobody else', m.length === 1 && mails().length === 2, J(mails().map(x => x.to + ' ' + x.subject)));
  231. check('tokyo\'s mail: subject counts 2, dated tokyo\'s local day', m[0] && m[0].subject === 'ident: 2 notifications (2026-10-21)', m[0] && m[0].subject);
  232. check('tokyo\'s mail lists both: name — app · identity, text (line breaks kept), action link, the zone', m[0] && m[0].text.includes('* Comment — Chat app · Default') && m[0].text.includes('TOKYO-ONE: Bea commented') && m[0].text.includes('TOKYO-TWO first line\n second line') && m[0].text.includes(SITE + '/post/1') && m[0].text.includes('(17:00, Asia/Tokyo)') && m[0].text.indexOf('TOKYO-ONE') < m[0].text.indexOf('TOKYO-TWO'), m[0] && m[0].text);
  233. check('tokyo\'s mail holds nobody else\'s', m[0] && !/VIENNA|NEWYORK|OFF-|UTC-ONE/.test(m[0].text));
  234. await sleep(ROUNDS);
  235. check('Tokyo: not twice (more rounds at 17:00+)', mailsTo(T).length === 1);
  236. s = store();
  237. check('stored: tokyo\'s two mailed, its round dated 2026-10-21 (count 2)', note(T1).mailSent && note(T2).mailSent && s.digests.some(d => d.account === acct(T).id && d.lastDate === '2026-10-21' && d.count === 2), J(s.digests));
  238. const T3 = await send(idT, { name: 'Comment', text: 'TOKYO-THREE (after 17:00: tomorrow)' });
  239. await sleep(ROUNDS);
  240. check('one arriving after Tokyo\'s 17:00 is not mailed today', mailsTo(T).length === 1);
  241. // ==== 4. Vienna's 17:00 (CEST: 15:00 UTC), New York's (EDT: 21:00 UTC), UTC's =================
  242. console.log('# Vienna 17:00 = 15:00 UTC, UTC 17:00, New York 17:00 = 21:00 UTC');
  243. setClock('2026-10-21T14:59:00Z'); await sleep(ROUNDS);
  244. check('Vienna 16:59: nothing for vienna or off', mailsTo(V).length === 1 && mailsTo(OFF).length === 0);
  245. setClock('2026-10-21T15:00:00Z'); await waitMails(3); await sleep(ROUNDS);
  246. m = mailsTo(V);
  247. check('Vienna 17:00: vienna\'s daily mail (one)', m.length === 2 && m[1].subject === 'ident: 2 notifications (2026-10-21)', J(m.map(x => x.subject)));
  248. check('vienna\'s mail: VIENNA-ONE + the unregistered Mention, NOT the urgent one again', m[1] && m[1].text.includes('VIENNA-ONE') && m[1].text.includes('* Mention — Chat app') && !m[1].text.includes('VIENNA-URGENT'), m[1] && m[1].text);
  249. check('off (Vienna too): nothing — one switched off after it arrived, one that arrived switched off', mailsTo(OFF).length === 0);
  250. setClock('2026-10-21T16:59:00Z'); await sleep(ROUNDS);
  251. check('UTC 16:59: nothing for utc (its zone: UTC, the default)', mailsTo(U).length === 0);
  252. setClock('2026-10-21T17:00:00Z'); await waitMails(4); await sleep(ROUNDS);
  253. check('UTC 17:00: utc\'s daily mail', mailsTo(U).length === 1 && mailsTo(U)[0].text.includes('UTC-ONE') && mailsTo(U)[0].text.includes('(17:00, UTC)'), J(mailsTo(U)));
  254. setClock('2026-10-21T20:59:00Z'); await sleep(ROUNDS);
  255. check('New York 16:59: nothing for newyork', mailsTo(NY).length === 0);
  256. setClock('2026-10-21T21:00:00Z'); await waitMails(5); await sleep(ROUNDS);
  257. check('New York 17:00: newyork\'s daily mail, dated its local day', mailsTo(NY).length === 1 && mailsTo(NY)[0].subject === 'ident: 1 notification (2026-10-21)' && mailsTo(NY)[0].text.includes('NEWYORK-ONE'), J(mailsTo(NY)));
  258. check('after the day: 5 mails in all (1 urgent + 4 daily), none to off', mails().length === 5 && mailsTo(OFF).length === 0, J(mails().map(x => x.to)));
  259. s = store();
  260. check('stored: off\'s are pending, not mailed (not lost: inbox; switched on, tomorrow\'s mail)', note(O1).mail === 'daily' && note(O1).mailSent === false && note(O2).mail === 'none' && note(O2).mailSent === false, J([note(O1), note(O2)]));
  261. // ==== 5. down at 17:00, restart: catch up once, never twice =================================
  262. console.log('# restart');
  263. clean = pages.map(x => x.problems().length);
  264. check('no console errors or warnings until the restart', clean.every(n => n === 0), pages.flatMap(x => x.problems().map(q => q.text)).join(' | '));
  265. await stopServer();
  266. setClock('2026-10-22T09:00:00Z'); // Tokyo 18:00 on the 22nd: its 17:00 passed while the server was down
  267. startServer(); await up(); await waitMails(6); await sleep(ROUNDS);
  268. m = mailsTo(T);
  269. check('server down at Tokyo\'s 17:00: the first round after the start sends the 22nd\'s mail, with the one that waited', m.length === 2 && m[1].subject === 'ident: 1 notification (2026-10-22)' && m[1].text.includes('TOKYO-THREE'), J(m.map(x => x.subject)));
  270. check('…and nothing else after the restart (no day sent twice)', mails().length === 6, J(mails().map(x => x.to + ' ' + x.subject)));
  271. await stopServer();
  272. setClock('2026-10-22T09:30:00Z');
  273. startServer(); await up(); await sleep(ROUNDS * 2);
  274. check('a second restart the same day: nothing (the sent day is stored)', mails().length === 6, J(mails().map(x => x.to + ' ' + x.subject)));
  275. s = store();
  276. check('stored: TOKYO-THREE mailed', note(T3).mailSent === true);
  277. // ==== 6. DST days ===============================================================================
  278. console.log('# DST: Vienna 25 Oct 2026 (CET from 03:00), New York 1 Nov 2026 (EST from 02:00)');
  279. const V3 = await send(idV, { name: 'Comment', text: 'VIENNA-DST' });
  280. const N2 = await send(idNY, { name: 'Comment', text: 'NEWYORK-DST' });
  281. setClock('2026-10-25T15:00:00Z'); await sleep(ROUNDS); // Vienna 16:00 CET (17:00 at the summer offset)
  282. check('Vienna DST day, 15:00 UTC = 16:00 CET: nothing yet (a fixed +2 would send)', mailsTo(V).length === 2, J(mailsTo(V).map(x => x.subject)));
  283. setClock('2026-10-25T16:00:00Z'); await waitMails(7); await sleep(ROUNDS);
  284. check('Vienna DST day, 16:00 UTC = 17:00 CET: vienna\'s mail, dated the 25th', mailsTo(V).length === 3 && mailsTo(V)[2].subject === 'ident: 1 notification (2026-10-25)' && mailsTo(V)[2].text.includes('VIENNA-DST'), J(mailsTo(V).map(x => x.subject)));
  285. setClock('2026-11-01T21:00:00Z'); await sleep(ROUNDS); // New York 16:00 EST
  286. check('New York DST day, 21:00 UTC = 16:00 EST: nothing yet', mailsTo(NY).length === 1, J(mailsTo(NY).map(x => x.subject)));
  287. setClock('2026-11-01T22:00:00Z'); await waitMails(8); await sleep(ROUNDS);
  288. check('New York DST day, 22:00 UTC = 17:00 EST: newyork\'s mail, dated 1 Nov', mailsTo(NY).length === 2 && mailsTo(NY)[1].subject === 'ident: 1 notification (2026-11-01)' && mailsTo(NY)[1].text.includes('NEWYORK-DST'), J(mailsTo(NY).map(x => x.subject)));
  289. check('nothing else on those days (no pending = no mail, off still nothing)', mails().length === 8 && mailsTo(OFF).length === 0, J(mails().map(x => x.to + ' ' + x.subject)));
  290. // ==== 7. the user changes the zone on `/`: the hour follows ==================================
  291. console.log('# vienna moves to Australia/Adelaide (+10:30 in November, its summer time) on the account page');
  292. const p = vienna.page;
  293. await p.goto(ID + '/'); await p.waitForSelector('#tzinput'); await ready(p);
  294. await p.type('#tzinput', 'Australia/Adelaide', { clear: true });
  295. await p.click('#savetz');
  296. await p.waitFor('document.querySelector("#timezone").textContent === "Australia/Adelaide"', { label: 'zone saved' });
  297. check('account page: zone changed to Australia/Adelaide (typed, saved)', (await txt(p, '#timezone')) === 'Australia/Adelaide');
  298. const V4 = await send(idV, { name: 'Comment', text: 'VIENNA-NOW-ADELAIDE' });
  299. setClock('2026-11-02T06:29:00Z'); await sleep(ROUNDS); // Adelaide 16:59 ACDT (Vienna would be 07:29)
  300. check('Adelaide 16:59: nothing', mailsTo(V).length === 3);
  301. setClock('2026-11-02T06:30:00Z'); await waitMails(9); await sleep(ROUNDS);
  302. check('Adelaide 17:00 (06:30 UTC): the mail comes at the new zone\'s 17:00, dated its local day', mailsTo(V).length === 4 && mailsTo(V)[3].subject === 'ident: 1 notification (2026-11-02)' && mailsTo(V)[3].text.includes('VIENNA-NOW-ADELAIDE') && mailsTo(V)[3].text.includes('(17:00, Australia/Adelaide)'), J(mailsTo(V).map(x => x.subject)));
  303. setClock('2026-11-02T16:00:00Z'); await sleep(ROUNDS); // Vienna's own 17:00 that day: nothing more
  304. check('…and not again at Vienna\'s 17:00 (one mail per local day)', mailsTo(V).length === 4);
  305. s = store();
  306. check('stored: every daily one mailed except off\'s', [T1, T2, T3, V1, V2, V3, V4, N1, N2, U1].every(id => note(id).mailSent === true) && !note(O1).mailSent && !note(O2).mailSent && !note(OU).mailSent, J(s.notifications.map(n => [n.text.slice(0, 12), n.mail, n.mailSent])));
  307. check('every mail went to the sink (the server log has no SMTP send)', !/mail: sent/.test(log));
  308. // up to the restart: clean. While the gate has the server stopped (section 5) the open pages' socket, hl:web's
  309. // reconnect probe (/__hl/up) and the shell's offline probe (/api/online) fail — expected; nothing else may appear.
  310. const probs = pages.flatMap((x, i) => x.problems().map(q => q.text).filter((t, k) => k < (clean[i] || 0) || !new RegExp('^network: .*127\\.0\\.0\\.1:' + PORT + '/').test(t)));
  311. check('no console errors or warnings (until the restart: none at all; after it: only the stopped server\'s network errors)', probs.length === 0, probs.join(' | '));
  312. } catch (err) {
  313. failed++;
  314. console.log(' FAIL (aborted) ' + (err && err.stack || err));
  315. for (const x of pages) console.log('--- console:\n' + x.dumpConsole());
  316. } finally {
  317. for (const b of browsers) { try { await b.close(); } catch {} }
  318. if (proc) { try { await stopServer(); } catch {} }
  319. await sleep(300);
  320. }
  321. console.log(`\n${passed} passed, ${failed} failed`);
  322. process.exit(failed ? 1 : 0);

Branches

Latest commits

  • 0f6d1592Merge branch 'f18b-shell-session' into mainIdent
  • 19868218|||PR ident#39 shell reads its session member instead of a cross-file emitmre
  • 5d1b3fedMerge branch 'v61-day61' into mainIdent
  • 83faeb15|||PR ident: vendor Hybriel day61mre
  • b2572b34Merge branch 'v59-day59' into mainIdent
  • 67cf016d|||PR ident: vendor Hybriel day59mre
  • 600c043dMerge branch 'v58-day58' into mainIdent
  • 365f8c80|||PR ident: vendor Hybriel day58mre
  • 585126e5Merge branch 'f16-setf' into mainIdent
  • 953bf03a|||PR ident setF mirror dropped (hybriel#370)mre
  • a1419d9cMerge branch 'f15-navigate' into mainIdent
  • 3b3e451f|||PR ident#36 navigate to the app instead of location.assignmre
  • e36f4516Merge branch 'f14-online' into mainIdent
  • 2c5eac91|||PR ident#38 online state without probe timermre
  • bf1980f2Merge branch 'v56-day56' into mainIdent
  • 62ae0adf|||PR ident: vendor Hybriel day56mre
  • 0d18abc4Merge branch 'f13-avatar' into mainIdent
  • 2a99730a|||PR ident#37 avatar in hlmre
  • fa4ed25bMerge branch 'f11-upsert' into mainIdent
  • 8f3d9bc9|||PR ident#42 keyed upsert and removemre