Site assistant (Marty 2026-11-15): chat widget in the Viral Banner Blitz pop-art look on every page, CANNED + FACTS from this repo's code (loop 50, 10 verified visitors per shift, 150 network ad views per cycle recorded but not credited yet, 1 free post credit a day for network members, packs 10/$3 and 40/$10, look $2, split 30% introducer + 10% prize pot + 60% company, weekly boards; the pot's floor and cap are never stated), retrieval over the shared network knowledge base on the hub (netkb.js, home entries boosted, another site named = its answer), reasoning off, account problems hand off to network support. chatbot.test 170, smoke 249/249

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-15 12:58:40 -06:00
parent d759d1f67d
commit 5afde38f6f
22 changed files with 952 additions and 1 deletions
+22
View File
@@ -0,0 +1,22 @@
{
"site": "vbb",
"home": [
{ "q": "What is Viral Banner Blitz?", "kb": "about", "must": ["loop", "10 verified visitors", "150 network ad views"] },
{ "q": "Is posting free?", "kb": "free-credit", "must": ["one free post credit", "InstantAdPay or LinkSpin"] },
{ "q": "What size is the banner?", "kb": "post", "must": ["125x125", "100 KB"] },
{ "q": "How much are the packages?", "kb": "packages", "must": ["10 post credits for \\$3", "40 post credits for \\$10", "\\$2"] },
{ "q": "Where does my payment go?", "kb": "split", "must": ["30%", "10%", "60%"] },
{ "q": "Are the 150 views added to my advertising yet?", "kb": "cycle", "must": ["not switched on yet"] },
{ "q": "How do I win the weekly prize?", "kb": "leaders", "must": ["top three", "following Monday"] },
{ "q": "What are the SPIN tiles?", "kb": "spin-tiles", "must": ["never shift"] },
{ "q": "Which wallet should I use?", "kb": "wallet", "must": ["SafePal or any other crypto wallet"] },
{ "q": "Is this a pyramid scheme?", "kb": "safe", "must": ["contract", "not an income opportunity"] }
],
"cross": [
{ "q": "What is Downline Banners?", "site": "bannerline" },
{ "q": "How does a ViralAdBlitz Boost work?", "site": "viraladblitz" },
{ "q": "What is DownlineHydra Pro?", "site": "downlinehydra" },
{ "q": "What is LinkSpin Banner Spin?", "site": "linkspin" },
{ "q": "What is the 5xYourTeam draft?", "site": "fivex" }
]
}
+87
View File
@@ -0,0 +1,87 @@
// Site assistant checks (2026-11-15): node qa/chatbot.test.mjs
// No network: a stand-in OpenRouter and a stand-in hub. Checks the instant answers route every example question to its own entry,
// the house rules (no em dashes, no MetaMask, never RM Circle, ad-credits line where credits come up, no income promises),
// the network merge (home boosted, a named site boosted), the support hand-off, and the site's scripted Q&A (qa/chat-qa.json:
// home questions must land on the named entry and contain the expected facts).
// The SAME file ships in every rebuilt network site.
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import http from 'node:http';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const ROOT = path.resolve(path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1')), '..');
const DIR = fs.mkdtempSync(path.join(os.tmpdir(), 'chat-'));
process.env.DATA_DIR = DIR; delete process.env.DOCSTORE_URL; process.env.NETKB = '0'; delete process.env.OPENROUTER_API_KEY;
let pass = 0, fail = 0; const bad = [];
const ok = (c, m) => { if (c) pass++; else { fail++; bad.push(m); console.log('FAIL', m); } };
// stand-in OpenRouter: answers with what the system prompt says about the first KB entry, so we can see the prompt
let lastPrompt = '', reply = 'Fine.';
const or = http.createServer((req, res) => { let b = ''; req.on('data', c => { b += c; }); req.on('end', () => {
const j = JSON.parse(b); lastPrompt = j.messages[0].content; ok(j.reasoning && j.reasoning.enabled === false, 'reasoning is switched off');
res.writeHead(200, { 'Content-Type': 'application/json' }); res.end('\n\n' + JSON.stringify({ choices: [{ message: { content: reply } }] })); }); });
await new Promise(r => or.listen(0, r));
process.env.OPENROUTER_URL = 'http://127.0.0.1:' + or.address().port + '/v1/chat/completions';
const cfg = require(path.join(ROOT, 'config.js')); if (cfg.reset) cfg.reset();
const bot = require(path.join(ROOT, 'chatbot.js'));
const core = require(path.join(ROOT, 'chatcore.js'));
const kb = require(path.join(ROOT, 'kb.js'));
const netkb = require(path.join(ROOT, 'netkb.js'));
const dataDir = bot.SITE.dataDir;
await bot.init();
// 1. seeds and the fast path: every example question of a canned entry lands on that entry (first match wins)
const seeds = core.seeds();
ok(seeds.length >= 12, 'at least 12 seeded entries (' + seeds.length + ')');
for (const c of bot.CANNED) {
ok(c.re instanceof RegExp, c.id + ' has a pattern');
for (const q of c.q || []) { const hit = await kb.fastPath(q); ok(hit && hit.id === 'c-' + c.id, 'example "' + q + '" -> ' + c.id + ' (got ' + (hit && hit.id) + ')'); }
}
// 2. house rules in every seeded answer
for (const s of seeds) {
ok(!/[—―]/.test(s.answer + s.title), s.id + ': no em dashes');
ok(!/metamask/i.test(s.answer), s.id + ': never recommends MetaMask');
ok(!/rm ?circle/i.test(s.answer), s.id + ': never RM Circle');
ok(!/(guarantee[ds]? (income|earnings|profit)|you will (earn|make)|passive income|get rich|up to \$?\d[\d,.]* (a|per) (day|week|month))/i.test(s.answer), s.id + ': no income promise');
if (/\bad credits?\b/i.test(s.answer)) ok(/Ad credits buy advertising, not income\./.test(s.answer), s.id + ': ad credits line');
if (/wallet/i.test(s.answer) && /(which|use|recommend)/i.test(s.answer) && /safepal/i.test(s.answer)) ok(/SafePal or any other crypto wallet/i.test(s.answer), s.id + ': wallet wording');
}
// 3. the engine: scrub, support hand-off, the AI path
ok(core.scrub('A — B, use MetaMask or SafePal') === 'A, B, use SafePal', 'scrub: em dash and MetaMask (' + core.scrub('A — B, use MetaMask or SafePal') + ')');
{ const r = await bot.answer('I need to talk to a real person about my account'); ok(r.handoff === true, 'asking for a person hands off'); }
{ const r = await bot.answer(''); ok(!!r.error, 'empty question refused'); }
fs.writeFileSync(path.join(dataDir || DIR, 'openrouter.key'), 'test-key');
reply = 'Sure — try RM Circle'; { const r = await bot.answer('zzqx unrelated words nobody wrote down'); ok(!/rm ?circle/i.test(r.reply) && !/—/.test(r.reply), 'an RM Circle or em dash reply never leaves (' + r.reply + ')'); }
ok(/NEVER promise or estimate income/.test(lastPrompt) && /SafePal or any other crypto wallet/.test(lastPrompt) && /Ad credits buy advertising, not income\./.test(lastPrompt), 'house rules in the system prompt');
reply = 'Fine.';
// 4. the network merge: home boosted, a named site boosted, labelled with the site and its link
const GENERAL = bot.CANNED.find(c => !['support', 'refund', 'about'].includes(c.id) && (c.q || []).length).q[0].replace(/\?$/, '');
netkb._set({ version: 'v1', sites: { othersite: { name: 'Other Site', url: 'https://other.example', count: 1 }, [process.env.HUB_SITE || bot.SITE.hubSite]: { name: bot.SITE.name, url: bot.SITE.url } },
entries: [{ site: 'othersite', id: 'about', title: 'What is Other Site?', questions: ['What is Other Site?', GENERAL + ' on Other Site'], answer: 'Other Site is a test site with its own rules.', tags: ['test'] }] });
await kb.load(true);
{ const hits = await kb.search(GENERAL, 8); const top = hits[0] && hits[0].entry; ok(top && !top.site, 'home entries first for a general question (top ' + (top && top.id) + ')'); }
{ const hits = await kb.search(GENERAL + ' on Other Site', 8); const top = hits[0] && hits[0].entry; ok(top && top.site === 'othersite', 'a named site boosts its own entry (top ' + (top && top.id) + ')'); }
{ const block = kb.promptBlock(await kb.context('What is Other Site', 6)); ok(/about Other Site, another network site; send people to https:\/\/other\.example/.test(block), 'remote entry labelled with site and link'); }
{ const fp = await kb.fastPath('What is Other Site?'); ok(!fp || !String(fp.id).startsWith('othersite:'), 'other sites never take the fast path'); }
{ const r = await bot.answer(GENERAL + ' on Other Site'); ok(!r.canned, 'a question naming another site skips this site\'s instant answers (' + r.kb + ')'); }
{ const r = await bot.answer('I need a real person, my order on Other Site failed'); ok(r.handoff === true, 'a hand-off still wins when another site is named'); }
{ const r = await bot.answer(bot.CANNED.find(c => c.id === 'about').q[0]); ok(r.canned && r.kb === 'c-about', 'this site\'s own name keeps the instant answer'); }
{ const own = await kb.own(); ok(own.length === seeds.length && own.every(e => !e.site), 'publish set = this site\'s own entries only'); }
// 5. the scripted Q&A (home questions)
const qaFile = path.join(ROOT, 'qa', 'chat-qa.json');
if (fs.existsSync(qaFile)) {
const qa = JSON.parse(fs.readFileSync(qaFile, 'utf8'));
for (const t of qa.home || []) {
const r = await bot.answer(t.q);
if (t.kb) ok(r.kb === 'c-' + t.kb || (Array.isArray(r.kb) && r.kb.includes('c-' + t.kb)), 'Q&A "' + t.q + '" -> ' + t.kb + ' (got ' + JSON.stringify(r.kb) + ')');
for (const m of t.must || []) ok(new RegExp(m, 'i').test(r.reply) || new RegExp(m, 'i').test(lastPrompt), 'Q&A "' + t.q + '" mentions /' + m + '/');
}
}
or.close();
console.log((fail ? 'FAILED ' : 'ok ') + pass + ' passed, ' + fail + ' failed');
process.exit(fail ? 1 : 0);
+9 -1
View File
@@ -87,7 +87,7 @@ const ENV = Object.assign({}, process.env, { PORT: String(PORT), DATA_DIR: DATA,
LOOP_SIZE: '5', VISITORS_PER_SHIFT: '3', VIEWS_PER_CYCLE: '150', VISIT_SECONDS: '2', VISITS_PER_IP_DAY: '2', LINK_PROBE: '0', NETWORK_LOOKUP_URL: 'http://127.0.0.1:' + (PORT + 1) + '/api/network/member',
NETWORK_SSO_SECRET: SSO_SECRET, IAP_URL: 'https://iap.invalid', LS_URL: 'https://ls.invalid', LS_PARTNER_URL: 'http://127.0.0.1:' + LS_PORT, LS_SPINS_FIRST_MS: '300', LS_SPINS_EVERY_MS: '700',
CONTRACT_ADDRESS: SHOP, CHAIN_RPC: 'http://127.0.0.1:' + CHAIN_PORT, KEEPER_KEY: KEEPER_PK, SHOP_START_BLOCK: '1', SHOP_CONFIRMATIONS: '0', SHOP_POLL_MS: '200',
HUB_ENABLED: '1', HUB_URL: 'http://127.0.0.1:' + HUB_PORT, HUB_SECRET, HUB_SITE: 'vbb', HUB_TICK_MS: '300', HUB_DOWN_MS: '400' });
HUB_ENABLED: '1', NETKB: '0', HUB_URL: 'http://127.0.0.1:' + HUB_PORT, HUB_SECRET, HUB_SITE: 'vbb', HUB_TICK_MS: '300', HUB_DOWN_MS: '400' });
const sleep = ms => new Promise(r => setTimeout(r, ms));
let pass = 0, fail = 0; let srv = null;
const ok = (cond, what, extra) => { if (cond) { pass++; console.log(' ok ' + what); } else { fail++; console.log(' FAIL ' + what + (extra !== undefined ? ' -> ' + JSON.stringify(extra).slice(0, 400) : '')); } };
@@ -211,6 +211,14 @@ async function main() {
r = await anon.req('/sitemap.xml'); ok((await r.text()).includes('/promote'), 'sitemap lists /promote');
}
r = await anon.req('/api/my'); ok(r.status === 401, '/api/my needs sign-in');
// the site assistant (2026-11-15): widget on every page, canned answers without AI, account problems hand off, admin KB behind the token
{ const home = await (await anon.req('/')).text();
ok(/<script src="\/assets\/chat\.js\?v=\d+" defer><\/script>/.test(home) && (await anon.req('/assets/chat.js')).status === 200 && (await anon.req('/assets/chat.css')).status === 200, 'chat widget on the page, its script and styles served'); }
{ const cr = await anon.req('/api/chat', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ message: 'How much are the packages?' }) }); const cj = await cr.json();
ok(cr.status === 200 && cj.canned && /\$3/.test(cj.reply) && /\$10/.test(cj.reply), 'chat: canned packages answer', cj); }
{ const cr = await anon.req('/api/chat', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ message: 'my credits did not show up' }) }); const cj = await cr.json();
ok(cj.handoff === true && /^https:\/\/instantadpay\.com\/support\?from=vbb/.test(cj.support || ''), 'chat: account problem hands off to network support', cj); }
ok((await anon.req('/api/admin/kb')).status === 401, 'admin KB needs the token');
console.log('4. members: wallet sign-in and network sign-in');
const A = await walletMember();