Files
rm-circle-team-router/qa/harness-server.js
T
martbost 0254f933be Find a Member: public lookup at /lookup (Marty 2026-11-14)
One box: member ID or wallet address -> member ID, wallet (short, full on
hover + Copy), level and tier, join date, sponsor ID (clickable), direct
referral count, Polygonscan link, public dashboard link. Chain facts only,
never names or emails. RM Circle only; nothing from any other site.

- chain.lookupPublic: served from the indexed state (zero RPC); only a
  position or wallet the index has not seen yet falls back to one eth_call
  (memberId(address) 0x39106821, verified live: 0x7c7D...d3c2 -> 7230)
- /api/public/lookup: own 12/min per-IP limiter, 3-minute answer cache
  (negative answers too), global budget of 60 RPC fallbacks per minute
- page lookup.html + lookup.js (no inline script), ?q= deep links, /find alias
- "Find a Member" in every site footer; chat.js?v=20261114a
- chatbot: canned answer in chat.js + FACT line and Site pages entry in the
  AI system prompt
- tests: qa/lookup-unit.mjs (25), qa/lookup-e2e.mjs (51, desktop + phone,
  CSP, no-email, rate limit) against qa/harness-server.js LOOKUP_SEED

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 12:53:19 -06:00

54 lines
2.8 KiB
JavaScript

// QA harness: boots the real server with the chain reads stubbed, so the join flow
// can be driven end to end without spending POL or waiting on the indexer.
//
// TEST_ADDR=0x.. TEST_ID=9001 COLD=1 PORT=3399 DATA_DIR=... node qa/harness-server.js
//
// COLD=1 reproduces the state that broke #787: the cached index does NOT know the
// brand-new position, so only a live contract read can resolve it.
const path = require('path');
process.chdir(path.join(__dirname, '..'));
const chain = require('../chain.js');
const ADDR = String(process.env.TEST_ADDR || '').toLowerCase();
const ID = Number(process.env.TEST_ID || 9001);
const COLD = process.env.COLD !== '0';
let seeded = !COLD; // warm index = already knows the member
chain.startIndexer = function () { /* no RPC polling in the harness */ };
chain.memberIdByAccount = function (a) {
return (seeded && String(a || '').toLowerCase() === ADDR) ? ID : null;
};
chain.verifyMember = async function (id) {
if (Number(id) !== ID) return { registered: false };
seeded = true; // a live read seeds the index, as the real one does
return { registered: true, id: ID, account: ADDR, referrerId: 21, uplineId: 21, tier: 2, level: 1,
directCount: 0, joinedAt: Math.floor(Date.now() / 1000), tierName: 'Premium', levelName: 'Scintilla' };
};
chain.memberPublic = async function (id) { return Number(id) === ID ? { registered: true, id: ID, level: 1, tier: 2, directCount: 0 } : { registered: false, id }; };
chain.memberLookup = async function (id) { return chain.memberPublic(id); };
chain.isInTeam = function () { return true; };
chain.getPayoutsPublic = function () { return []; };
chain.getIncome = async function () { return []; };
chain.getMatrixTree = async function () { return null; };
chain.getCoachingScan = async function () { return { rows: [] }; };
chain.liveDirects = async function () { return []; };
chain.balanceOf = async function () { return '0'; };
chain.getOwnerUpgradeNeeds = async function () { return null; };
chain.getOrgRouting = async function () { return null; };
chain.getOrgShare = async function () { return null; };
chain.nextOpenPosition = function () { return 21; };
// LOOKUP_SEED=<file.json>: seed the in-memory index for the /lookup suite, and keep the
// lookup offline (a miss reports not-found instead of reaching a real Polygon RPC).
if (process.env.LOOKUP_SEED) {
chain.__test.setState(JSON.parse(require('fs').readFileSync(process.env.LOOKUP_SEED, 'utf8')));
const realLookup = chain.lookupPublic;
chain.lookupPublic = async function (raw) {
const r = await realLookup(raw, { allowRpc: false });
if (r && r.busy) { global.__lookupRpcFallbacks = (global.__lookupRpcFallbacks || 0) + 1; return { found: false, query: r.query }; }
return r;
};
}
console.log('harness: addr=' + ADDR + ' id=' + ID + ' coldIndex=' + COLD);
require('../server.js');