Spooky Doors house ads: an empty street serves one of Marty's programs instead of "Nobody's home"

When a door finds no visit pack and no video, /api/door/open serves a house ad from rates.doorHouseAds
(RM Circle, Drip Runner, Gem Kingdom, PolHunter by default; ref templates carry the player's IAP username
where the program takes a share link). Rotation: never the same program twice in a row, else the one least
recently shown to that member today. Same dwell + Halloween icon check. No advertiser charge and no campaign
imps, but it counts toward doorCapPerDay (visit_repeat row with campaign 0). Callback and receipt add
house: true and program, with credits 0, host null, campaignId 0. doorHouseAds = [] restores none=1.
Admin rates table keeps text columns as text so the list survives a save. qa/door.mjs covers it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-02 15:06:53 -05:00
parent dbbce34202
commit 9809953ae0
7 changed files with 69 additions and 18 deletions
+25 -4
View File
@@ -3,7 +3,8 @@
// Boots server.js on its own port with a throwaway DATA_DIR and throwaway SD/DR secrets, plus a mock Spooky Doors
// game server that records the signed callbacks. Nothing touches production: SD_URL and DR_URL point at the mock.
// Covers: open -> challenge (wrong pick, then right) -> done -> callback signature + receipt, re-open after done,
// "nobody's home" (none=1, door not counted), cap (cap=1), the door/refuel/earn caps staying separate, bad tokens,
// house ads when the street is empty (RM Circle first, then the next program with the player's ref; credits 0, counted),
// "nobody's home" only with doorHouseAds = [] (none=1, door not counted), cap (cap=1), the door/refuel/earn caps staying separate, bad tokens,
// and the Games card season window. Exit code 1 on any failure.
import http from 'node:http';
import crypto from 'node:crypto';
@@ -100,10 +101,30 @@ try {
const again = (await api('/api/door/open?t=' + encodeURIComponent(t1))).j; ok(again && again.done && again.ret === d1.ret, 're-open after done returns the same receipt redirect');
const twice = (await api('/api/door/done', { n: n1, answer: 0 })).j; ok(twice && twice.error, 'a door cannot be completed twice');
// 2. nobody's home: the only pack is visited, no videos -> none=1 and the door is not counted
// 2. the only pack is visited and there are no videos: a house ad (one of Marty's programs) for a smaller treat
const n2 = crypto.randomBytes(12).toString('hex');
const o2 = (await api('/api/door/open?t=' + encodeURIComponent(mint({ kind: 'door', memberId: 77, email: player, nonce: n2, ret: SD + '/play?door=' + n2 })))).j;
ok(o2 && o2.none && o2.why === 'empty' && o2.ret === SD + '/play?door=' + n2 + '&none=1', 'nothing to serve -> ret&none=1', JSON.stringify(o2));
const o2 = (await api('/api/door/open?t=' + encodeURIComponent(mint({ kind: 'door', memberId: 77, email: player, username: 'qadoor', nonce: n2, ret: SD + '/play?door=' + n2 })))).j;
ok(o2 && o2.mode === 'visit' && o2.house === true && o2.program === 'RM Circle' && o2.host === null && o2.target === 'https://rmcircle.team/' && o2.dwell === 2, 'nothing to serve -> a house ad (RM Circle, plain url)', JSON.stringify(o2));
ok(o2 && o2.doors && o2.doors.used === 1, 'house door shows the door count', JSON.stringify(o2 && o2.doors));
await sleep(2200);
const hch = (await api('/api/door/challenge?n=' + n2)).j;
const d2 = (await api('/api/door/done', { n: n2, answer: hch.options.indexOf(CAP[hch.prompt]) })).j;
ok(d2 && d2.ok && d2.posted === true && d2.house === true && d2.program === 'RM Circle' && d2.host === null, 'house door done + callback posted', JSON.stringify(d2 && { ok: d2.ok, posted: d2.posted, house: d2.house, program: d2.program }));
const hr = d2 && verify(new URL(d2.ret).searchParams.get('r'));
ok(hr && hr.kind === 'door-receipt' && hr.nonce === n2 && hr.memberId === 77 && hr.house === true && hr.credits === 0 && hr.host === null && hr.campaignId === 0 && hr.program === 'RM Circle', 'house receipt {house: true, credits: 0, host: null, campaignId: 0, program}', JSON.stringify(hr && { house: hr.house, credits: hr.credits, host: hr.host, campaignId: hr.campaignId, program: hr.program }));
const hb = callbacks[1] && JSON.parse(callbacks[1].raw);
ok(hb && hb.nonce === n2 && hb.house === true && hb.credits === 0 && hb.host === null && hb.program === 'RM Circle' && Object.keys(hb).sort().join() === 'campaignId,credits,host,house,memberId,nonce,program', 'house callback body adds {house, program}', callbacks[1] && callbacks[1].raw);
const camps = (await api('/api/admin/campaigns', null, adminH)).j; const pack = camps && (camps.campaigns || []).find(x => x.id === cid);
ok(pack && pack.imps === 1, 'house door does not touch the pack imps', pack && String(pack.imps));
// next house door: not the same program twice in a row, and the player's username rides along as the program's own ref link
const n2c = crypto.randomBytes(12).toString('hex');
const o2c = (await api('/api/door/open?t=' + encodeURIComponent(mint({ kind: 'door', memberId: 77, email: player, nonce: n2c, ret: SD + '/play?door=' + n2c })))).j;
ok(o2c && o2c.house && o2c.program === 'Drip Runner' && o2c.target === 'https://driprunner.app/r/qadoor' && o2c.doors.used === 2, 'next house door rotates (Drip Runner, /r/<username>) and the first one counted', JSON.stringify(o2c && { program: o2c.program, target: o2c.target, doors: o2c.doors }));
// doorHouseAds = [] turns house doors off: nobody's home again, and the door is not counted
await api('/api/admin/rates', { method: 'PATCH', data: { doorHouseAds: [] } }, adminH);
const n2e = crypto.randomBytes(12).toString('hex');
const o2e = (await api('/api/door/open?t=' + encodeURIComponent(mint({ kind: 'door', memberId: 77, email: player, nonce: n2e, ret: SD + '/play?door=' + n2e })))).j;
ok(o2e && o2e.none && o2e.why === 'empty' && o2e.ret === SD + '/play?door=' + n2e + '&none=1', 'doorHouseAds [] + nothing to serve -> ret&none=1', JSON.stringify(o2e));
// 2b. doors may repeat a campaign after doorRepeatDays (0 here = no cooldown): the same pack is served again
await api('/api/admin/rates', { method: 'PATCH', data: { doorRepeatDays: 0 } }, adminH);