Staging test mode (Marty's rule: test apps never touch real people): TANK_MODE=iap with DRAFT_LIVE not 1 reads the pool + statuses from InstantAdPay but every pick (5 instant picks on a purchase, the Monday draft) and release is a preview kept here: no tank.adopt(), no sponsor change, no email. Yellow 'TEST MODE, nobody is adopted' strip on every page (/api/config testMode). Admin view: testMode, previewPicks, adoptionMailsSkipped. iap-tank 35/35 (new section 6 against the real draftpartner.js), unit 62/62, smoke 156/156. common.js/fx.css ?v=3

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-15 08:42:22 -06:00
parent 1112a8c589
commit 3815965fc1
22 changed files with 101 additions and 50 deletions
+24 -1
View File
@@ -40,7 +40,7 @@ function fakeAccounts() {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'fx-iaptank-'));
const iapDir = path.join(dir, 'iap'); fs.mkdirSync(iapDir);
delete process.env.DATABASE_URL;
Object.assign(process.env, { DATA_DIR: path.join(dir, 'fx'), DOCSTORE_URL: '', TANK_MODE: 'iap', IAP_URL: 'http://127.0.0.1:' + PORT, DRAFT_PARTNER_SECRET: SECRET, DRAFT_ROUNDS: '2', PICK_RETURN_DAYS: '3' });
Object.assign(process.env, { DATA_DIR: path.join(dir, 'fx'), DOCSTORE_URL: '', TANK_MODE: 'iap', IAP_URL: 'http://127.0.0.1:' + PORT, DRAFT_PARTNER_SECRET: SECRET, DRAFT_ROUNDS: '2', PICK_RETURN_DAYS: '3', DRAFT_LIVE: '1' }); // sections 1-5 live; section 6 = staging test mode
fs.mkdirSync(process.env.DATA_DIR);
require(path.join(APP, 'config.js')).reset(); const C = require(path.join(APP, 'config.js')).get();
const store = require(path.join(APP, 'store.js')); const league = require(path.join(APP, 'league.js')); const tank = require(path.join(APP, 'tankpool.js'));
@@ -137,6 +137,29 @@ function fakeAccounts() {
ok(r.error && store.picks().length === n0, 'no answer: a pick is refused and nothing is recorded', r);
const st = await tank.status([back[0].id], now()); ok(st[back[0].id] === null, 'no answer: status is null (nothing changes on the sweep)');
ok(tank.view().remote.failed >= 3 && tank.view().remote.secret === true, 'the admin view counts the failures', tank.view().remote);
console.log('6. staging test mode (DRAFT_LIVE not 1): the pool is read, picks are previews, nobody is adopted, no mail');
C.iapBase = 'http://127.0.0.1:' + PORT; delete process.env.DRAFT_LIVE;
const m0 = mails.length, c0 = chats.length;
ok(tank.preview() === true && tank.live() === false && tank.view().testMode === true, 'test mode is on without DRAFT_LIVE=1', tank.view());
const tp = await league.pool(now()); ok(tp.length > 0, 'the pool is still read from InstantAdPay', tp.length);
const who = tp[0]; const whoEmail = emailOfId(who.id); const sp0 = await sponsorOf(whoEmail);
r = await league.instantPick(A, who.id);
ok(r.ok && /^preview:/.test(store.pick(r.pickId).ref), 'instant pick in test mode: recorded here as a preview (ref preview:...)', r);
ok(await sponsorOf(whoEmail) === sp0 && (await itank.openOf(whoEmail)).length === 0, 'InstantAdPay: no sponsor change, no open adoption');
ok(mails.length === m0 && chats.length === c0, 'no adoption email, no chat', mails.slice(m0));
ok(!(await league.pool(now())).some(x => x.id === who.id), 'a previewed person leaves the pool on this site only');
const nextMon = store.ctToMs('2026-11-23', 19); league.clock.set(nextMon + 1000); await league.tick();
const d2 = store.draft('2026-11-23'); const made2 = d2 ? d2.made.filter(x => x.person) : [];
ok(d2 && d2.status === 'done' && made2.length > 0, 'the Monday draft runs in test mode', d2 && d2.made.map(x => x.person ? 'pick' : x.skipped || 'x'));
const prev = store.picks().filter(p => p.status === 'open');
ok(prev.length > 0 && prev.every(p => /^preview:/.test(p.ref || '')), 'every open pick is a preview', prev.map(p => p.ref));
let clean = true; for (const p of prev) { const e = emailOfId(p.person); if ((await itank.openOf(e)).length || (await sponsorOf(e)) !== '') clean = false; }
ok(clean, 'InstantAdPay: no drafted person got a sponsor or an open adoption');
ok(mails.length === m0 && chats.length === c0, 'still no email or chat after the draft', mails.length - m0);
league.clock.set(nextMon + 3 * D); const rp = prev.find(p => p.coach === A) || prev[0]; r = await league.release(rp.coach, rp.id);
ok(r.ok && store.pick(rp.id).status === 'returned' && mails.length === m0, 'releasing a preview pick touches nothing on InstantAdPay', r);
ok(tank.view().adoptionMailsSkipped >= 1 + made2.length, 'the admin view counts the adoptions (and emails) that test mode skipped', tank.view());
} finally { srv.close(); fs.rmSync(dir, { recursive: true, force: true }); }
console.log('\n' + pass + ' passed, ' + fail + ' failed');
process.exit(fail ? 1 : 0);