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:
+23
-4
@@ -42,9 +42,17 @@ function init(cfg, opts) {
|
||||
try { fixture = JSON.parse(fs.readFileSync(f, 'utf8')); } catch (e) { fixture = { people: [] }; console.error('tankpool: no stub pool at', f); }
|
||||
fixture.base = nowFn(); // relative times are measured from boot
|
||||
console.log('tankpool: STUB mode (' + fixture.people.length + ' fixture people, nobody is adopted for real, no mail)');
|
||||
} else console.log('tankpool: InstantAdPay mode (' + C.iapBase + '/api/partner/draft/*' + (secret() ? '' : ', DRAFT_PARTNER_SECRET MISSING: every call refuses') + ')');
|
||||
} else console.log('tankpool: InstantAdPay mode (' + C.iapBase + '/api/partner/draft/*' + (secret() ? '' : ', DRAFT_PARTNER_SECRET MISSING: every call refuses') + ')' + (live() ? ' LIVE: picks are real adoptions' : ' TEST MODE (DRAFT_LIVE not 1): pool read-only, picks are previews, nobody is adopted, no mail'));
|
||||
}
|
||||
const isStub = () => mode === 'stub';
|
||||
// ---- staging test mode (Marty 2026-11-15, "test apps never touch real people"): with TANK_MODE=iap and DRAFT_LIVE not '1', the pool
|
||||
// and pick status are READ from InstantAdPay, but every pick (instant picks on a purchase and the weekly draft) and every release is a
|
||||
// PREVIEW kept here only: no tank.adopt() on InstantAdPay, no sponsor change, no "X is now your sponsor" email. DRAFT_LIVE=1 at go-live.
|
||||
const live = () => !isStub() && String(process.env.DRAFT_LIVE || '').trim() === '1';
|
||||
const preview = () => !isStub() && !live();
|
||||
const PFILE = () => path.join(C.dataDir, 'preview-picks.json');
|
||||
function pst() { let s = {}; try { s = JSON.parse(fs.readFileSync(PFILE(), 'utf8')); } catch (e) {} s.picked = s.picked || {}; s.log = s.log || []; s.wouldMail = s.wouldMail || 0; return s; }
|
||||
function pput(s) { s.log = s.log.slice(-300); fs.writeFileSync(PFILE() + '.tmp', JSON.stringify(s)); fs.renameSync(PFILE() + '.tmp', PFILE()); }
|
||||
// ---- the InstantAdPay client ----
|
||||
const secret = () => { const s = String(process.env.DRAFT_PARTNER_SECRET || '').trim(); return s.length >= 32 ? s : ''; };
|
||||
const remote = { calls: 0, failed: 0, lastError: null, lastPool: 0 };
|
||||
@@ -82,7 +90,7 @@ function person(p, s, now) {
|
||||
}
|
||||
|
||||
async function candidates(now) {
|
||||
if (!isStub()) { const r = await call('pool', {}); if (!r.ok || !Array.isArray(r.pool)) return []; remote.lastPool = r.pool.length; return r.pool.filter(c => c && c.id).map(candOf); }
|
||||
if (!isStub()) { const r = await call('pool', {}); if (!r.ok || !Array.isArray(r.pool)) return []; remote.lastPool = r.pool.length; const taken = preview() ? pst().picked : {}; return r.pool.filter(c => c && c.id && !taken[String(c.id)]).map(candOf); }
|
||||
const s = st(); now = now || nowFn();
|
||||
return fixture.people.filter(p => !s.adopted[p.id]).map(p => { const x = person(p, s, now); return Object.assign(x, { wallet: !!x.wallet }); })
|
||||
.filter(x => !x.payouts && !x.purchase); // payouts on = out of the tank (the IAP rule)
|
||||
@@ -104,6 +112,13 @@ async function status(ids, now) {
|
||||
return out;
|
||||
}
|
||||
async function adopt(o) {
|
||||
if (preview()) {
|
||||
const s = pst(); const id = String(o.person || ''); if (!id) return { error: 'Not in the holding tank.' };
|
||||
if (s.picked[id]) return { error: 'Already picked (test mode).' };
|
||||
const c = o.coach || {}; s.picked[id] = { coach: c.address || null, at: nowFn(), kind: o.kind || 'draft', week: o.week || null };
|
||||
s.wouldMail++; s.log.push({ at: nowFn(), preview: 'adopt', person: id, coach: c.address || null, kind: o.kind || 'draft' }); pput(s);
|
||||
return { ok: true, ref: 'preview:' + id, preview: true };
|
||||
}
|
||||
if (!isStub()) {
|
||||
const c = o.coach || {}; const body = { rid: rid(), coach: { wallet: c.address, hubId: c.hubId || null, username: c.username || null, positions: Number(c.positions) || 0 },
|
||||
person: o.person, kind: o.kind || 'draft', week: o.week || null, slot: o.slot || null, note: o.note || '' };
|
||||
@@ -121,6 +136,10 @@ async function adopt(o) {
|
||||
return { ok: true, ref: 'stub:' + p.id };
|
||||
}
|
||||
async function release(o) {
|
||||
if (preview() || String(o.ref || '').startsWith('preview:')) { // a preview pick never touches InstantAdPay, even after DRAFT_LIVE flips to 1
|
||||
const s = pst(); const id = String(o.person || ''); delete s.picked[id];
|
||||
s.log.push({ at: nowFn(), preview: 'release', person: id, why: o.why || '' }); pput(s); return { ok: true, outcome: 'returned', preview: true };
|
||||
}
|
||||
if (!isStub()) {
|
||||
const body = { rid: rid(), coach: { wallet: o.coach }, ref: o.ref || null, person: o.person, why: o.kind === 'return' || /window/.test(o.why || '') ? 'return' : 'coach' };
|
||||
let r = await call('release', body); if (r.transient) r = await call('release', body);
|
||||
@@ -136,5 +155,5 @@ function setStatus(id, patch) {
|
||||
for (const k of ['wallet', 'payouts', 'purchase', 'seen']) if (patch[k] !== undefined) o[k] = patch[k] ? (typeof patch[k] === 'number' ? patch[k] : t) : 0;
|
||||
put(s); return { ok: true, over: o };
|
||||
}
|
||||
function view() { if (!C) return {}; const s = isStub() ? st() : null; return { mode, remote: isStub() ? null : Object.assign({ url: C.iapBase, secret: !!secret() }, remote), fixture: fixture ? fixture.people.length : 0, adopted: s ? Object.keys(s.adopted).length : 0, adoptionMailsThatWouldSend: s ? s.mails : 0, log: s ? s.log.slice(-20) : [] }; }
|
||||
module.exports = { init, candidates, status, adopt, release, setStatus, view, isStub, H, D };
|
||||
function view() { if (!C) return {}; const s = isStub() ? st() : null; const ps = preview() ? pst() : null; return { mode, live: live(), testMode: preview(), previewPicks: ps ? Object.keys(ps.picked).length : 0, adoptionMailsSkipped: ps ? ps.wouldMail : 0, remote: isStub() ? null : Object.assign({ url: C.iapBase, secret: !!secret() }, remote), fixture: fixture ? fixture.people.length : 0, adopted: s ? Object.keys(s.adopted).length : 0, adoptionMailsThatWouldSend: s ? s.mails : 0, log: s ? s.log.slice(-20) : [] }; }
|
||||
module.exports = { init, candidates, status, adopt, release, setStatus, view, isStub, live, preview, H, D };
|
||||
|
||||
Reference in New Issue
Block a user