Files
instantadpay/qa/chatbot-parse.mjs
T
martbost 1089942bca Game POL pays to any LINKED wallet (Marty approved "build all three", 2026-10-27)
- walletnudge.js: the hourly push hands the member's signature-linked wallet (accounts.address, only set by
  auth.verifyChallenge -> accounts.linkWallet) to every game holding an unpaid balance, activated or not; memberId is the
  on-chain id when there is one, else 0 (a failed chain read falls back to the stored id instead of skipping the row).
  Holding-tank members waiting to switch on payouts no longer have their game POL stuck. Game side unchanged contract:
  signed POST, fill-empty-only (different wallet = 409, retried once a day), idempotent.
- Nudge copy (no linked wallet only): "You've earned X POL in <game>. Link your wallet (one free signature) and it's sent
  automatically, including everything you've earned so far." + /my#wallet; never mentions switching on payouts.
- The IAP -> game /auth tokens already carried wallet: a.address regardless of activation (no change).
- chatbot.js: game-pol-wallet canned answer (ahead of the per-game entries) + GAME POL TO ANY LINKED WALLET prompt fact
- qa/walletnudge.test.cjs (mock game: non-activated push with memberId 0, activated push, chain-read failure, nudge copy,
  409 refusal + daily retry), wired into qa/run.sh member + walletnudge; chatbot-parse routing cases for the new answer

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 09:19:10 -05:00

107 lines
5.8 KiB
JavaScript

// The OpenRouter response shapes that broke the chatbot on 2026-09-17, and the ones
// that must keep working. Runs the real parse branch from chatbot.js with a fake https
// server, so this is the actual code path, not a copy of it.
//
// Run: node qa/chatbot-parse.mjs
import http from 'node:http';
import https from 'node:https';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const ok = [], bad = [];
const t = (n, c, extra) => { (c ? ok : bad).push(n + (c || !extra ? '' : ' -> ' + extra)); };
let BODY = '';
const srv = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(BODY); });
await new Promise(r => srv.listen(0, '127.0.0.1', r));
const port = srv.address().port;
// point chatbot.js's https.request at the local plain-http stub
const realRequest = https.request;
https.request = (opts, cb) => http.request({ ...opts, hostname: '127.0.0.1', port, protocol: 'http:', rejectUnauthorized: false }, cb);
process.env.OPENROUTER_API_KEY = 'test-key';
const cb = require('../chatbot.js');
cb.init({ dataDir: '.', chain: null });
const good = JSON.stringify({ choices: [{ message: { content: 'Here is a straight answer.' } }] });
const ask = async q => (await cb.answer(q)).reply;
const FAILMSG = /did not come back to me just now/;
// 1. the exact production failure: 200 with only keepalive padding, no JSON at all
BODY = '\n \n \n';
t('keepalive-only body no longer crashes into a dead end', FAILMSG.test(await ask('explain something obscure')));
// 2. the shape that ALSO arrives normally: keepalive padding, THEN the real JSON
BODY = '\n \n' + good;
t('keepalive padding before real JSON still parses', /straight answer/.test(await ask('explain something obscure')));
// 3. plain JSON, the happy path
BODY = good;
t('plain JSON still parses', /straight answer/.test(await ask('explain something obscure')));
// 4. SSE-style comment lines before the JSON
BODY = ': OPENROUTER PROCESSING\n: OPENROUTER PROCESSING\n' + good;
t('SSE comment lines before the JSON still parse', /straight answer/.test(await ask('explain something obscure')));
// 5. 200 with an empty content string is a failure, not a blank reply to the member
BODY = JSON.stringify({ choices: [{ message: { content: ' ' } }] });
t('empty content is treated as a failure, never sent as a blank answer', FAILMSG.test(await ask('explain something obscure')));
// 6. garbage that is not JSON at all
BODY = '<html>502 bad gateway</html>';
t('non-JSON body is handled', FAILMSG.test(await ask('explain something obscure')));
// 7. canned answers never touch the network, so they survive any outage
BODY = '';
const pif = await ask('Should I pif someone from the holding tank');
t('the PIF question answers with no AI at all', /PIF is a gift/.test(pif), pif.slice(0, 80));
t('and it says you cannot PIF someone still in the tank', /still sitting in the holding tank/.test(pif));
// Marty, 2026-09-17: the risk is the answer, not a footnote. Sending POL to someone
// who has never replied is the easiest money on the site to lose, so every one of
// these must survive any future edit to the wording.
t('it says talk to them and get a commitment FIRST', /do not send anything until you have actually talked to that person/i.test(pif));
t('it says the transfer is irreversible with no refund', /no refund, no chargeback/i.test(pif));
t('it says support cannot pull it back', /nothing we can do to pull it back/i.test(pif));
t('it says they may go quiet or spend it elsewhere', /go quiet, spend it on something else, or never sign in again/i.test(pif));
t('it flags the tank member as the highest risk case', /easiest money on this site to lose/i.test(pif));
t('it gives the honest arithmetic both ways', /costs you about half/.test(pif) && /costs you all of it/.test(pif));
t('it says never gift money you need and never borrow', /never gift money you need, never borrow/i.test(pif));
t('it never sells PIF as a tactic', !/you should (definitely |really )?pif/i.test(pif));
// 8. ROUTING. CANNED is first-match-wins, so widening any pattern can silently steal a
// neighbour. Both of these already happened: "how much do I earn" returned the price
// ladder, and "what do I get for buying a package" returned the commission split. Every
// pattern edit must keep this table green.
const WANT = {
PIF: /PIF is a gift/,
PRICE: /Five packages, priced/,
EARN: /Every package splits the same way/,
TANK: /The holding tank is where free members/,
GAMEPOL: /Game POL is paid to the wallet linked/
};
const ROUTES = [
['PIF', 'should I pif someone from the holding tank'], ['PIF', 'what is pif'],
['PIF', 'should i pay it forward'], ['PIF', 'can I front someone the $20'],
['PIF', 'should I spot them the money'], ['PIF', 'should I pay for their first package'],
['PIF', 'can I just buy the package for someone in my downline who wont respond'],
['PIF', 'is it smart to fund a new members first package for them'],
['PRICE', 'which package should i buy'], ['PRICE', 'how much is the starter package'],
['PRICE', 'should I buy the $20 package'], ['PRICE', 'what do I get for buying a package'],
['PRICE', 'how much does it cost'],
['EARN', 'how much do I earn'], ['EARN', 'how much can i make'],
['EARN', 'what will i get paid'], ['EARN', 'what is the commission'],
['TANK', 'how does the holding tank work'], ['TANK', 'can I adopt someone from the tank'],
['GAMEPOL', 'my gem kingdom pol was never sent'], ['GAMEPOL', 'it says 1.50 POL is waiting for your wallet'],
['GAMEPOL', 'do I need to switch on payouts to get my game pol']
];
for (const [want, q] of ROUTES) {
const reply = await ask(q);
t('routes to ' + want + ': "' + q + '"', WANT[want].test(reply), String(reply).slice(0, 55));
}
https.request = realRequest;
srv.close();
console.log('PASS ' + ok.length);
for (const b of bad) console.log('FAIL ' + b);
process.exit(bad.length ? 1 : 0);