Files
linkspin/qa/kb-retrieval.cjs
T
martbost c037923528 Remove every MoonPay mention and link (ZeroFox/MoonPay false-positive takedown, 2026-10-26)
- server.js: /api/moonpay-url endpoint deleted (MOONPAY_PUBLIC_KEY / MOONPAY_SECRET_KEY env and siteConfig().moonpayPublicKey no longer read)
- admin.js: moonpayPublicKey settings label dropped
- credits.html + credits-screen.js: "Buy POL with a card" button and handler removed
- my.js: openMoonpay() and the card-buy button removed; the New to crypto note now points to /wallets ("Wallet help")
- wallets.html + wallets.js: card section rewritten neutrally (any major exchange or on-ramp, POL on Polygon, your own address), wlMoonpay button logic, in-wallet note and MoonPay FAQ/disclaimer replaced
- chatbot.js: wallets canned answer, tags/regex and FACTS rewritten with no brand named
- kb-seed.js: f-moonpay-declined replaced by f-card-declined (the old seed is retired from kb.json on the next boot unless it was admin-edited)
- qa/kb-retrieval.cjs: case updated to f-card-declined
- cache tags bumped: credits-screen.js, my.js, wallets.js ?v=20261026a

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 08:04:32 -05:00

49 lines
3.2 KiB
JavaScript

// Knowledge-base retrieval unit test (kb.js): the right entry must rank first for each sample question,
// scored over the real seeds (chatbot.js CANNED + kb-seed.js). No server, no network.
// node qa/kb-retrieval.cjs
const path = require('path');
const kb = require(path.join(__dirname, '..', 'kb.js'));
const chatbot = require(path.join(__dirname, '..', 'chatbot.js'));
const { buildIndex, rank, relevant, validate } = kb._pure;
const entries = chatbot.seeds();
const idx = buildIndex(entries);
const CASES = [
['Can I hook up my Coinbase account to pay for a package?', 'f-coinbase'],
['can i just use coinbase', 'f-coinbase'],
['I already have an InstantAdPay account, will my upline carry over here?', 'f-team-here'],
['How many extra POL should I keep for gas fees?', 'f-how-much-pol'],
['My card was declined when I tried to buy POL', 'f-card-declined'],
['When does the daily set reset each day?', 'f-claim-streak'],
['How many videos can I watch per day?', 'f-visits-videos'],
['How do I rotate several offers behind one short link?', 'c-spin-links'],
['How do I put an ad slot on my own website?', 'c-zones'],
['Can I track conversions from PropellerAds with a postback?', 'c-sources'],
['Someone on Telegram asked for my recovery phrase', 'f-recovery-phrase'],
['Which network do I choose when withdrawing POL from Binance?', 'f-exchange-withdraw']
];
let bad = 0;
for (const [q, want] of CASES) {
const hits = rank(idx, q, 5), top = hits[0];
const ok = top && top.entry.id === want && relevant(hits).length > 0;
if (!ok) bad++;
console.log((ok ? 'ok ' : 'FAIL ') + q + ' -> ' + hits.slice(0, 3).map(h => h.entry.id + ' ' + h.score).join(', ') + (ok ? '' : ' (wanted ' + want + ')'));
}
// off-topic questions should bring nothing back, so the prompt says "I'm not sure, ask support"
for (const q of ['What is the weather in Paris tomorrow?', 'Recommend a good pizza recipe']) {
const r = relevant(rank(idx, q, 5));
if (r.length) bad++;
console.log((r.length ? 'FAIL ' : 'ok ') + 'off-topic: ' + q + ' -> ' + (r.map(h => h.entry.id + ' ' + h.score).join(', ') || 'nothing'));
}
// admin input hygiene: em dashes are turned into commas, a bad pattern is refused
const v = validate({ title: 'T', answer: 'One — two', questions: 'a\nb', tags: 'X, y' });
if (v.answer !== 'One, two' || v.questions.length !== 2 || v.tags[0] !== 'x') { bad++; console.log('FAIL validate', v); } else console.log('ok validate cleans em dashes, splits questions and tags');
if (!validate({ title: 'T', answer: 'a', pattern: '(' }).error) { bad++; console.log('FAIL validate accepted a broken pattern'); } else console.log('ok validate refuses a broken pattern');
// every CANNED regex still answers through the KB fast path in the same order
const ordered = entries.filter(e => e.pattern).sort((a, b) => a.order - b.order);
const first = msg => ordered.find(e => new RegExp(e.pattern, 'i').test(msg));
const canned = chatbot.CANNED.find(c => c.re.test('how do I withdraw'));
if (!first('how do I withdraw') || first('how do I withdraw').answer !== canned.a) { bad++; console.log('FAIL fast-path order'); } else console.log('ok fast path keeps CANNED order');
console.log(bad ? bad + ' failure(s)' : 'all retrieval checks passed');
process.exit(bad ? 1 : 0);