gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit31aac93631aac936tracker#3: no border on the header and on filled buttons; inverted buttons keep theirsmre31aac936/tests/browser.mjs

7.1 KB

  1. // tests/browser.mjs — THE GATE of tracker.worldapi.org#1: this app's own server on its own storage, its OWN ident
  2. // (a copy of ident's code without .env, codes to a mail sink: tests/identkit.mjs, same as calendar's gate), a real
  3. // headless Chrome. Proves: signed out (header shows "Log in with ident") -> sign in -> the header selector shows
  4. // signed in, "Log out" appears, the page itself stays empty -> sign out -> signed out again (a reload confirms it).
  5. //
  6. // node tests/browser.mjs (TRACKER_GATE_PORT server, default 8700; TRACKER_GATE_IDENT_PORT ident, default 8701;
  7. // TRACKER_GATE_CHROME "8702-8709" = Chrome debug ports)
  8. import { spawn } from 'node:child_process';
  9. import { existsSync, mkdirSync, rmSync } from 'node:fs';
  10. import { dirname, join, resolve } from 'node:path';
  11. import { fileURLToPath } from 'node:url';
  12. import { launchBrowser } from './cdp.mjs';
  13. import { startIdent } from './identkit.mjs';
  14. if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';
  15. const HERE = dirname(fileURLToPath(import.meta.url));
  16. const APP = resolve(HERE, '..');
  17. const PORT = Number(process.env.TRACKER_GATE_PORT || 8700);
  18. const [CH_FROM, CH_TO] = (process.env.TRACKER_GATE_CHROME || '8702-8709').split('-').map(Number);
  19. const IDENT_PORT = Number(process.env.TRACKER_GATE_IDENT_PORT || 8701);
  20. const BASE = `http://127.0.0.1:${PORT}`;
  21. const STORE = join(APP, '.scratch', 'gate-store');
  22. const IDENT_DIR = process.env.TRACKER_GATE_IDENT_DIR || [resolve(APP, '../ident.worldapi.org'), '/media/STORAGE/projects/ident.worldapi.org'].find(d => existsSync(join(d, 'project.hl')));
  23. const SCRATCH = join(APP, '.scratch');
  24. const SESSIONS = join(SCRATCH, 'gate-sessions');
  25. rmSync(SESSIONS, { recursive: true, force: true });
  26. rmSync(STORE, { recursive: true, force: true });
  27. mkdirSync(SESSIONS, { recursive: true });
  28. let failures = 0, passes = 0;
  29. function check(label, ok, detail = '') {
  30. console.log(`${ok ? 'ok ' : 'FAIL'} ${label}${ok ? '' : ' — ' + detail}`);
  31. if (ok) passes++; else failures++;
  32. }
  33. let ident = null, server = null, browser = null, log = '';
  34. async function stop() {
  35. if (ident) { try { await ident.stop(); } catch {} ident = null; }
  36. if (browser) { try { await browser.close(); } catch {} browser = null; }
  37. if (server) {
  38. try { server.kill('SIGTERM'); } catch {}
  39. await new Promise(r => { if (server.exitCode !== null || server.signalCode !== null) return r(); server.once('exit', r); setTimeout(r, 3000); });
  40. server = null;
  41. }
  42. }
  43. async function main() {
  44. ident = await startIdent({ identDir: IDENT_DIR, workDir: join(STORE, 'ident'), port: IDENT_PORT });
  45. const alice = await ident.signIn('[email protected]');
  46. const APPKEY = await ident.registerApp(alice, 'tracker (gate)', [BASE]);
  47. check('ident: our own ident runs (a copy without .env), tracker is registered', /^pk_[0-9a-f]{32}$/.test(APPKEY.key) && !existsSync(join(STORE, 'ident', 'ident-code', '.env')));
  48. server = spawn(join(APP, 'bin/hybriel'), ['project.hl'], { cwd: APP, env: { ...process.env, TRACKER_PORT: String(PORT), TRACKER_SESSIONS: SESSIONS + '/', TRACKER_STORAGE: join(STORE, 'mpackdb'), TRACKER_WATCH: '0',
  49. TRACKER_URL: BASE, IDENT_URL: ident.base, IDENT_EXCHANGE_URL: ident.base, TRACKER_KEY: APPKEY.key, TRACKER_SECRET: APPKEY.secret }, stdio: ['ignore', 'pipe', 'pipe'] });
  50. server.stdout.on('data', d => log += d); server.stderr.on('data', d => log += d);
  51. for (let i = 0; ; i++) {
  52. try { if ((await fetch(BASE + '/')).ok) break; } catch {}
  53. if (i > 80) throw new Error('tracker did not come up\n' + log);
  54. await new Promise(r => setTimeout(r, 250));
  55. }
  56. check('tracker is up', true);
  57. browser = await launchBrowser({ debugPortRange: [CH_FROM, CH_TO] });
  58. const page = await browser.newPage();
  59. page.captureNetwork();
  60. const ev = (e) => page.evaluate(e);
  61. const hydrated = () => page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { timeout: 15000, label: 'hydrated' });
  62. const loginAs = async (who) => {
  63. const code = await ident.selectorCode(who, APPKEY, BASE);
  64. await page.goto(BASE + '/login/callback?ident_code=' + code);
  65. await page.waitForSelector('#logout');
  66. await hydrated();
  67. };
  68. // ---- signed out: header shows the selector + "Log in with ident", the page itself is empty ----
  69. await page.goto(BASE + '/');
  70. await hydrated();
  71. check('signed out: the identity selector is in the header', await ev(`!!document.querySelector('#selector')`));
  72. check('signed out: "Log in with ident" shows, no "Log out"', (await ev(`!!document.querySelector('#loginbutton')`)) && !(await ev(`!!document.querySelector('#logout')`)));
  73. check('the page itself stays empty (no centered sign-in)', (await ev(`document.querySelector('main').textContent.trim()`)) === '');
  74. // ---- tracker.worldapi.org#3: no bottom border on the header, no border on filled buttons ----
  75. check('the header has no bottom border', (await ev(`getComputedStyle(document.querySelector('application-header')).borderBottomWidth`)) === '0px');
  76. check('"Log in with ident" has no border', (await ev(`getComputedStyle(document.querySelector('#loginbutton')).borderTopWidth`)) === '0px');
  77. check('the ident selector\'s "choose ident" button has no border', (await ev(`getComputedStyle(document.querySelector('#selector').shadowRoot.querySelector('[part~="button"]')).borderTopWidth`)) === '0px');
  78. let r = await fetch(BASE + '/login/callback', { redirect: 'manual' });
  79. check('login: /login/callback without a code → /login/failed', r.status === 302 && r.headers.get('location') === '/login/failed');
  80. // ---- sign in: the header selector flips to signed in, "Log out" appears, page stays empty ----
  81. await loginAs(alice);
  82. check('signed in: the selector is still in the header, now signed in', (await ev(`!!document.querySelector('#selector')`)) && (await ev(`document.querySelector('#selector').classList.contains('in')`)));
  83. check('signed in: "Log out" shows, no "Log in with ident"', (await ev(`!!document.querySelector('#logout')`)) && !(await ev(`!!document.querySelector('#loginbutton')`)));
  84. check('the page itself stays empty while signed in too', (await ev(`document.querySelector('main').textContent.trim()`)) === '');
  85. check('"Log out" (inverted) keeps its border', (await ev(`getComputedStyle(document.querySelector('#logout')).borderTopWidth`)) !== '0px');
  86. // ---- sign out: back to signed out, a reload confirms the app's own session (not just client state) ----
  87. await page.click('#logout');
  88. await page.waitForSelector('#loginbutton', { timeout: 15000 });
  89. check('sign out returns to the signed-out header', (await ev(`!!document.querySelector('#loginbutton')`)) && !(await ev(`!!document.querySelector('#logout')`)));
  90. await page.goto(BASE + '/');
  91. await hydrated();
  92. check('reload after sign-out stays signed out', (await ev(`!!document.querySelector('#loginbutton')`)) && !(await ev(`!!document.querySelector('#logout')`)));
  93. const problems = page.problems();
  94. check('no console errors/warnings', problems.length === 0, page.dumpConsole());
  95. }
  96. try {
  97. await main();
  98. } catch (e) {
  99. check('gate ran without throwing', false, e.stack || String(e));
  100. } finally {
  101. await stop();
  102. }
  103. console.log(`\n${passes} passed, ${failures} failed`);
  104. process.exit(failures === 0 ? 0 : 1);

Branches

Latest commits

  • 31aac936tracker#3: no border on the header and on filled buttons; inverted buttons keep theirsmre
  • 2ad9d29ctracker#1: login exactly like calendar (identity selector in the header, empty homepage)mre
  • 3691e176tracker#1: empty tracker with the ident login (state of 2026-09-27)mre