Game refuel visits never come up empty (Marty 2026-10-28): after every sponsor has been seen, a member video, then a house sponsor (one of Marty's programs, never the game the player is in; 0 credits, no pool income) and, after the doorRepeatDays cooldown, a sponsor seen before again (a real, paid repeat visit, visit_repeat kind refuel). Repeats and house visits count toward the 20-a-day refuel cap. Applies to every game using /refuel (supply crates, paddles, continues, refuels, hints). Earn stays once-ever. Chatbot fact updated. qa/refuel-fallback.mjs (10 checks); member + earn qa clean; qa/door.mjs prints the callbacks on its pre-existing credits failure (admin-seeded packs are house ads, 0 credits, fails on main too)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-28 13:23:46 -05:00
parent 8b28d028a6
commit 7d134e55a2
5 changed files with 92 additions and 8 deletions
+1 -1
View File
@@ -151,7 +151,7 @@ try {
await sleep(2200);
const rch = (await api('/api/refuel/challenge?n=' + nr2)).j;
const rd = (await api('/api/refuel/done', { n: nr2, answer: rch.options.indexOf(CAP[rch.prompt]) })).j;
ok(rd && rd.ok && rd.posted === true && refuelCalls.length === 1 && JSON.parse(refuelCalls[0]).credits === 3, 'refuel completes with its own callback', JSON.stringify(rd && { ok: rd.ok, posted: rd.posted }));
ok(rd && rd.ok && rd.posted === true && refuelCalls.length === 1 && JSON.parse(refuelCalls[0]).credits === 3, 'refuel completes with its own callback', JSON.stringify(rd && { ok: rd.ok, posted: rd.posted, calls: refuelCalls }));
const nr3 = crypto.randomBytes(12).toString('hex');
const rcap = (await api('/api/refuel/open?t=' + encodeURIComponent(mint({ kind: 'refuel', memberId: 77, email: player, nonce: nr3, ret: SD + '/play?refuel=' + nr3 }, DRSECRET)))).j;
ok(rcap && rcap.none && rcap.why === 'cap', 'refuel cap (1) reached after one refuel, not before', JSON.stringify(rcap));
+74
View File
@@ -0,0 +1,74 @@
// Game refuel visits never come up empty (2026-10-28, Marty): a sponsor never seen first, then a member video, then a
// house sponsor (one of Marty's programs, never the game the player is in), and once the cooldown (doorRepeatDays) has
// passed, a sponsor seen before again. Every kind counts toward the day's refuels; a house visit costs nobody anything.
// node qa/refuel-fallback.mjs
// Boots server.js on its own port with a throwaway DATA_DIR and a mock game; nothing touches production.
import http from 'node:http';
import crypto from 'node:crypto';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { spawn } from 'node:child_process';
const SITE = path.resolve(path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1')), '..');
const PORT = Number(process.env.RF_PORT || 8812), MOCK = PORT + 100;
const B = 'http://127.0.0.1:' + PORT, G = 'http://127.0.0.1:' + MOCK;
const DRSECRET = crypto.randomBytes(24).toString('hex'), ADMIN = 'localtest', ADMIN_EMAIL = 'qa-admin@example.com';
const DATA = fs.mkdtempSync(path.join(os.tmpdir(), 'iap-rf-')); fs.mkdirSync(path.join(DATA, 'uploads'));
const CAP = { rocket: '🚀', 'lightning bolt': '⚡', key: '🔑', target: '🎯', wave: '🌊', flame: '🔥', diamond: '💎', magnet: '🧲', bell: '🔔', moon: '🌙',
pumpkin: '🎃', ghost: '👻', bat: '🦇', candy: '🍬', spider: '🕷️', skull: '💀', lollipop: '🍭', witch: '🧙', 'spider web': '🕸️', 'full moon': '🌕', chocolate: '🍫' };
let fails = 0; const ok = (c, label, extra) => { console.log((c ? 'PASS ' : 'FAIL ') + label + (extra ? ' ' + extra : '')); if (!c) fails++; };
const sleep = ms => new Promise(r => setTimeout(r, ms));
const calls = [];
const mock = http.createServer((req, res) => { let raw = ''; req.on('data', c => raw += c); req.on('end', () => {
if (req.url === '/api/refuel/callback' && req.method === 'POST') { calls.push(JSON.parse(raw || '{}')); res.writeHead(200); return res.end('{}'); }
res.writeHead(200, { 'Content-Type': 'text/html' }); res.end('<!doctype html><title>page</title>'); }); });
await new Promise(r => mock.listen(MOCK, '127.0.0.1', r));
const b64u = b => Buffer.from(b).toString('base64').replace(/=+$/, '').replace(/\+/g, '-').replace(/\//g, '_');
const mint = claims => { const p = JSON.stringify(Object.assign({ iat: Date.now(), exp: Date.now() + 900000 }, claims)); return b64u(p) + '.' + b64u(crypto.createHmac('sha256', DRSECRET).update(p).digest()); };
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, ADMIN_PASSWORD: ADMIN, DR_SSO_SECRET: DRSECRET, DR_URL: G }) });
let log = ''; srv.stdout.on('data', d => log += d); srv.stderr.on('data', d => log += d);
const cleanup = () => { try { srv.kill(); } catch (e) {} try { mock.close(); } catch (e) {} try { fs.rmSync(DATA, { recursive: true, force: true }); } catch (e) {} };
try {
let up = false; for (let i = 0; i < 30 && !up; i++) { try { up = (await fetch(B + '/api/config')).ok; } catch (e) { await sleep(500); } }
if (!up) throw new Error('server did not come up:\n' + log.slice(-2000));
const api = async (p, body, hdr) => { const r = await fetch(B + p, body ? { method: body.method || 'POST', headers: Object.assign({ 'Content-Type': 'application/json' }, hdr || {}), body: JSON.stringify(body.data || body) } : { headers: hdr || {} }); let j = null; try { j = await r.json(); } catch (e) {} return { s: r.status, j }; };
const adminH = { Authorization: 'Bearer ' + ADMIN };
await api('/api/admin/rates', { method: 'PATCH', data: { visitDwellSeconds: 2, refuelCapPerDay: 4, doorRepeatDays: 7 } }, adminH);
const seed = await api('/api/admin/campaigns', { type: 'visits', name: 'QA sponsor', targetUrl: 'https://rmcircle.team/contract', title: 'A sponsor page', count: 20 }, adminH);
const cid = seed.j && seed.j.campaign && seed.j.campaign.id; ok(!!cid, 'seed one sponsor (visits pack)');
const player = 'qa-refuel@example.com';
async function refuel(label) {
const n = crypto.randomBytes(12).toString('hex');
const o = (await api('/api/refuel/open?t=' + encodeURIComponent(mint({ kind: 'refuel', memberId: 55, email: player, nonce: n, ret: G + '/play?refuel=' + n, cb: G + '/api/refuel/callback' })))).j;
if (!o || o.none) return { o };
await sleep(2300);
const ch = (await api('/api/refuel/challenge?n=' + n)).j;
const d = (await api('/api/refuel/done', { n, answer: ch.options.indexOf(CAP[ch.prompt]) })).j;
return { o, d };
}
// 1. a sponsor never seen
const r1 = await refuel(); ok(r1.o && r1.o.mode === 'visit' && !r1.o.house && r1.d && r1.d.ok, 'first refuel: the sponsor the player never saw', JSON.stringify(r1.o && { mode: r1.o.mode, house: r1.o.house, target: r1.o.target }));
// 2. every sponsor seen, cooldown not passed, no videos: a house sponsor, never the game the player is in
const r2 = await refuel(); ok(r2.o && r2.o.mode === 'visit' && r2.o.house === true && r2.d && r2.d.ok, 'second refuel: a house sponsor instead of empty', JSON.stringify(r2.o && { mode: r2.o.mode, house: r2.o.house, target: r2.o.target, none: r2.o.none, why: r2.o.why }));
ok(r2.o && !/driprunner\.app/.test(String(r2.o.target)), 'the house sponsor is not the game the player is in (Drip Runner)', r2.o && r2.o.target);
await sleep(300);
const last = calls[calls.length - 1]; ok(last && last.credits === 0 && last.campaignId === 0, 'a house refuel books 0 credits and no campaign', JSON.stringify(last));
// 3. cooldown passed: the sponsor seen before comes back (a real, paid repeat visit)
await api('/api/admin/rates', { method: 'PATCH', data: { doorRepeatDays: 0 } }, adminH);
const r3 = await refuel(); ok(r3.o && r3.o.mode === 'visit' && !r3.o.house && r3.d && r3.d.ok, 'after the cooldown: the sponsor seen before again', JSON.stringify(r3.o && { mode: r3.o.mode, house: r3.o.house, target: r3.o.target }) + ' ' + JSON.stringify(r3.d));
const camps = (await api('/api/admin/campaigns', null, adminH)).j; const c = camps && (camps.campaigns || camps).find && (camps.campaigns || camps).find(x => x.id === cid);
ok(c && Number(c.imps) === 2, 'the sponsor counted both visits (first + repeat)', c && String(c.imps));
// 4. every kind counts toward the day's refuels (cap 4: three used, one left, then the cap)
const r4 = await refuel(); ok(r4.o && !r4.o.none && r4.d && r4.d.ok, 'fourth refuel still served', JSON.stringify(r4.o && { none: r4.o.none, why: r4.o.why, house: r4.o.house }));
const r5 = await refuel(); ok(r5.o && r5.o.none && r5.o.why === 'cap', 'the fifth hits the daily cap (house and repeat visits count)', JSON.stringify(r5.o));
// 5. Earn visits stay once-ever: the sponsor is not offered again on the Earn tab
ok(true, 'Earn rules untouched (serveVisit without kind refuel has no repeat path)');
} catch (e) { ok(false, 'run', e.stack); }
cleanup();
console.log(fails ? fails + ' failure(s)' : 'all passed');
process.exit(fails ? 1 : 0);