Holding tank: 24-hour sign-up grace plus a Who invited you card (Marty 2026-11-07: "24-hour grace plus the prompt"). On Nov 2 a sponsorless sign-up was adopted five hours after joining, before he could say who invited him.

Grace: for 24 hours from an account's created time nobody can adopt the person by hand. They stay on the waiting list after the open ones with an Opens in badge and no Adopt button, and adopt() refuses in plain words. Only sign-up counts, so someone back in the tank later has no grace. Auto-assign does not wait for it: the 24-hour hold still runs from the wallet link and is not stretched. No notice tells people to adopt someone they cannot adopt yet: the wallet-ready post waits for the grace and says the time really left, is skipped when the rotation takes them in that tick, the arrivals post moves to when the grace ends (marks.claim per member), and the Overview note and weekly email count only people who are open.

Prompt: a member with no sponsor and no member number sees the card at the top of Overview, types a username, confirms in an in-page box, and that person becomes their sponsor through setSponsor as a deliberate change with by 'invited', so it follows to LinkSpin and clears the hold. Refused: self, unknown username, already sponsored, member number or wallet already on the contract, a chain loop, a suspended sponsor, a no-payout chain, and a line with nobody on the contract (they would walk up to the company). The network sponsor is tried first. Nobody invited me hides it and a small link brings it back. Not an adoption: status 'invited', no 7-day window, not counted toward the two. The named sponsor gets the referral email and an on-site notice. Switch-on-payouts reminders track the named sponsor.

Chatbot canned + systemPrompt, KNOWLEDGE_DATE 2026-11-07. my.js, admin.js, admin-sponsorcheck.js ?v=20261107tg. qa/tank-hold.mjs, qa/sponsorfollow.test.cjs and qa/sponsorfollow-e2e.mjs extended (SF_E2E_PORT overrides the ports).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-07 07:04:18 -06:00
parent 973fc80570
commit bfbea142b6
13 changed files with 405 additions and 33 deletions
+13 -2
View File
@@ -17,7 +17,7 @@ const LS_SITE = process.env.LS_SITE || path.join(IAP_SITE, '..', '..', 'linkspin
const SECRET = 'qa-sponsorfollow-' + 'x'.repeat(40);
process.env.LS_SYNC_SECRET = SECRET;
const SF = require(path.join(IAP_SITE, 'sponsorfollow.js'));
const IAP_PORT = 8811, LS_PORT = 8812, IAP = 'http://127.0.0.1:' + IAP_PORT, LS = 'http://127.0.0.1:' + LS_PORT;
const IAP_PORT = Number(process.env.SF_E2E_PORT || 8811), LS_PORT = IAP_PORT + 1, IAP = 'http://127.0.0.1:' + IAP_PORT, LS = 'http://127.0.0.1:' + LS_PORT;
const sleep = ms => new Promise(r => setTimeout(r, ms));
let pass = 0, fail = 0; const lines = [];
const ok = (cond, name, extra) => { if (cond) { pass++; lines.push('ok ' + name); } else { fail++; lines.push('FAIL ' + name + (extra ? '\n ' + extra : '')); } };
@@ -30,7 +30,7 @@ function seed(dir, list) {
for (const a of list) { db.byEmail[a.email] = a; db.byCode[a.code] = a.email; }
fs.writeFileSync(path.join(dir, 'accounts.json'), JSON.stringify(db));
}
const base = () => [acct('adopter@qa.test', 'adopter', { memberId: 0 }), acct('old@qa.test', 'oldsponsor'), acct('lead1@qa.test', 'leadone'), acct('lead2@qa.test', 'leadtwo', { sponsorRef: 'oldsponsor' }), acct('lead4@qa.test', 'leadfour', { sponsorRef: 'oldsponsor' })];
const base = () => [acct('boss@qa.test', 'qaboss', { memberId: 77 }), acct('lead5@qa.test', 'leadfive'), acct('adopter@qa.test', 'adopter', { memberId: 0 }), acct('old@qa.test', 'oldsponsor'), acct('lead1@qa.test', 'leadone'), acct('lead2@qa.test', 'leadtwo', { sponsorRef: 'oldsponsor' }), acct('lead4@qa.test', 'leadfour', { sponsorRef: 'oldsponsor' })];
const iapDir = fs.mkdtempSync(path.join(os.tmpdir(), 'sf-e2e-iap-')), lsDir = fs.mkdtempSync(path.join(os.tmpdir(), 'sf-e2e-ls-'));
// lead3 is bound on InstantAdPay (memberId), lead4 joined LinkSpin under someone else (ordinary, already different)
seed(iapDir, base().concat([acct('lead3@qa.test', 'leadthree', { memberId: 42, sponsorRef: 'oldsponsor' })]));
@@ -70,6 +70,17 @@ try {
await sleep(6000);
ok((await facts(IAP, 'lead3@qa.test')).sponsorEmail === 'old@qa.test', 'bound on InstantAdPay: sponsor there unchanged');
// 3b. Who invited you (2026-11-07): the member, signed in on InstantAdPay, names their sponsor; LinkSpin follows through the real sync
{ const st = await fetch(IAP + '/api/auth/email/start', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: 'lead5@qa.test', fts: Date.now() - 8000 }) }).then(x => x.json());
const v = await fetch(IAP + '/api/auth/email/verify', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: 'lead5@qa.test', code: st.devCode }) });
const cookie = (v.headers.getSetCookie ? v.headers.getSetCookie() : []).map(c => c.split(';')[0]).join('; ');
const inv = await fetch(IAP + '/api/my/tank/invited', { method: 'POST', headers: { 'Content-Type': 'application/json', Cookie: cookie }, body: JSON.stringify({ who: '@qaboss' }) }).then(x => x.json());
ok(inv.ok && inv.name === '@qaboss', 'lead5 names @qaboss on InstantAdPay', JSON.stringify({ inv, dev: !!st.devCode }));
ok(await waitFor(async () => (await facts(LS, 'lead5@qa.test')).sponsorEmail === 'boss@qa.test'), 'LinkSpin follows: lead5 under boss');
const f5 = await facts(LS, 'lead5@qa.test'); ok(f5 && f5.prov && f5.prov.by === 'invited' && f5.prov.origin === 'instantadpay', 'LinkSpin keeps the record (by invited, origin instantadpay)', JSON.stringify(f5 && f5.prov));
const a5 = await admin(IAP, '/api/admin/tank'); ok((a5.adoptions || []).some(x => x.adoptee === 'lead5@qa.test' && x.status === 'invited'), 'InstantAdPay admin tank shows the record');
}
// 4. ping-pong: let both ticks run; nothing keeps bouncing
const s1 = await admin(IAP, '/api/admin/lssync'), t1 = await admin(LS, '/api/admin/iapsync');
await admin(IAP, '/api/admin/lssync/run', {}); await admin(LS, '/api/admin/iapsync/run', {}); await sleep(1500);
+25
View File
@@ -173,6 +173,31 @@ async function network() {
assert.strictEqual(P.chats.length, 1); assert.strictEqual(Q.chats.length, 0, 'no chat on the quiet side');
const qr = await Q.tank.adopt('other@x.co', 'lead'); assert.ok(qr.error, 'cannot be adopted twice across the network');
});
await t('Who invited you: the member names a sponsor on one platform, the other follows and agrees (2026-11-07)', async () => {
const P = platform('instantadpay', 'linkspin'), Q = platform('linkspin', 'instantadpay'); people(P, Q);
const r = await P.tank.nameSponsor('lead@x.co', 'adopter'); assert.ok(r.ok, JSON.stringify(r));
assert.strictEqual(P.store.get('lead@x.co').by, 'invited');
const s = await settle(P, Q, ['lead@x.co', 'adopter@x.co']);
assert.strictEqual(s.moves, 1); assert.strictEqual(await spOf(Q, 'lead@x.co'), 'adopter@x.co');
assert.ok(!(await Q.tank.waiting()).some(w => w.email === 'lead@x.co'), 'gone from the other waiting list');
assert.strictEqual(Q.store.get('lead@x.co').by, 'invited'); assert.strictEqual(Q.store.get('lead@x.co').origin, 'instantadpay');
assert.ok((await Q.tank.adopt('other@x.co', 'lead')).error, 'nobody adopts them on the other side');
assert.ok((await Q.tank.nameSponsor('lead@x.co', 'otheradopter')).error, 'the other side refuses a second name');
});
await t('Who invited you: a bound member on the other platform keeps that sponsor; reported, not moved', async () => {
const P = platform('instantadpay', 'linkspin'), Q = platform('linkspin', 'instantadpay'); people(P, Q);
Q.bound.add('lead@x.co');
const r = await P.tank.nameSponsor('lead@x.co', 'adopter'); assert.ok(r.ok, JSON.stringify(r));
const { d } = await deliver(P, Q, 'lead@x.co');
assert.strictEqual(d.action, 'bound'); assert.strictEqual(await spOf(Q, 'lead@x.co'), null);
});
await t('sign-up grace holds on both platforms', async () => {
const P = platform('instantadpay', 'linkspin'), Q = platform('linkspin', 'instantadpay'); people(P, Q);
for (const X of [P, Q]) X.accounts.add('fresh@x.co', { username: 'fresh', created: Date.now() });
for (const X of [P, Q]) assert.ok(/less than 24 hours/.test((await X.tank.adopt('adopter@x.co', 'fresh')).error || ''), X.name);
assert.strictEqual(await spOf(P, 'fresh@x.co'), null); assert.strictEqual(await spOf(Q, 'fresh@x.co'), null);
});
await t('ping-pong guard: the applied change comes back as "same" and settles in one round trip', async () => {
const P = platform('instantadpay', 'linkspin'), Q = platform('linkspin', 'instantadpay'); people(P, Q);
await P.tank.adopt('adopter@x.co', 'lead');
+184
View File
@@ -24,6 +24,7 @@ delete process.env.DATABASE_URL; // JSON stores only
let fails = 0; const ok = (cond, label, extra) => { console.log((cond ? 'PASS ' : 'FAIL ') + label + (extra ? ' ' + extra : '')); if (!cond) fails++; };
const sleep = ms => new Promise(r => setTimeout(r, ms));
const H = 3600000;
const addr = () => '0x' + crypto.randomBytes(20).toString('hex');
// ---------------- Part A ----------------
function fakeAccounts() {
@@ -222,12 +223,156 @@ async function partA() {
}
// ---------------- Part B ----------------
// ---------------- Sign-up grace + "Who invited you?" (Marty approved 2026-11-07) ----------------
async function partGrace() {
console.log('-- Sign-up grace + Who invited you: tank.js with a mocked clock');
const M = 60000;
{ // hand adoption: blocked for 24 hours from created, open after, old members untouched
const B = bench(); const { tank, accounts, env } = B; const t0 = env.now;
B.buyer('ad@x.co', 11);
accounts.add('new@x.co', { created: t0 - H }); accounts.add('old@x.co');
const w = await tank.waiting(); const row = w.find(x => x.email === 'new@x.co');
ok(row && row.opensAt === t0 + 23 * H, 'waiting(): new sign-up carries opensAt = created + 24 h', JSON.stringify(row));
ok(w.find(x => x.email === 'old@x.co').opensAt === 0, 'waiting(): an old account is open now');
ok(w[w.length - 1].email === 'new@x.co', 'waiting(): grace members sort after the open ones');
ok((await tank.adoptable()).every(x => x.email !== 'new@x.co'), 'adoptable() leaves out grace members (Overview note, weekly email)');
const r = await tank.adopt('ad@x.co', 'new', 'hi');
ok(r.error && /less than 24 hours/.test(r.error) && /23 h 0 min/.test(r.error), 'grace blocks a hand adoption with a plain message', JSON.stringify(r));
ok(!(await accounts.byEmail('new@x.co')).sponsorRef, '...and writes no sponsor');
ok(!B.mails.length && !B.chats.length, '...and tells nobody');
env.now = t0 + 23 * H - M;
ok((await tank.adopt('ad@x.co', 'new', 'hi')).error, 'still blocked one minute before it opens');
env.now = t0 + 23 * H + M;
const r2 = await tank.adopt('ad@x.co', 'new', 'hi');
ok(r2.ok, 'opens after 24 hours', JSON.stringify(r2));
const r3 = await tank.adopt('ad@x.co', 'old', 'hi');
ok(r3.ok, 'an old account is adoptable at once (back in the tank later = no grace)', JSON.stringify(r3));
}
{ // wallet in the first hour: hand adoption opens at 24 h, the safety net keeps its own clock
const B = bench(); const { tank, accounts, env } = B; const t0 = env.now;
B.buyer('ad@x.co', 11); B.buyer('ad2@x.co', 12);
accounts.add('w@x.co', { created: t0 });
env.now = t0 + H; accounts._by.get('w@x.co').address = addr(); accounts._by.get('w@x.co').lastSeen = env.now;
const t1 = await tank.readyTick();
ok(t1.fresh.length === 0, 'wallet in the first hour: no "adopt them" notice during the grace', JSON.stringify(t1.fresh));
const h = await tank.holdFor(await accounts.byEmail('w@x.co'));
ok(h.hold.since === t0 + H && h.hold.until === t0 + 25 * H, 'the hold clock runs from the wallet link, not stretched by the grace', JSON.stringify(h.hold));
env.now = t0 + 23 * H; ok((await tank.readyTick()).fresh.length === 0, 'still no notice at 23 hours');
ok((await tank.adopt('ad@x.co', 'w', 'hi')).error, 'hand adoption refused at 23 hours');
env.now = t0 + 24 * H + M; for (const em of ['ad@x.co', 'ad2@x.co']) accounts._by.get(em).lastSeen = env.now;
const t2 = await tank.readyTick();
ok(t2.fresh.length === 1 && t2.fresh[0].until === t0 + 25 * H && !t2.assigned.length, 'grace over: notice once, with the real end of the hold', JSON.stringify(t2.fresh));
ok(tank.leftText(t2.fresh[0].until - env.now) === '59 min', 'the notice text can say the time really left', tank.leftText(t2.fresh[0].until - env.now));
ok((await tank.readyTick()).fresh.length === 0, '...and not twice');
env.now = t0 + 25 * H - 10 * M;
const t3 = await tank.readyTick();
ok(t3.assigned.length === 1 && t3.assigned[0].adoptee === 'w@x.co', 'the rotation takes them inside 24 hours of the wallet link', JSON.stringify(t3.assigned));
}
{ // wallet in the first minutes: the rotation fires just before the grace ends, no notice ever goes out
const B = bench(); const { tank, accounts, env } = B; const t0 = env.now;
B.buyer('ad@x.co', 11);
accounts.add('fast@x.co', { created: t0, address: addr() });
env.now = t0 + 5 * M; ok((await tank.readyTick()).fresh.length === 0, 'wallet in minute 5: no notice');
env.now = t0 + 24 * H - 5 * M; accounts._by.get('ad@x.co').lastSeen = env.now;
const t = await tank.readyTick();
ok(t.assigned.length === 1 && t.fresh.length === 0, 'auto path unaffected: assigned inside the grace (24 h from the wallet link), no adopt notice', JSON.stringify({ a: t.assigned, f: t.fresh }));
ok((await accounts.byEmail('fast@x.co')).sponsorRef === 'ad', 'the safety net wrote the sponsor');
}
{ // grace ends in the last tick of the hold: the safety net takes them, nobody is told to adopt someone already gone
const B = bench(); const { tank, accounts, env } = B; const t0 = env.now;
B.buyer('ad@x.co', 11);
accounts.add('mid@x.co', { created: t0 });
env.now = t0 + 10 * M; accounts._by.get('mid@x.co').address = addr(); await tank.readyTick();
env.now = t0 + 24 * H + M; accounts._by.get('ad@x.co').lastSeen = env.now; // 9 minutes of hold left: inside the last tick
const t = await tank.readyTick();
ok(t.assigned.length === 1 && t.fresh.length === 0, 'no notice for someone the rotation takes in the same tick', JSON.stringify({ a: t.assigned, f: t.fresh }));
}
{ // the arrivals post: announced when the grace ends
const B = bench(); const { tank, env } = B; const t0 = env.now;
const list = [{ email: 'a', joined: t0 - 24 * H - 5 * M }, { email: 'b', joined: t0 - 24 * H - 20 * M }, { email: 'c', joined: t0 - H }];
ok(tank.openedSince(list, t0 - 15 * M).map(x => x.email).join() === 'a', 'openedSince: only people whose grace ended since the last check');
}
{ // Who invited you: every refusal, nothing written
const B = bench(); const { tank, accounts, env } = B; const t0 = env.now;
B.buyer('boss@x.co', 21);
accounts.add('m@x.co', { username: 'mm1', created: t0 });
accounts.add('kid@x.co', { username: 'kid', sponsorRef: 'mm1' }); // joined under m: a loop
accounts.add('free@x.co', { username: 'free' }); // no payouts, nobody above them
accounts.add('under@x.co', { username: 'under', sponsorRef: 'boss' }); // no payouts, but boss above them
accounts.add('has@x.co', { username: 'hassp', sponsorRef: 'boss' });
accounts.add('bound@x.co', { username: 'bound1', memberId: 55 });
const say = async (e, who) => { const r = await tank.nameSponsor(e, who); return r.error || ''; };
ok(/Type the username/.test(await say('m@x.co', ' ')), 'refused: empty');
ok(/That is you/.test(await say('m@x.co', '@MM1')), 'refused: self (any case, leading @)');
ok(/No member here/.test(await say('m@x.co', 'nosuchname')), 'refused: unknown username');
ok(/No member here/.test(await say('m@x.co', 'bad name!')), 'refused: not a username');
ok(/already have a sponsor/.test(await say('has@x.co', 'boss')), 'refused: already sponsored');
ok(/locked on the contract/.test(await say('bound@x.co', 'boss')), 'refused: member id');
ok(/in your own line/.test(await say('m@x.co', 'kid')), 'refused: chain loop (inDownlineOf)');
ok(/nobody above them/.test(await say('m@x.co', 'free')), 'refused: nobody on the contract in that line (would fall to the company)');
B.blocked.add(21);
ok(/cannot take new members/.test(await say('m@x.co', 'boss')), 'refused: no-payout chain');
B.blocked.delete(21);
ok(!(await accounts.byEmail('m@x.co')).sponsorRef && !B.mails.length, 'no refusal wrote a sponsor or sent a notice');
const c = await tank.nameSponsor('m@x.co', 'boss', { check: true });
ok(c.ok && c.name === '@boss' && !(await accounts.byEmail('m@x.co')).sponsorRef && !B.mails.length, 'check mode validates and writes nothing', JSON.stringify(c));
ok((await tank.nameSponsor('m@x.co', 'under', { check: true })).ok, 'a sponsor with no payouts but someone above them on the contract is allowed');
B.net['m2@x.co'] = { sponsorEmail: 'boss@x.co', via: 'email' };
accounts.add('m2@x.co', { username: 'mm2' });
const al = await tank.nameSponsor('m2@x.co', 'under');
ok(al.error && al.aligned && (await accounts.byEmail('m2@x.co')).sponsorRef === 'boss', 'the sponsor the network already knows comes first', JSON.stringify(al));
}
{ // Who invited you: success
const B = bench(); const { tank, accounts, env } = B; const t0 = env.now;
B.buyer('boss@x.co', 21); B.buyer('ad@x.co', 22);
accounts.add('m@x.co', { username: 'mm1', created: t0 });
const m0 = await accounts.byEmail('m@x.co');
ok(tank.inviteAsk(m0) && tank.inviteAsk(m0).dismissed === false, 'inviteAsk: the card shows for a tank member');
ok(tank.inviteAsk(await accounts.byEmail('boss@x.co')) === null, 'inviteAsk: no card for a member with a sponsor line / member id');
tank.dismissInvite('m@x.co');
ok(tank.inviteAsk(m0).dismissed === true, 'Nobody invited me: card dismissed');
ok(!(await accounts.byEmail('m@x.co')).sponsorRef && (await tank.waiting()).some(w => w.email === 'm@x.co'), '...nothing else changes: still in the tank');
const r = await tank.nameSponsor('m@x.co', '@Boss');
ok(r.ok && r.name === '@boss', 'prompt success', JSON.stringify(r));
const a = await accounts.byEmail('m@x.co');
ok(a.sponsorRef === 'boss', 'sponsor written');
ok((await tank.holdFor(a)) === null && tank.inviteAsk(a) === null, 'hold gone, card gone');
ok(!(await tank.waiting()).some(w => w.email === 'm@x.co'), 'out of the waiting list');
ok(B.mails.length === 1 && B.mails[0].to === 'boss@x.co' && /new referral/.test(B.mails[0].subject), 'the named sponsor gets the notice, nobody else', JSON.stringify(B.mails.map(x => x.to)));
ok(!B.chats.length, 'no chat written in the sponsor\'s name');
const v = await tank.adminView(); const rec = v.adoptions.find(x => x.adoptee === 'm@x.co');
ok(rec && rec.status === 'invited' && rec.adopter === 'boss@x.co', 'admin record: status invited');
ok((await tank.summaryFor('m@x.co')) === null, 'not an adoption: nothing counts toward the two, nothing open on the other site');
const again = await tank.nameSponsor('m@x.co', 'ad');
ok(/already have a sponsor/.test(again.error || '') && (await accounts.byEmail('m@x.co')).sponsorRef === 'boss', 'a second name is refused');
env.now = t0 + 8 * 86400000; await tank.sweep();
ok((await accounts.byEmail('m@x.co')).sponsorRef === 'boss', 'no 7-day window: still theirs after a week');
}
{ // a ready member names someone: the hold record clears the way an adoption does, no auto-assign
const B = bench(); const { tank, accounts, env } = B; const t0 = env.now;
B.buyer('boss@x.co', 21); B.buyer('ad@x.co', 22);
accounts.add('r@x.co', { username: 'rr1', created: t0, address: addr() });
await tank.readyTick();
ok(tank.readyRec('r@x.co'), 'setup: on the 24-hour clock');
const r = await tank.nameSponsor('r@x.co', 'boss');
ok(r.ok && !tank.readyRec('r@x.co'), 'the hold record clears', JSON.stringify(r));
env.now = t0 + 24 * H;
for (const em of ['boss@x.co', 'ad@x.co']) accounts._by.get(em).lastSeen = env.now;
ok(!(await tank.readyTick()).assigned.length && (await accounts.byEmail('r@x.co')).sponsorRef === 'boss', 'the rotation leaves them alone');
ok(tank.payView().some(p => p.email === 'r@x.co' && p.adopter === 'boss@x.co'), 'the switch-on-payouts reminders track the named sponsor');
const B2 = bench(); B2.buyer('boss@x.co', 21); const w = '0x' + 'e'.repeat(40); B2.accounts.add('c@x.co', { username: 'cc1', address: w }); B2.onChain.add(w);
ok(/locked on the contract/.test((await B2.tank.nameSponsor('c@x.co', 'boss')).error || ''), 'refused: wallet already on the contract, member number not saved yet');
}
}
async function partB() {
console.log('-- Part B: local copy');
const PORT = Number(process.env.TANKHOLD_PORT || 8799);
const BASE = 'http://127.0.0.1:' + PORT; const ADMIN = 'localtest';
const DATA = fs.mkdtempSync(path.join(os.tmpdir(), 'iap-tankhold-srv-')); fs.mkdirSync(path.join(DATA, 'uploads'));
const LSSECRET = crypto.randomBytes(24).toString('hex'); // throwaway
{ const a = { email: 'qa-sponsor@example.com', pass: null, sponsorRef: '', code: 'cqasp1', username: 'qasponsor', address: null, created: Date.now() - 30 * 86400000, lastSeen: Date.now() - H, memberId: 42 }; // a member with a contract position, for the Who invited you checks
fs.writeFileSync(path.join(DATA, 'accounts.json'), JSON.stringify({ v: 2, byEmail: { [a.email]: a }, byAddress: {}, byCode: { [a.code]: a.email }, joins: 0, positions: {} })); }
const srv = spawn(process.execPath, ['server.js'], { cwd: SITE, stdio: ['ignore', 'pipe', 'pipe'],
env: Object.assign({}, process.env, { PORT: String(PORT), DATA_DIR: DATA, NODE_ENV: 'development', ADMIN_EMAIL: 'qa-admin@example.com', ADMIN_PASSWORD: ADMIN, LS_SYNC_SECRET: LSSECRET, LS_URL: 'http://127.0.0.1:1' }) });
let log = ''; srv.stdout.on('data', d => log += d); srv.stderr.on('data', d => log += d);
@@ -354,6 +499,44 @@ async function partB() {
ok(s5.act.length === 0 && s5.note === 'Step 1: link your wallet (one free signature). Then switching on payouts with member #21 starts by itself.', 'no wallet yet: asks to link first, nothing starts', JSON.stringify(s5));
await c.close(); }
ok(!errs.length, 'no page errors (one-tap link pages)', errs.join(' | ').slice(0, 200));
{ // 6. Who invited you + the sign-up grace, on the real page (2026-11-07)
const nc = await signIn('qa-new@example.com', 'qanewone', null, '10.78.0.9');
const m0 = (await api('/api/me', null, { Cookie: nc })).j;
ok(m0 && m0.inviteAsk && m0.inviteAsk.dismissed === false, '/api/me: inviteAsk for a tank member', JSON.stringify(m0 && m0.inviteAsk));
const sc = await signIn('qa-sponsor@example.com', null, null, '10.78.0.10');
const tv = (await api('/api/my/tank', null, { Cookie: sc })).j; const row6 = tv && tv.waiting.find(w => w.email === 'qa-new@example.com');
ok(row6 && row6.opensAt > Date.now(), '/api/my/tank: a new sign-up is listed with opensAt', JSON.stringify(row6));
const bad = await api('/api/my/tank/invited', { who: 'nosuchname' }, { Cookie: nc });
ok(bad.status === 400 && /No member here/.test(bad.j.error), 'POST invited: unknown username refused', JSON.stringify(bad));
const self = await api('/api/my/tank/invited', { who: 'qanewone' }, { Cookie: nc });
ok(self.status === 400 && /That is you/.test(self.j.error), 'POST invited: self refused', JSON.stringify(self));
const anon = await api('/api/my/tank/invited', { who: 'qasponsor' });
ok(anon.status === 401, 'POST invited: signed out refused');
const { c, pg } = await actCtx(nc); await pg.goto(BASE + '/my#overview', { waitUntil: 'load' }); await pg.waitForTimeout(3500);
const vis = id => pg.evaluate(i => { const e = document.getElementById(i); return !!(e && !e.hidden); }, id);
ok(await vis('inviteCard'), 'Overview: Who invited you card shows');
await pg.screenshot({ path: path.join(SITE, 'qa/out/tank-invite-card.png') }).catch(() => {});
await pg.fill('#inviteWho', 'nosuchname'); await pg.click('#inviteGo'); await pg.waitForTimeout(700);
ok(/No member here/.test(await pg.textContent('#inviteMsg')), 'card: the refusal shows in the card', await pg.textContent('#inviteMsg'));
await pg.click('#inviteNo'); await pg.waitForTimeout(500);
ok(!(await vis('inviteCard')) && await vis('inviteSmall'), 'card: Nobody invited me hides it, the small link stays');
await pg.reload({ waitUntil: 'load' }); await pg.waitForTimeout(3000);
ok(!(await vis('inviteCard')) && await vis('inviteSmall'), 'card: stays dismissed after a reload');
await pg.click('#inviteBack'); await pg.fill('#inviteWho', '@qasponsor'); await pg.click('#inviteGo'); await pg.waitForSelector('#dlgCancel', { timeout: 8000 }).catch(async e => { throw new Error('no confirm box; card says: ' + await pg.textContent('#inviteMsg') + ' | ' + e.message.slice(0, 80)); });
await pg.click('#dlgCancel'); await pg.waitForTimeout(500);
ok(!(await api('/api/me', null, { Cookie: nc })).j.sponsorName, 'card: Not them writes nothing');
await pg.click('#inviteGo'); await pg.waitForSelector('#dlgOk', { timeout: 5000 }); await pg.click('#dlgOk'); await pg.waitForTimeout(2500);
const m1 = (await api('/api/me', null, { Cookie: nc })).j;
ok(m1 && m1.sponsorName === '@qasponsor' && !m1.inviteAsk, 'card: yes sets the sponsor, the card is gone', JSON.stringify({ n: m1 && m1.sponsorName, a: m1 && m1.inviteAsk }));
ok(!(await vis('inviteCard')) && !(await vis('inviteSmall')), 'card: nothing left on the Overview');
const adm6 = (await api('/api/admin/tank', null, adminH)).j;
ok(adm6.adoptions.some(a => a.adoptee === 'qa-new@example.com' && a.status === 'invited'), 'admin tank: the invited record shows');
await c.close();
const pc2 = await signIn('qa-kid2@example.com', 'qakidtwo', 'iap.sponsor=qasponsor', '10.78.0.11');
const m2 = (await api('/api/me', null, { Cookie: pc2 })).j;
ok(m2 && !m2.inviteAsk, 'a member who joined through a link never sees the card');
ok(!errs.length, 'no page errors (Who invited you)', errs.join(' | ').slice(0, 200));
}
} finally {
if (browser) await browser.close().catch(() => {});
try { srv.kill(); } catch (e) {}
@@ -363,6 +546,7 @@ async function partB() {
}
await partA();
await partGrace();
if (process.argv[2] !== 'unit') await partB();
console.log(fails ? '\n' + fails + ' FAILED' : '\nall passed');
process.exit(fails ? 1 : 0);