Tiers (Marty 2026-11-02, every game must fund itself): guests earn nothing (a guest's chapters, drips and best follow them at sign-in, the POL does not; no more collected= payout on /auth), a free InstantAdPay account earns freeSharePct (25, admin) of the chapter drip with the note "Game Pass holders earn the full amount.", Game Pass holders earn the full drip plus the shield perk, GAMEPASS off = everyone full. /api/me carries tier, freeSharePct and yourDrip; landing, lobby, clear card, tester briefing and share preview say play free, sign in to earn a taste, Game Pass for the full table. Tests: guest 0 at sign-in, free 25%, pass 100%, gp off full, settings key.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-02 17:01:10 -06:00
parent 4d8dde2ad2
commit b69086aaac
11 changed files with 92 additions and 55 deletions
+23 -12
View File
@@ -40,26 +40,37 @@ const ok = (name, cond, info) => { if (cond) { pass++; console.log(' ok ', nam
ok('48 h without an answer: stuck, the admin chat told once', rr.stuck === 1 && alerts.length === 1 && alerts[0][0] === 'gpstuck'); gp.dequeue(7, '', 'q:old'); mode = 'ok';
// ---- the game: a chapter's first clear pays once -> 'progress'; the only POL Drip Runner pays
// the tiers (Marty 2026-11-02): guests earn nothing, a free account earns freeSharePct (25) of the drip, Game Pass holders the drip
ledger.setSettings({ seedPol: 100, dailyCapPol: 5, dripPol: 0.01 });
const me = { memberId: 7, email: 'hugh@example.com', username: 'hugh', wallet: '0x' + 'a'.repeat(40) }, today = ledger.ctDay();
ok('classification: every chapter is progress', ledger.kindOf('chapter:1') === 'progress' && ledger.kindOf('chapter:9') === 'progress');
ok('settings: freeSharePct defaults to 25 and is admin-editable', ledger.settings().freeSharePct === 25 && ledger.freeShare() === 25 && ledger.setSettings({ freeSharePct: 50 }).freeSharePct === 50 && ledger.dripFor(me) === 0.005 && ledger.setSettings({ freeSharePct: 25 }).freeSharePct === 25);
ok('tiers: no pass = free tier at 25% of the drip (4 decimals)', ledger.tierOf(me) === 'free' && !ledger.fullTier(me) && ledger.dripFor(me) === 0.0025);
seen.length = 0; let g = await ledger.chapterDripGated(me, 1, true);
ok('chapter 1 pays what IAP allowed, asked as progress with ref chapter:1', g.reason === 'paid' && g.pol === 0.01 && seen[0].ref === 'chapter:1' && seen[0].kind === 'progress' && seen[0].memberId === 7 && seen[0].email === 'hugh@example.com', g);
ok('free tier: chapter 1 asks IAP for the scaled 0.0025 as progress (ref chapter:1), pays it, the note names the Pass', g.reason === 'paid' && g.pol === 0.0025 && seen[0].pol === 0.0025 && seen[0].ref === 'chapter:1' && seen[0].kind === 'progress' && seen[0].memberId === 7 && seen[0].email === 'hugh@example.com' && g.note === 'Game Pass holders earn the full amount.', g);
g = await ledger.chapterDripGated(me, 1, false); ok('a replay is not a reward (no IAP call)', g.reason === 'replay' && seen.length === 1);
script['chapter:2'] = { allowed: 0, deferred: 0.01 }; g = await ledger.chapterDripGated(me, 2, true);
ok('chapter 2 deferred: handled, owed, the player told', g.reason === 'deferred' && g.pol === 0 && ledger.account(7).gpOwed === 0.01 && /pays out over the next days/.test(g.note) && store.read('drips', []).some(d => d.chapter === 2 && d.pol === 0));
script['carry:' + today] = { allowed: 0.01, carried: 0.01 }; ok('carry sweep collects it once a day', (await ledger.carrySweep()) === 0.01 && ledger.account(7).gpOwed === 0 && (await ledger.carrySweep()) === 0);
mode = '500'; g = await ledger.chapterDripGated(me, 3, true); ok('IAP down: queued, nothing paid, the player told', g.reason === 'iap' && gp.queued(7, me.email, 'chapter:3') && /recorded/.test(g.note));
const n = seen.length; g = await ledger.chapterDripGated(me, 3, true); ok('a queued chapter is not asked again', g.reason === 'iap' && seen.length === n);
mode = 'ok'; await gp.retry(ledger.payQueued, Date.now() + gp.RETRY_MS + 1); ok('the queued chapter pays on retry', !gp.queued(7, me.email, 'chapter:3') && store.read('drips', []).some(d => d.chapter === 3 && d.pol === 0.01) && ledger.account(7).unpaid === 0.03);
ok('the pool only counts what was paid', ledger.pool().out === 0.03);
// the pass: remembered from the hand-off, and re-recorded by every grant answer (so the stub says pass: true for a holder)
gp.rememberPass(7, me.email, { active: true, until: Date.now() + 86400000 }); ok('tiers: pass active = full tier, the whole drip', ledger.tierOf(me) === 'full' && ledger.fullTier(me) && ledger.dripFor(me) === 0.01);
for (const ref of ['chapter:2', 'chapter:4', 'carry:' + today]) script[ref] = { allowed: 0.01, pass: true };
g = await ledger.chapterDripGated(me, 2, true); ok('pass holder: chapter 2 pays the full 0.01, no free note', g.reason === 'paid' && g.pol === 0.01 && seen.at(-1).pol === 0.01 && !g.note, g);
script['chapter:3'] = { allowed: 0, deferred: 0.01, pass: true }; g = await ledger.chapterDripGated(me, 3, true);
ok('chapter 3 deferred: handled, owed, the player told', g.reason === 'deferred' && g.pol === 0 && ledger.account(7).gpOwed === 0.01 && /pays out over the next days/.test(g.note) && store.read('drips', []).some(d => d.chapter === 3 && d.pol === 0));
script['carry:' + today] = { allowed: 0.01, carried: 0.01, pass: true }; ok('carry sweep collects it once a day', (await ledger.carrySweep()) === 0.01 && ledger.account(7).gpOwed === 0 && (await ledger.carrySweep()) === 0);
mode = '500'; g = await ledger.chapterDripGated(me, 4, true); ok('IAP down: queued, nothing paid, the player told', g.reason === 'iap' && gp.queued(7, me.email, 'chapter:4') && /recorded/.test(g.note));
const n = seen.length; g = await ledger.chapterDripGated(me, 4, true); ok('a queued chapter is not asked again', g.reason === 'iap' && seen.length === n);
mode = 'ok'; await gp.retry(ledger.payQueued, Date.now() + gp.RETRY_MS + 1); ok('the queued chapter pays on retry', !gp.queued(7, me.email, 'chapter:4') && store.read('drips', []).some(d => d.chapter === 4 && d.pol === 0.01) && ledger.account(7).unpaid === 0.0325);
ok('the pool only counts what was paid', ledger.pool().out === 0.0325);
// a member with no wallet: negative local id (sso.emailId) -> memberId 0 + email on the wire; the pass flag keyed by email
const nw = { memberId: sso.emailId('nowallet@example.com'), email: 'nowallet@example.com', username: 'nw', wallet: null };
ok('the negative local id is never sent', nw.memberId < 0 && ledger.iapId(nw) === 0);
g = await ledger.chapterDripGated(nw, 1, true); ok('a wallet-less member is gated by email', g.reason === 'paid' && seen.at(-1).memberId === 0 && seen.at(-1).email === 'nowallet@example.com');
const guest = { memberId: -999999999999, guest: true, email: null }; seen.length = 0; g = await ledger.chapterDripGated(guest, 1, true); ok('a guest gets the plain chapterDrip (no IAP call)', seen.length === 0 && g.reason === 'paid');
ledger.setSettings({ dailyCapPol: 0.001 }); g = await ledger.chapterDripGated(me, 4, true); ok('the local daily cap still stands in front of IAP', g.reason === 'cap'); ledger.setSettings({ dailyCapPol: 5 });
process.env.GAMEPASS = 'off'; seen.length = 0; g = await ledger.chapterDripGated(me, 4, true); ok('GAMEPASS=off: the plain chapterDrip, no IAP call', g.reason === 'paid' && seen.length === 0); process.env.GAMEPASS = 'on';
g = await ledger.chapterDripGated(nw, 1, true); ok('a wallet-less member is gated by email, on the free tier', g.reason === 'paid' && g.pol === 0.0025 && seen.at(-1).memberId === 0 && seen.at(-1).email === 'nowallet@example.com');
const guest = { memberId: -999999999999, guest: true, email: null }; seen.length = 0; const drips0 = store.read('drips', []).length; g = await ledger.chapterDripGated(guest, 1, true);
ok('a guest earns nothing: no IAP call, no drip row, reason guest (2026-11-02)', seen.length === 0 && g.reason === 'guest' && g.pol === 0 && store.read('drips', []).length === drips0 && ledger.tierOf(guest) === 'guest');
ok('...on the plain path too', ledger.chapterDrip(guest, 1, true).reason === 'guest' && store.read('drips', []).length === drips0);
ledger.setSettings({ dailyCapPol: 0.001 }); g = await ledger.chapterDripGated(me, 5, true); ok('the local daily cap still stands in front of IAP', g.reason === 'cap'); ledger.setSettings({ dailyCapPol: 5 });
gp.rememberPass(7, me.email, false);
process.env.GAMEPASS = 'off'; seen.length = 0; ok('GAMEPASS=off: everyone is on the full tier', ledger.fullTier(me) && ledger.tierOf(me) === 'full' && ledger.dripFor(me) === 0.01 && ledger.tierOf(guest) === 'guest');
g = await ledger.chapterDripGated(me, 5, true); ok('GAMEPASS=off: the plain chapterDrip pays the full drip, no IAP call, no free note', g.reason === 'paid' && g.pol === 0.01 && seen.length === 0 && !g.note); process.env.GAMEPASS = 'on';
ok('history explains deferral and carry', ledger.balance(7).history.some(h => /paying out over the next days/.test(h.label)) && ledger.balance(7).history.some(h => /Carried-over/.test(h.label)));
// the perk: a shield at the start of every run while the pass is active
gp.rememberPass(7, me.email, false); let run = game.start(me, 390, 760); ok('no pass: no free shield', run.armed.shield === false && !run.armed.passShield);
+7 -4
View File
@@ -39,6 +39,8 @@ const spawnLib = require('../lib/spawn');
const tok0 = sso.mint({ memberId: 42, email: 'runner@example.com', wallet: '0x' + 'ab'.repeat(20), username: 'runner42' });
const denied = await call('/auth?t=' + tok0); eq(denied.status, 403, 'a member not on the tester list is refused');
const st = await admin('/api/admin/settings', { testers: ['runner@example.com'], thresholdPol: 0.02, dripPol: 0.01 }); eq(st.body.settings.testers, ['runner@example.com'], 'admin adds a tester');
eq((await admin('/api/admin/state')).body.settings.freeSharePct, 25, 'freeSharePct defaults to 25');
eq((await admin('/api/admin/settings', { freeSharePct: 40 })).body.settings.freeSharePct, 40, 'admin saves freeSharePct'); await admin('/api/admin/settings', { freeSharePct: 25 });
const tok = sso.mint({ memberId: 42, email: 'runner@example.com', wallet: '0x' + 'ab'.repeat(20), username: 'runner42' });
const a = await call('/auth?t=' + tok); eq([a.status, a.headers.get('location')], [302, '/play'], 'a listed member signs in and lands on the game');
eq((await call('/auth?t=' + tok)).status, 400, 'the hand-off token cannot be replayed');
@@ -116,13 +118,14 @@ const spawnLib = require('../lib/spawn');
const ggen = spawnLib.drips(gr.seed, W, H); const gcl = []; let gT = 0; while (gcl.length < 20) { const gg = ggen(); for (const d of gg.drips) if (gcl.length < 20) { gT = spawnLib.arrival(gg.t, d.x0, W, gr.speed) + 0.1; gcl.push({ k: 'd', i: d.i, t: Math.round(gT * 1000) / 1000 }); } }
backdate(gr.runId, gT + 5);
const gev = (await hit('/api/run/events', { method: 'POST', body: JSON.stringify({ runId: gr.runId, t: gT + 0.2, events: gcl, goal: true }) }, g)).body;
eq([gev.cleared.chapter, gev.cleared.pol, gev.cleared.reason], [1, 0, 'guest'], 'a guest clear pays nothing yet (reason guest)');
eq([gev.cleared.chapter, gev.cleared.pol, gev.cleared.reason], [1, 0, 'guest'], 'a guest clear pays nothing (reason guest)');
eq((await hit('/api/me', {}, g)).body.pool.tier, 'guest', '/api/me says tier guest');
eq((await hit('/api/refuel/start', { method: 'POST', body: JSON.stringify({ runId: gr.runId }) }, g)).status, 403, 'a guest cannot refuel before signing in');
// the newcomer joins IAP under runner42 and signs in: the guest run is adopted and the clear pays
// the newcomer joins IAP under runner42 and signs in: the guest run is adopted; the progress follows, the POL does not (2026-11-02)
const tokN = sso.mint({ memberId: 77, email: 'newbie@example.com', wallet: '0x' + 'cd'.repeat(20), username: 'newbie', sponsorRef: 'runner42' });
const au = await hit('/auth?t=' + tokN, {}, g); g = jarAdd(g, au.set);
eq([au.status, au.loc], [302, '/play?collected=1'], 'sign-in adopts the guest and pays the pending clear');
const nme = (await hit('/api/me', {}, g)).body; eq([nme.me.guest, nme.player.chapter, nme.player.bank, nme.balance.unpaid], [false, 2, 20, 0.01], 'progress and the drip followed the newcomer');
eq([au.status, au.loc], [302, '/play?carried=1'], 'sign-in adopts the guest progress and pays nothing for guest clears');
const nme = (await hit('/api/me', {}, g)).body; eq([nme.me.guest, nme.player.chapter, nme.player.bank, nme.balance.unpaid, nme.balance.earnedTotal, nme.pool.tier], [false, 2, 20, 0, 0, 'full'], 'progress followed the newcomer, no POL for the guest clear; GAMEPASS off = full tier');
// the newcomer refuels: runner42 (their IAP sponsor) gets the slice
const nr = (await hit('/api/run/start', { method: 'POST', body: JSON.stringify({ W, H }) }, g)).body;
const nrf = (await hit('/api/refuel/start', { method: 'POST', body: JSON.stringify({ runId: nr.runId }) }, g)).body;