gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit54bc5fe154bc5fe1Harden delta relevance, overflow caps and retry verificationmre54bc5fe1/tests/short-id-switch.mjs

22.8 KB

  1. // tests/short-id-switch.mjs — THE SHORT-ID SWITCH GATE of tickets.worldapi.org (mission 039, ident#23), all over HTTP, no browser:
  2. // 1. the OLD ident (the pre-ident#23 build, a copy of its code: OLD_IDENT_DIR, default
  3. // ident.worldapi.org/.scratch/pre-023-ident) + this app on a fresh store: alice (Default AND a second identity
  4. // "Work") and bob log in and make data; alice's "Work" identity is deleted in ident afterwards;
  5. // 2. both stop; the ident store and the app store are COPIED (the originals stay as they were);
  6. // 3. the NEW ident (ident#23's dev build, a copy of ident.worldapi.org's code: NEW_IDENT_DIR) on the ident copy;
  7. // 4. CONTROL: the app on an UNMIGRATED copy → alice comes back as a NEW user (why the migration is needed);
  8. // 5. tools/migrate-short-ids.hl on the other copy, TWICE: counts; the second run changes nothing;
  9. // 6. the app on the migrated copy with the new ident: alice's OLD app session still works; a fresh login through the
  10. // new ident finds the SAME user with the SAME data; bob too; nobody sees the other's data.
  11. // Ports 8726, 8727 (ident, app). Work dir .scratch/m039-switch (wiped at start). Every process started is stopped by PID.
  12. // node tests/short-id-switch.mjs
  13. import { spawn, execFileSync } from 'node:child_process';
  14. import { cpSync, mkdirSync, readFileSync, rmSync, existsSync, writeFileSync } from 'node:fs';
  15. import { dirname, join, resolve } from 'node:path';
  16. import { fileURLToPath } from 'node:url';
  17. import { copyIdent } from './identkit.mjs';
  18. const HERE = dirname(fileURLToPath(import.meta.url));
  19. const APP = resolve(HERE, '..');
  20. const BIN = join(APP, 'bin/hybriel');
  21. const PROJECTS = resolve(APP, '..');
  22. const NEW_IDENT_DIR = process.env.NEW_IDENT_DIR || join(PROJECTS, 'ident.worldapi.org');
  23. const OLD_IDENT_DIR = process.env.OLD_IDENT_DIR || join(PROJECTS, 'ident.worldapi.org/.scratch/pre-023-ident');
  24. const IDENT_PORT = Number(process.env.SWITCH_IDENT_PORT || 8706), PORT = Number(process.env.SWITCH_PORT || 8707);
  25. const ID = `http://127.0.0.1:${IDENT_PORT}`;
  26. const BASE = `http://127.0.0.1:${PORT}`;
  27. const W = join(APP, '.scratch/m039-switch');
  28. const J = JSON.stringify;
  29. const sleep = (ms) => new Promise(r => setTimeout(r, ms));
  30. const COLD_MS = Number(process.env.TICKETS_COLD_MS || 120000); // cold compile at a start (hybriel#148)
  31. const SHORT = /^[2-9a-hj-km-np-z]{5}$/;
  32. const OLD = /^[0-9a-f]{32}$/;
  33. let passed = 0, failed = 0;
  34. const check = (name, ok, detail = '') => {
  35. if (ok) { passed++; console.log(' ok ' + name); } else { failed++; console.log(' FAIL ' + name + (detail ? ' — ' + detail : '')); }
  36. };
  37. let log = '';
  38. const procs = new Set();
  39. function start(label, bin, args, cwd, env) {
  40. log += `\n==== ${label}\n`;
  41. const p = spawn(bin, args, { cwd, env: { ...process.env, ...env }, stdio: ['ignore', 'pipe', 'pipe'] });
  42. p.stdout.on('data', d => log += d); p.stderr.on('data', d => log += d);
  43. procs.add(p);
  44. return p;
  45. }
  46. async function stop(p) {
  47. if (!p) return;
  48. try { p.kill('SIGTERM'); } catch {}
  49. await new Promise(r => { if (p.exitCode !== null || p.signalCode !== null) return r(); p.once('exit', r); setTimeout(r, 3000); });
  50. procs.delete(p);
  51. }
  52. async function up(url, what) {
  53. for (const end = Date.now() + COLD_MS; Date.now() < end;) { try { const r = await fetch(url, { redirect: 'manual' }); if (r.status < 500) return; } catch {} await sleep(250); }
  54. throw new Error(what + ' did not come up\n' + log.slice(-3000));
  55. }
  56. // ---- ident (old or new code, on a given data dir; codes go to a mail sink — never real mail) -------------------
  57. async function startIdentOn(codeDir, dataDir) {
  58. mkdirSync(dataDir, { recursive: true });
  59. const sink = join(dataDir, 'mail.txt');
  60. if (!existsSync(sink)) writeFileSync(sink, '');
  61. const p = start('ident ' + codeDir, join(codeDir, 'bin/hybriel'), ['project.hl'], codeDir, {
  62. IDENT_PORT: String(IDENT_PORT), IDENT_STORAGE: join(dataDir, 'mpackdb'), IDENT_SESSIONS: join(dataDir, 'sessions') + '/',
  63. IDENT_MAIL_SINK: sink, IDENT_IP_LIMIT: '1000', IDENT_IP_DAY_LIMIT: '1000', IDENT_WATCH: '0', HL_HOST: '127.0.0.1',
  64. SMTP_HOST: '', SMTP_USER: '', SMTP_PASSWORD: '' });
  65. await up(ID + '/', 'ident');
  66. return { p, sink };
  67. }
  68. let iemitI = 0;
  69. async function identEmit(event, payload, cookie) {
  70. const r = await fetch(ID + '/__hl/emit', { method: 'POST', headers: { 'content-type': 'application/json', ...(cookie ? { cookie } : {}) }, body: J({ t: 'emit', i: ++iemitI, event, payload }) });
  71. const t = await r.text(); let j = null; try { j = JSON.parse(t); } catch {}
  72. return { value: j && j.value, raw: t, setCookie: (r.headers.get('set-cookie') || '').split(';')[0] };
  73. }
  74. async function identSignIn(sink, email) {
  75. const c = await fetch(ID + '/api/code', { method: 'POST', headers: { 'content-type': 'application/json' }, body: J({ email }) });
  76. if (c.status !== 200) throw new Error('ident code refused: ' + c.status);
  77. const code = readFileSync(sink, 'utf8').trim().split('\n').filter(l => l.startsWith(email + ' ')).pop().split(' ')[1];
  78. const v = await identEmit('verifyCode', [email, code, 'Europe/Vienna']);
  79. if (!v.value || !v.value.account) throw new Error('ident sign-in failed: ' + v.raw);
  80. return { email, cookie: v.setCookie, identities: v.value.identities };
  81. }
  82. // the selector's path: identities (as the app's page asks) → choose → one-time code
  83. async function selectorCode(who, app, identityName = null) {
  84. const l = await (await fetch(ID + '/api/selector/identities?key=' + app.key, { headers: { origin: BASE, cookie: who.cookie } })).json();
  85. if (!l.identities || !l.identities.length) throw new Error('no identities: ' + J(l));
  86. const pick = identityName ? l.identities.find(i => i.name === identityName) : l.identities[0];
  87. if (!pick) throw new Error('no identity named ' + identityName + ': ' + J(l));
  88. const c = await (await fetch(ID + '/api/selector/choose?key=' + app.key, { method: 'POST', headers: { origin: BASE, cookie: who.cookie, 'content-type': 'application/json' }, body: J({ identity: pick.id }) })).json();
  89. if (!c.code) throw new Error('choose failed: ' + J(c));
  90. return c.code;
  91. }
  92. // ---- the app -----------------------------------------------------------------------------------------------------
  93. async function startApp(codeDir, store, app, extra = {}) {
  94. const p = start('tickets.worldapi.org on ' + store, join(codeDir, 'bin/hybriel'), ['project.hl'], codeDir, {
  95. ...appEnv(store), HL_HOST: '127.0.0.1', IDENT_URL: ID, IDENT_EXCHANGE_URL: ID, IDENT_API_KEY: app.key, IDENT_API_SECRET: app.secret, ...extra });
  96. await up(BASE + '/', 'tickets.worldapi.org');
  97. return p;
  98. }
  99. // the login button's / selector's landing: <app>/login/callback?ident_code= → the app's session cookie
  100. async function appLogin(who, app, identityName = null, cookie = null) {
  101. const code = await selectorCode(who, app, identityName);
  102. const r = await fetch(BASE + '/login/callback?ident_code=' + code, { redirect: 'manual', headers: cookie ? { cookie } : {} });
  103. const loc = r.headers.get('location') || '';
  104. if (r.status !== 302 || loc.startsWith('/login/failed')) {
  105. let why = r.status !== 302 ? (await r.text()).replace(/<(style|script)[\s\S]*?<\/(style|script)>/g, " ").replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 200) : '';
  106. const sc = (r.headers.get('set-cookie') || '').split(';')[0] || cookie;
  107. if (r.status === 302) try { why = await (await fetch(BASE + '/login/failed', { headers: sc ? { cookie: sc } : {} })).text(); why = (why.match(/login failed[^<]*|ident refused[^<]*|that is not[^<]*/i) || [why.slice(0, 200)])[0]; } catch {}
  108. return { error: 'login failed (' + r.status + ' → ' + loc + ') ' + why };
  109. }
  110. return { cookie: (r.headers.get('set-cookie') || '').split(';')[0] || cookie };
  111. }
  112. let aemitI = 0;
  113. async function appEmit(cookie, event, payload) {
  114. const r = await fetch(BASE + '/__hl/emit', { method: 'POST', headers: { 'content-type': 'application/json', cookie }, body: J({ t: 'emit', i: ++aemitI, event, payload }) });
  115. const t = await r.text(); let j = null; try { j = JSON.parse(t); } catch {}
  116. return j && j.value !== undefined ? j.value : { error: 'no value: ' + t.slice(0, 300) };
  117. }
  118. const runTool = (store, app) => execFileSync(BIN, ['tools/migrate-short-ids.hl'], { cwd: APP, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'],
  119. env: { ...process.env, ...appEnv(store), IDENT_EXCHANGE_URL: ID, IDENT_URL: ID, IDENT_API_KEY: app.key, IDENT_API_SECRET: app.secret } });
  120. const counts = (out) => { const m = out.match(/users seen (\d+), mapped (\d+), already short (\d+), unmapped (\d+), conflicts (\d+), failed (\d+)/); return m ? m.slice(1).map(Number) : null; };
  121. import { readdirSync } from 'node:fs';
  122. // ---- tickets: what a user has — display name, tickets written (events/links `user` = users @id), API tokens, and the
  123. // CREATOR role (env TICKETS_CREATOR_IDENTITY = an ident id → the tool prints its new value) ------------------------------
  124. // tickets' users.hl (NOT changed by mission 039: the folder holds held tickets#20 work) refuses an exchange answer that is
  125. // not hex (`!isHex(j.identity, 64)`) — a short id like `a68sz` is refused. So the app runs from a COPY of its code in
  126. // which that one check is widened the way gitoria/notes/calendar were (unless the folder already has it); the gate ALSO
  127. // shows that the unchanged code cannot log anyone in after the switch.
  128. let creatorOld = null;
  129. let appCode = null;
  130. const HEX_CHECK = '!isHex(j.identity, 64)';
  131. const appEnv = (store) => ({ TICKETS_PORT: String(PORT), TICKETS_STORAGE: join(store, 'mpackdb'), TICKETS_SESSIONS: join(store, 'sessions'),
  132. TICKETS_WATCH: '0', TICKETS_PUBLIC_URL: BASE, TICKETS_CREATOR_IDENTITY: creatorOld || '' });
  133. const SKIP_CODE = new Set(['.env', 'storage', '.sessions', '.scratch', 'server.log', 'server.pid', '.git']);
  134. const unpatched = () => readFileSync(join(APP, 'lib/users.hl'), 'utf8').includes(HEX_CHECK);
  135. async function prepareCode() {
  136. if (!unpatched()) { console.log(' (tickets\' users.hl already accepts short ids — running the folder itself)'); appCode = APP; return APP; }
  137. const to = join(W, 'tickets-code');
  138. mkdirSync(to, { recursive: true });
  139. for (const e of readdirSync(APP)) if (!SKIP_CODE.has(e)) cpSync(join(APP, e), join(to, e), { recursive: true });
  140. if (existsSync(join(to, '.env'))) throw new Error('a .env was copied — refusing');
  141. const u = readFileSync(join(to, 'lib/users.hl'), 'utf8');
  142. const fn = `static isIdentId = (s) => {
  143. if (s == null || hlTypeName(s) != 'String' || s.length == 0 || s.length > 64) { return false }
  144. let i = 0
  145. while (i < s.length) {
  146. let c = s.charCodeAt(i)
  147. if (!((c >= 48 && c <= 57) || (c >= 97 && c <= 122))) { return false }
  148. i = i + 1
  149. }
  150. return true
  151. }
  152. `;
  153. writeFileSync(join(to, 'lib/users.hl'), u.replace(HEX_CHECK, '!isIdentId(j.identity)').replace('// THE EXCHANGE:', fn + '// THE EXCHANGE:'));
  154. console.log(' (tickets runs from a COPY whose users.hl accepts short ids: ' + to + ')');
  155. appCode = to;
  156. return to;
  157. }
  158. const firstEnv = async () => ({});
  159. const laterEnv = async (mig) => ({ TICKETS_CREATOR_IDENTITY: (mig.ids || {})[creatorOld] || '' });
  160. const wapi = async (method, path, token, body) => {
  161. const r = await fetch(BASE + path, { method, headers: { ...(body ? { 'content-type': 'application/json' } : {}), ...(token ? { authorization: 'Bearer ' + token } : {}) }, body: body ? J(body) : undefined });
  162. let json = null; try { json = await r.json(); } catch {}
  163. return { status: r.status, json };
  164. };
  165. async function makeData(ca, cb, cw) {
  166. const out = {};
  167. // ticket #20: a ticket needs a role — alice opens the project m039 (its admin) and makes bob and Workname `edit`
  168. for (const [who, cookie, name] of [['alice', ca, 'Alice'], ['bob', cb, 'Bob'], ['work', cw, 'Workname']]) {
  169. const n = await appEmit(cookie, 'saveDisplayName', [name]);
  170. const k = await appEmit(cookie, 'tokenCreate', ['laptop']);
  171. const y = await appEmit(cookie, 'youData', []);
  172. out[who] = { name, token: k && k.token, oldId: y && y.identity, ok: n && !n.error && k && !k.error };
  173. }
  174. const pr = await wapi('POST', '/api/projects', out.alice.token, { title: 'm039' });
  175. const m1 = await wapi('POST', '/api/projects/m039/members', out.alice.token, { user: 'Bob', role: 'edit' });
  176. const m2 = await wapi('POST', '/api/projects/m039/members', out.alice.token, { user: 'Workname', role: 'edit' });
  177. for (const w of ['alice', 'bob', 'work']) {
  178. const t = await wapi('POST', '/api/projects/m039/tickets', out[w].token, { subject: out[w].name + '\'s ticket', summary: 'written before the switch' });
  179. out[w].ticket = t.json && t.json.ticket && t.json.ticket.id;
  180. out[w].ok = out[w].ok && !!out[w].ticket;
  181. }
  182. out.alice.ok = out.alice.ok && pr.status === 201 && m1.status < 300 && m2.status < 300;
  183. out.alice.other = out.bob.ticket; out.bob.other = out.alice.ticket;
  184. creatorOld = out.alice.oldId; // alice is the creator from now on
  185. check('old world: three users with names, a ticket and a token each; /you shows the OLD per-app id (32 hex)',
  186. ['alice', 'bob', 'work'].every(w => out[w].ok && /^tkt_/.test(out[w].token || '') && OLD.test(out[w].oldId || '')), J(out).slice(0, 600));
  187. return out;
  188. }
  189. async function toolExtra(r1, r2, mig, app, alice) {
  190. const want = (mig.ids || {})[creatorOld];
  191. check('the tool prints TICKETS_CREATOR_IDENTITY\'s new value (alice\'s short id), both runs',
  192. !!want && r1.includes('set TICKETS_CREATOR_IDENTITY=' + want + ' in .env') && r2.includes('set TICKETS_CREATOR_IDENTITY=' + want + ' in .env'), (r1.match(/TICKETS_CREATOR_IDENTITY.*/) || [''])[0]);
  193. if (!unpatched()) return;
  194. // the UNCHANGED tickets code on a throw-away copy of the migrated store: the new ident's answer is refused
  195. cpSync(join(W, 'app-store-migrated'), join(W, 'app-store-unpatched'), { recursive: true });
  196. const p = await startApp(APP, join(W, 'app-store-unpatched'), app, await laterEnv(mig));
  197. const l = await appLogin(alice, app);
  198. await stop(p);
  199. if (/^[0-9a-f]+$/.test(want)) { console.log(' skip the unchanged-code check: alice\'s short id ' + want + ' happens to be hex'); return; }
  200. check('the UNCHANGED tickets code (users.hl isHex) can NOT log alice in after the switch — tickets needs the users.hl change first',
  201. !!l.error, J(l).slice(0, 300));
  202. console.log(' | unchanged code: ' + (l.error || 'logged in?!'));
  203. }
  204. async function isNewEmptyUser(cookie, before) {
  205. const y = await appEmit(cookie, 'youData', []);
  206. return y && y.named === false && SHORT.test(y.identity || '') && y.identity !== before.alice.oldId;
  207. }
  208. async function sameUser(label, cookie, who, mig) {
  209. const y = await appEmit(cookie, 'youData', []);
  210. // ticket #20: the token made before still acts as the same user — with the same role in m039 (alice admin, the others edit)
  211. const members = (await wapi('GET', '/api/projects/m039')).json.members || [];
  212. const role = (members.find(m => m.name === who.name) || {}).role;
  213. const edit = await wapi('POST', `/api/tickets/${who.ticket}/edit`, who.token, { summary: 'edited after the switch: ' + label });
  214. const other = who.name === 'Bob' ? await wapi('POST', `/api/tickets/${who.other}/edit`, who.token, { summary: 'bob edits alice\'s (role edit): ' + label }) : { status: 200 };
  215. const want = mig ? mig.ids[who.oldId] : null;
  216. check(label + ': the SAME user — name ' + who.name + ', the token made before still works, role ' + (who.name === 'Alice' ? 'admin' : 'edit') + ' kept' + (mig ? ', /you shows the short id' : ''),
  217. y && y.name === who.name && (y.tokens || []).some(t => t.label === 'laptop') && role === (who.name === 'Alice' ? 'admin' : 'edit') && edit.status < 300 && other.status < 300 && (!mig || y.identity === want),
  218. J([y, role, edit, other, want]).slice(0, 500));
  219. }
  220. let identP = null, appP = null;
  221. try {
  222. rmSync(W, { recursive: true, force: true });
  223. mkdirSync(W, { recursive: true });
  224. const oldCode = join(W, 'ident-old-code'), newCode = join(W, 'ident-new-code');
  225. copyIdent(OLD_IDENT_DIR, oldCode);
  226. copyIdent(NEW_IDENT_DIR, newCode);
  227. const oldIsOld = !readFileSync(join(oldCode, 'store.hl'), 'utf8').includes('shortId');
  228. const newIsNew = readFileSync(join(newCode, 'project.hl'), 'utf8').includes('migrate-ids');
  229. check('the old ident has no short ids, the new one has /api/migrate-ids', oldIsOld && newIsNew);
  230. const CODE = await prepareCode();
  231. // ---- 1. the OLD world -------------------------------------------------------------------------------------------
  232. console.log('# 1. old ident + tickets.worldapi.org, data made');
  233. let id = await startIdentOn(oldCode, join(W, 'ident-data'));
  234. identP = id.p;
  235. const alice = await identSignIn(id.sink, '[email protected]');
  236. const bob = await identSignIn(id.sink, '[email protected]');
  237. const added = await identEmit('addIdentity', [{ identityName: 'Work' }], alice.cookie);
  238. const work = added.value && added.value.identities ? added.value.identities.find(i => i.identityName === 'Work') : null;
  239. const reg = await identEmit('appCreate', [{ name: 'tickets.worldapi.org', origins: [BASE] }], alice.cookie);
  240. if (!reg.value || !reg.value.secret) throw new Error('appCreate failed: ' + reg.raw);
  241. const app = { key: reg.value.app.apiKey, secret: reg.value.secret };
  242. writeFileSync(join(W, 'test-app-key.json'), J(app)); // the THROW-AWAY test app's key (for a by-hand rerun of the tool)
  243. appP = await startApp(CODE, join(W, 'app-store'), app, await firstEnv());
  244. const a1 = await appLogin(alice, app), b1 = await appLogin(bob, app);
  245. const w1 = await appLogin(alice, app, 'Work');
  246. check('old ident: alice, bob and alice\'s "Work" log in to tickets.worldapi.org', !a1.error && !b1.error && !w1.error && work != null, J([a1.error, b1.error, w1.error]));
  247. const before = await makeData(a1.cookie, b1.cookie, w1.cookie);
  248. await stop(appP); appP = null;
  249. const dropped = await identEmit('dropIdentity', [work.id], alice.cookie);
  250. check('alice deletes her "Work" identity in ident (its app user becomes UNMAPPED)', dropped.value && !dropped.value.error, dropped.raw.slice(0, 200));
  251. await stop(identP); identP = null;
  252. // ---- 2. copies --------------------------------------------------------------------------------------------------
  253. cpSync(join(W, 'ident-data'), join(W, 'ident-data-new'), { recursive: true });
  254. cpSync(join(W, 'app-store'), join(W, 'app-store-control'), { recursive: true });
  255. cpSync(join(W, 'app-store'), join(W, 'app-store-migrated'), { recursive: true });
  256. // ---- 3. the NEW ident on the copy -------------------------------------------------------------------------------
  257. console.log('# 2. new ident (ident#23) on a copy of the old ident store');
  258. id = await startIdentOn(newCode, join(W, 'ident-data-new'));
  259. identP = id.p;
  260. const mig = await (await fetch(ID + '/api/migrate-ids', { method: 'POST', headers: { 'content-type': 'application/json' }, body: J(app) })).json();
  261. const olds = Object.keys(mig.ids || {});
  262. check('new ident: migrate-ids maps 2 old ids (alice Default, bob) to short ids; the deleted identity is left out; not finished',
  263. olds.length === 2 && olds.every(k => OLD.test(k)) && Object.values(mig.ids).every(v => SHORT.test(v)) && mig.finished === false, J(mig));
  264. // ---- 4. CONTROL: unmigrated store ---------------------------------------------------------------------------------
  265. console.log('# 3. control: the app on an UNMIGRATED copy');
  266. appP = await startApp(CODE, join(W, 'app-store-control'), app, await laterEnv(mig));
  267. const c1 = await appLogin(alice, app);
  268. if (c1.error) check('control: login through the new ident fails or …', false, c1.error);
  269. else check('control (not migrated): alice comes back as a NEW, EMPTY user — this is what the migration prevents', await isNewEmptyUser(c1.cookie, before), '');
  270. await stop(appP); appP = null;
  271. // ---- 5. the migration, twice --------------------------------------------------------------------------------------
  272. console.log('# 4. tools/migrate-short-ids.hl on the other copy, twice');
  273. const r1 = runTool(join(W, 'app-store-migrated'), app);
  274. writeFileSync(join(W, 'migrate-run1.txt'), r1);
  275. console.log(r1.trim().split('\n').map(l => ' | ' + l).join('\n'));
  276. check('run 1: users seen 3, mapped 2, already short 0, unmapped 1 (deleted identity), conflicts 0, failed 0', J(counts(r1)) === J([3, 2, 0, 1, 0, 0]), J(counts(r1)));
  277. const shorts = [...r1.matchAll(/MAPPED user \S+ → (\S+)/g)].map(m => m[1]).sort();
  278. check('run 1: the users now hold exactly the short ids ident mapped', J(shorts) === J(Object.values(mig.ids).sort()), J([shorts, mig.ids]));
  279. check('run 1 never prints the key or the secret', !r1.includes(app.secret) && !r1.includes(app.key));
  280. const r2 = runTool(join(W, 'app-store-migrated'), app);
  281. writeFileSync(join(W, 'migrate-run2.txt'), r2);
  282. check('run 2 (idempotent): seen 3, mapped 0, already short 2, unmapped 1', J(counts(r2)) === J([3, 0, 2, 1, 0, 0]), J(counts(r2)));
  283. await toolExtra(r1, r2, mig, app, alice);
  284. const badSecret = (() => { try { runTool(join(W, 'app-store-migrated'), { key: app.key, secret: 'sk_' + '0'.repeat(48) }); return 'ran'; } catch (e) { return String(e.stdout || '') + String(e.stderr || ''); } })();
  285. // the control copy: the app ran with the new ident BEFORE the migration and made a new user for alice's short id
  286. const rc = (() => { try { return 'exit 0: ' + runTool(join(W, 'app-store-control'), app); } catch (e) { return String(e.stdout || '') + String(e.stderr || ''); } })();
  287. writeFileSync(join(W, 'migrate-control.txt'), rc);
  288. check('the tool on the control copy (app ran before the migration): alice = CONFLICT, left alone, exit non-zero',
  289. J(counts(rc)) === J([4, 1, 1, 1, 1, 0]) && /CONFLICT user/.test(rc) && /CONFLICTS:/.test(rc) && !rc.startsWith('exit 0'), rc.slice(0, 400));
  290. check('a wrong secret: the tool stops with ident\'s 401, changes nothing', /401/.test(badSecret), badSecret.slice(0, 300));
  291. // ---- 6. the app on the migrated store ------------------------------------------------------------------------------
  292. console.log('# 5. the app on the MIGRATED copy with the new ident');
  293. appP = await startApp(CODE, join(W, 'app-store-migrated'), app, await laterEnv(mig));
  294. await sameUser('alice, OLD app session (no new login)', a1.cookie, before.alice);
  295. const a2 = await appLogin(alice, app);
  296. check('alice logs in again through the new ident', !a2.error, a2.error);
  297. if (!a2.error) await sameUser('alice, fresh login through the new ident', a2.cookie, before.alice, mig);
  298. const b2 = await appLogin(bob, app);
  299. check('bob logs in again through the new ident', !b2.error, b2.error);
  300. if (!b2.error) await sameUser('bob, fresh login through the new ident', b2.cookie, before.bob, mig);
  301. await stop(appP); appP = null;
  302. const r3 = runTool(join(W, 'app-store-migrated'), app);
  303. writeFileSync(join(W, 'migrate-run3.txt'), r3);
  304. check('after the logins: still 3 users (no new one was made), all short or unmapped as before', J(counts(r3)) === J([3, 0, 2, 1, 0, 0]), J(counts(r3)));
  305. await stop(identP); identP = null;
  306. } catch (err) {
  307. failed++; console.log(' FAIL (aborted) ' + (err.stack || err));
  308. } finally {
  309. for (const p of [...procs]) await stop(p);
  310. mkdirSync(W, { recursive: true });
  311. writeFileSync(join(W, 'servers.log'), log);
  312. }
  313. console.log(`\n${passed} passed, ${failed} failed`);
  314. process.exit(failed ? 1 : 0);

Branches

Latest commits

  • 54bc5fe1Harden delta relevance, overflow caps and retry verificationmre
  • 8d8e2053Document subscription contract and exercise delta deliverymre
  • fd23726aAdd subscription delta API and signed wake bridgemre
  • c5d28fb5Tickets conductor: S51 startedmre
  • fd6ca1e6Tickets conductor: brief 027 waker design, push-test projectmre
  • e448e656Tickets conductor: STATUS #51mre
  • 1c10857bTickets conductor: P51 eval, brief 027mre
  • e725969dTickets conductor: #51 directionmre
  • 1b5c63ddTickets conductor: P51 startedmre
  • 9f13fbdaTickets conductor: brief 026 prioritymre
  • acc477d9Tickets conductor: brief 026 + Vinzenz recommendationsmre
  • 9233a734Tickets conductor: brief 026 completemre
  • 5da589fdTickets conductor: brief 026 + Gitoria's answermre
  • a3cd5329Tickets conductor: tickets#51 opened, brief 026 draftmre
  • 6f6e5797Tickets conductor: STATUS wordingmre
  • 957de51fTickets conductor: T36 live, #36 review, #50 donemre
  • bc2fde32Merge branch 'main' into t36-stylemre
  • b7ca093atests: wait for the new row and normalize editor marker spacesmre
  • 41da3525Tickets conductor: flake cause, T36 deploy stepmre
  • 64c477e6Tickets conductor: deploy waits for Arachnemre