gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commiteb7aeeb9eb7aeeb9mission brief 016mreeb7aeeb9/tests/realdata-baseline.mjs

11.8 KB

  1. // tests/realdata-baseline.mjs (mission 010): every read the app answers + a fixed write sequence, on a COPY of the
  2. // LIVE storage, saved for diffing two code trees (a cleanup must answer the same). Compare two outputs with
  3. // tests/realdata-compare.py (reads) and tests/realdata-compare-writes.py (the 'w-' files). README "Test".
  4. // node tests/realdata-baseline.mjs <tree> <port> <outdir> (run in tickets.worldapi.org; kills only the server it started)
  5. // The live copy: TICKETS_REALDATA (default .scratch/realdata) must hold storage/mpackdb, e.g. from Byrodin:
  6. // tar -C /CONTAINERS/projects/tickets.worldapi.org -cf - storage/mpackdb | ssh loreana tar -C <repo>/.scratch/realdata -xf -
  7. // Signed in as the creator (identity az5b2 → users @id 0mufikk6hj1u) through a session file written before the start;
  8. // every HTML page is fetched signed in AND signed out. Writes nothing to the live data (a fresh copy per run).
  9. import { spawn, execSync } from 'node:child_process';
  10. import { writeFileSync, mkdirSync, rmSync } from 'node:fs';
  11. import { createHash, randomBytes } from 'node:crypto';
  12. import { join, resolve } from 'node:path';
  13. const [tree, port, outArg] = process.argv.slice(2);
  14. const W = resolve(process.env.TICKETS_REALDATA || '.scratch/realdata'), OUT = resolve(outArg), RUN = OUT + '.run';
  15. rmSync(RUN, { recursive: true, force: true }); rmSync(OUT, { recursive: true, force: true });
  16. mkdirSync(join(RUN, 'sessions'), { recursive: true }); mkdirSync(OUT, { recursive: true });
  17. execSync(`cp -a ${W}/storage ${RUN}/storage`);
  18. const sid = randomBytes(16).toString('hex'), now = Date.now();
  19. writeFileSync(join(RUN, 'sessions', createHash('sha256').update(sid).digest('hex')),
  20. JSON.stringify({ created: now, data: { tag: 'w080tag' }, handled: [], id: sid, seen: now, user: { id: '0mufikk6hj1u' } }), { mode: 0o600 });
  21. const COOKIE = 'hlsid=' + sid;
  22. const sleep = ms => new Promise(r => setTimeout(r, ms));
  23. const BASE = `http://127.0.0.1:${port}`;
  24. const srv = spawn(resolve(tree, 'bin/hybriel'), ['project.hl'], { cwd: resolve(tree), stdio: ['ignore', 'pipe', 'pipe'],
  25. env: { ...process.env, TICKETS_PORT: port, TICKETS_STORAGE: join(RUN, 'storage/mpackdb'), TICKETS_SESSIONS: join(RUN, 'sessions'),
  26. IDENT_URL: 'http://127.0.0.1:9', IDENT_EXCHANGE_URL: 'http://127.0.0.1:9', TICKETS_PUBLIC_URL: BASE, TICKETS_CREATOR_IDENTITY: '', TICKETS_WATCH: '0', IDENT_API_KEY: 'pk_w080', IDENT_API_SECRET: '' } });
  27. let log = ''; srv.stdout.on('data', d => log += d); srv.stderr.on('data', d => log += d);
  28. let n = 0;
  29. const save = async (name, url, opts = {}) => {
  30. const r = await fetch(BASE + url, { redirect: 'manual', ...opts });
  31. const body = await r.text();
  32. const head = [r.status, r.headers.get('content-type'), r.headers.get('location') || ''].join(' | ');
  33. // the session's own cookie / the server's hashed asset urls are the same in both runs; nothing is masked
  34. writeFileSync(join(OUT, String(++n).padStart(4, '0') + '-' + name.replace(/[^a-zA-Z0-9._-]+/g, '_').slice(0, 120)), head + '\n' + body);
  35. return { status: r.status, body };
  36. };
  37. try {
  38. for (let i = 0; i < 240; i++) { try { if ((await fetch(BASE + '/api/projects')).ok) break; } catch {} await sleep(500); }
  39. const projects = JSON.parse((await save('api-projects', '/api/projects')).body).details;
  40. const pages = ['/', '/inbox', '/you', '/new-project', '/state/open', '/state/review', '/state/done', '/nope', '/connect/ffff', '/projects/nosuch', '/projects/nosuch/1'];
  41. const apis = ['/api/tickets', '/api/tickets?state=open', '/api/tickets?state=awaiting-creator', '/api/tickets?state=bogus', '/api/inbox',
  42. '/api/projects/nosuch', '/api/tickets/99999', '/api/tickets/zzzz', '/connect', '/connect?app=x&return=https://evil.example/&state=s', '/login/callback', '/login/callback?ident_code=zz', '/tickets/1', '/tickets/38', '/tickets/9999'];
  43. for (const p of projects) {
  44. pages.push('/projects/' + p.slug, '/project/' + p.slug, '/projects/' + p.slug + '/settings', '/project/' + p.slug + '/state/open');
  45. apis.push('/api/projects/' + p.slug, '/api/projects/' + p.slug + '/tickets', '/api/projects/' + p.slug + '/tickets?state=done', '/api/projects/' + p.slug + '/connections', '/api/tickets?project=' + p.slug);
  46. const ts = JSON.parse((await save('list-' + p.slug, '/api/projects/' + p.slug + '/tickets')).body).tickets || [];
  47. for (const t of ts) { pages.push(t.href); apis.push(t.apiHref, '/api/tickets/' + t.id); if (t.oldNumber != null) apis.push('/api/tickets/' + t.oldNumber); }
  48. }
  49. for (const u of pages) { await save('in' + u, u, { headers: { cookie: COOKIE } }); await save('out' + u, u); }
  50. for (const u of apis) { await save('json' + u, u); await save('md' + u, u, { headers: { accept: 'text/markdown' } }); }
  51. // refusals that write nothing: no token, a bad token, bad JSON with a bad token (auth first), wrong method
  52. const posts = ['/api/tickets', '/api/projects', '/api/projects/' + projects[0].slug + '/members', '/api/connect/exchange', '/api/tickets/' + 'x/comments'];
  53. for (const u of posts) {
  54. await save('post-none' + u, u, { method: 'POST', body: '{"text":"x"}' });
  55. await save('post-badtok' + u, u, { method: 'POST', body: '{nope', headers: { authorization: 'Bearer tkt_' + '0'.repeat(48) } });
  56. await save('put' + u, u, { method: 'PUT', body: '{}' });
  57. }
  58. await save('exchange-badjson', '/api/connect/exchange', { method: 'POST', body: '{"code":' });
  59. await save('exchange-unknown', '/api/connect/exchange', { method: 'POST', body: '{"code":"abcdef"}' });
  60. // WRITES (same sequence on old and new code, each on its own fresh copy): a token over the face, then API writes and
  61. // faces as the creator; every answer and the pages / reads of what changed are saved ('w-' files; compare-writes masks
  62. // the new ids and times)
  63. let ei = 0;
  64. const emitF = async (name, event, payload) => {
  65. const r = await fetch(BASE + '/__hl/emit', { method: 'POST', headers: { 'content-type': 'application/json', cookie: COOKIE }, body: JSON.stringify({ t: 'emit', i: ++ei, event, payload }) });
  66. const body = await r.text();
  67. writeFileSync(join(OUT, String(++n).padStart(4, '0') + '-w-face-' + name), r.status + '\n' + body);
  68. try { return JSON.parse(body).value; } catch { return null; }
  69. };
  70. const tok = (await emitF('tokenCreate', 'tokenCreate', ['w080'])).token;
  71. const P = '/api/projects/tickets.worldapi.org';
  72. const send = (name, method, url, body) => save('w-' + name, url, { method, headers: { authorization: 'Bearer ' + tok, 'content-type': 'application/json' }, body: body == null ? undefined : JSON.stringify(body) });
  73. const made = JSON.parse((await send('create', 'POST', P + '/tickets', { subject: 'W080 write check', summary: '**bold** and `code`\n\n- a\n- b' })).body);
  74. const T = P + '/tickets/' + made.ticket.number, U = '/api/tickets/' + made.ticket.id;
  75. await send('create-again-source', 'POST', '/api/tickets', { project: 'tickets.worldapi.org', subject: 'W080 sourced', source: 'w080-source.md' });
  76. await send('create-again-source2', 'POST', '/api/tickets', { project: 'tickets.worldapi.org', subject: 'W080 sourced', source: 'w080-source.md' });
  77. await send('comment', 'POST', T + '/comments', { text: 'a *comment*' });
  78. await send('comment-empty', 'POST', T + '/comments', { text: ' ' });
  79. await send('comment-author', 'POST', T + '/comments', { text: 'x', author: 'me' });
  80. await send('state-progress', 'POST', T + '/state', { state: 'in progress', text: 'note' });
  81. await send('state-same', 'POST', T + '/state', { state: 'progress' });
  82. await send('state-bad', 'POST', T + '/state', { state: 'nope' });
  83. await send('state-review', 'POST', U + '/state', { state: 'awaiting creator' });
  84. await send('assign-nobody', 'POST', T + '/assign', { assignee: '' });
  85. await send('assign-again', 'POST', T + '/assign', { assignee: '' });
  86. await send('assign-unknown', 'POST', T + '/assign', { assignee: 'nobody-here' });
  87. await send('assign-me', 'POST', T + '/assign', { assignee: 'Caramboleyo' });
  88. await send('edit', 'POST', T + '/edit', { subject: 'W080 write check (edited)', summary: 'new *summary*' });
  89. await send('edit-same', 'POST', T + '/edit', { subject: 'W080 write check (edited)' });
  90. await send('parent', 'POST', T + '/parent', { parent: 'tickets.worldapi.org#1' });
  91. await send('parent-self', 'POST', T + '/parent', { parent: 'tickets.worldapi.org#' + made.ticket.number });
  92. await send('blocker-add', 'POST', U + '/blocked-by', { add: 'tickets.worldapi.org # 2' });
  93. await send('blocker-twice', 'POST', T + '/blocked-by', { add: 'tickets.worldapi.org#2' });
  94. await send('blocker-both', 'POST', T + '/blocked-by', { add: 'x', remove: 'y' });
  95. await send('blocker-remove', 'POST', T + '/blocked-by', { remove: 'tickets.worldapi.org#2' });
  96. await send('parent-remove', 'POST', T + '/parent', { parent: '' });
  97. await send('newproject', 'POST', '/api/projects', { title: 'W080 Project!', description: 'd' });
  98. await send('newproject-dup', 'POST', '/api/projects', { title: 'x', slug: 'w080-project' });
  99. await send('project-update', 'POST', '/api/projects/w080-project', { slug: 'w080-renamed', description: 'changed' });
  100. await send('project-old-slug', 'GET', '/api/projects/w080-project');
  101. await send('members-add-unknown', 'POST', '/api/projects/w080-renamed/members', { user: 'nobody-here', role: 'use' });
  102. await send('members-bad-role', 'POST', '/api/projects/w080-renamed/members', { user: 'Caramboleyo', role: 'king' });
  103. await send('members-last-admin', 'POST', '/api/projects/w080-renamed/members', { user: 'Caramboleyo', role: 'use' });
  104. await send('members-remove-last', 'POST', '/api/projects/w080-renamed/members/remove', { user: 'Caramboleyo' });
  105. await send('invite-bad-role', 'POST', '/api/projects/w080-renamed/invites', { role: 'king' });
  106. await send('invite-bad-uses', 'POST', '/api/projects/w080-renamed/invites', { role: 'use', uses: '0' });
  107. await send('invite-no-ident', 'POST', '/api/projects/w080-renamed/invites', { role: 'use' });
  108. await send('disconnect-unknown', 'POST', '/api/projects/w080-renamed/connections/remove', { id: 'zzz' });
  109. await send('inbox', 'GET', '/api/inbox');
  110. await emitF('commentOn', 'commentOn', [made.ticket.id, 'face comment']);
  111. await emitF('setTicketState', 'setTicketState', [made.ticket.id, 'done', 'closing']);
  112. await emitF('ticketRights', 'ticketRights', [made.ticket.id]);
  113. await emitF('ticketEdit-bad', 'ticketEdit', [made.ticket.id, 5, 'x']);
  114. await emitF('ticketAddBlocker', 'ticketAddBlocker', [made.ticket.id, 'tickets.worldapi.org#3']);
  115. await emitF('whatICanOpen', 'whatICanOpen', ['tickets.worldapi.org']);
  116. await emitF('myInbox', 'myInbox', []);
  117. await emitF('myInboxCount', 'myInboxCount', []);
  118. await emitF('youData', 'youData', []);
  119. await emitF('proposeSlug', 'proposeSlug', ['W080 Project!']);
  120. await emitF('settingsInvite-role', 'settingsInvite', [made.ticket.projectId, 'king', '1', '7', '']);
  121. await emitF('settingsInvite-uses', 'settingsInvite', [made.ticket.projectId, 'use', '0', '7', '']);
  122. await emitF('settingsRemove-last', 'settingsRemove', [made.ticket.projectId, '0mufikk6hj1u']);
  123. await emitF('connectChoices', 'connectChoices', []);
  124. for (const u of [T, U, '/api/tickets/' + made.ticket.id, '/api/projects/tickets.worldapi.org/tickets/1', '/api/projects/tickets.worldapi.org/tickets/2', '/api/projects/w080-renamed', '/api/projects']) {
  125. const nm = u.replace(made.ticket.id, 'NEWID'); await save('w-read' + nm, u); await save('w-md' + nm, u, { headers: { accept: 'text/markdown' } });
  126. }
  127. for (const u of [made.ticket.href, '/projects/tickets.worldapi.org/1', '/projects/tickets.worldapi.org', '/inbox', '/you', '/projects/w080-renamed/settings', '/projects/w080-project']) {
  128. await save('w-page' + u, u, { headers: { cookie: COOKIE } });
  129. }
  130. console.log(`${n} responses saved to ${OUT} (${pages.length} pages ×2, ${apis.length} api urls ×2, + writes)`);
  131. } finally { srv.kill('SIGTERM'); await sleep(1000); try { process.kill(srv.pid, 'SIGKILL'); } catch {} }
  132. writeFileSync(join(OUT, '0000-server-log'), log.split('\n').filter(l => !/listening|watch/i.test(l)).join('\n'));
  133. rmSync(RUN, { recursive: true, force: true });

Branches

Latest commits

  • eb7aeeb9mission brief 016mre
  • e4c34759paths: projects moved into /media/STORAGE/projects/WorldAPI/mre
  • 26efb23freport w6-events (events test)mre
  • c6bfab04mission 015: re-vendor Hybriel 0f396652 (static build), reportmre
  • b7ec5981mission brief 015mre
  • 5dc68731docker-compose: init: true (hybriel#156, PID 1 ignored SIGTERM, every restart waited 10 s)mre
  • 8a460b16mission 014: Apollo's 'stream opened right after the start gets no live events' is not a tickets bug — events.mjs checks early streamsmre
  • 6309ca81mission brief 014mre
  • c1161469mission 013: GitHub pipe tables on ticket pages (lib/markdown.hl + View + CSS) and re-vendor hybriel master a832f73bmre
  • a30b5d12mission brief (w13)mre
  • b50a6f93w9 (tickets): re-vendor hybriel 9f912f3b (#146 emit in a lib static, #147) — the 12 live-push emits in lib/api.hl compile as they are; cold start (#148): tests wait TICKETS_COLD_MS for every start, deploy.sh gates browser + events and waits up to 120 s for the URL, container /tmp tmpfs + hybriel-cache volume; events-client stops at EVENTS_MAX inside a chunk; connect.mjs ports by env. bin/hybriel sha256 7421907868ac07d8a7d08296b083c6f8b20407d0e099ce4bebbf7ae053d9060a. Gates (8720–8739): browser 315/0 (+ all-cold 315/0), events 48/0 cold, connect 60/0, short-id 19/0; real-data copy old 0e8a41c vs new: 2,425 reads + 72 writes identical after masking ?v hashes, offline at, route order; event stream on the copy delivers. Not deployed.mre
  • 43be6578w9: re-vendor hybriel master edfd400a; event stream imports sseStart/sseSend/sseAlive from hl:http1 (hybriel#144), useTransport gone; tools/import.hl plain declarations. BLOCKED: hybriel-native refuses `emit client` in a static (lib/api.hl) — the server does not compile on edfd400a, gates fail at start; scratch copy without those emits: events 48/0, gate 254 ok up to the first live pushmre
  • 0e8a41caw6 (ticket #26): event stream for programs — GET /api/events (Server-Sent Events)mre
  • bb64d57cmission 012 (ticket #25 API part): every /api/projects/<x>/… route takes the project's id (12-char record id) as well as its slug, same answers byte for byte; tickets stay under their project, no global /api/tickets/<x>. gate 315/0 (old code: the 13 id checks fail), connect 60/0, live-data copy old vs new 1,484 identical, slug vs id 772 identicalmre
  • 7538b034mission 011 (ticket #25 web part): short page URLs /<slug> and /<slug>/<number>; /projects/<slug>, /projects/<slug>/<n>, /projects/<slug>/tickets/<n> and /tickets/<ref> answer 301 (current slug); slug pages moved behind hl:web's own routes after construction (they answered /__hl/* and /components/*.hl); reserved slugs refused; API paths unchanged. gate 293/0, connect 60/0, live-data copy 187/0, API old vs new: only page links differmre
  • 0369106emission 010 (code order) 4/4: README file map + import order + 'Same output' test, STATUS (entry, lessons, how to verify), LOG, report; tests/realdata-baseline.mjs + realdata-compare*.py (a cleanup answers the same on live data), tests/letcount.pymre
  • a75e0279mission 010 (code order) 3/4: let only where a variable is reassigned or re-bound in a loop body (456 lets → plain declarations; Hybriel refuses a plain declaration inside a loop on its 2nd pass). gate 249/0, connect 60/0, real-data reads identical, a 50-step write sequence (API + faces) identical to the old codemre
  • e9d5c618mission 010 (code order) 2/4: one lib/ file per topic — store.hl split into projects / tickets (+ relations) / events / tickets-helpers, util.hl shared helpers (env, storage dir, URLs, sorts, Vienna time), the function routes out of project.hl into lib/api.hl (thin; auth/filters/Accept in api-helpers.hl), invite + member-removal logic out of the faces/routes into invites.hl / tickets.hl; project.hl is the map. /login/callback gets req + the session store by reference. gate 249/0, connect 60/0, real-data reads identicalmre
  • 97e269b5mission 010 (code order) 1/4: .hl files out of the root — lib/ (store, users, connections, invites, migrate, markdown, mdview, import = ticketfile, util = localtime, jsoncheck, api-helpers = api), tools/import.hl, components/styles.hl; import paths only. gate 249/0, connect 60/0, real-data reads identicalmre
  • 38f9d10ftickets: Hybriel master 06617221 (plugin allocators 3a781359 + 413f60e4, mpackdb 2cb7ae5e, http1 773de63e); gate 249/0, connect 60/0mre