3a00ddf3dc
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
35 lines
3.7 KiB
JavaScript
35 lines
3.7 KiB
JavaScript
// The shared network knowledge base in this site's chatbot (2026-11-15): node qa/netkb-merge.test.cjs
|
|
// No network: netkb's merged set is set by hand. Checks: this site's entries rank first for a general question, a named site's
|
|
// entries rank first when it is named, other sites never take the fast path, the prompt labels them with the site and link,
|
|
// a question naming another site skips this site's instant answers (a hand-off still wins), and own() is this site only.
|
|
// The SAME file ships in InstantAdPay and LinkSpin.
|
|
const fs = require('fs'); const os = require('os'); const path = require('path');
|
|
const DIR = fs.mkdtempSync(path.join(os.tmpdir(), 'netkb-'));
|
|
delete process.env.DATABASE_URL; delete process.env.OPENROUTER_API_KEY; process.env.NETKB = '0';
|
|
const kb = require('../kb'); const netkb = require('../netkb'); const bot = require('../chatbot');
|
|
let pass = 0, fail = 0;
|
|
const ok = (c, m) => { if (c) { pass++; console.log('PASS', m); } else { fail++; console.log('FAIL', m); } };
|
|
(async () => {
|
|
await bot.init({ dataDir: DIR, chain: null });
|
|
const self = fs.existsSync(path.join(__dirname, '..', 'tickets.js')) ? 'iap' : 'linkspin';
|
|
netkb._set({ version: 'v1', sites: { downlinehydra: { name: 'DownlineHydra', url: 'https://downlinehydra.com' }, [self]: { name: 'Me', url: 'https://me.example' } },
|
|
entries: [
|
|
{ site: 'downlinehydra', id: 'c-pro', title: 'Pro: what it costs', questions: ['How much is Pro?', 'What do I get with Pro?'], answer: 'Pro is $30 one time.', tags: ['pro', 'price'] },
|
|
{ site: 'downlinehydra', id: 'c-withdraw', title: 'Withdrawals', questions: ['How do I withdraw?'], answer: 'Nothing to withdraw on DownlineHydra.', tags: ['withdraw'] },
|
|
{ site: self, id: 'c-own', title: 'Own entry from the hub', questions: ['x'], answer: 'never in remote', tags: [] }] });
|
|
await kb.load(true);
|
|
const top = async q => { const h = await kb.search(q, 8); return h[0] && h[0].entry; };
|
|
{ const t = await top('How do I withdraw?'); ok(t && !t.site, 'a general question ranks this site first (' + (t && t.id) + ')'); }
|
|
{ const t = await top('How do I withdraw on DownlineHydra?'); ok(t && t.site === 'downlinehydra', 'a named site ranks its own entry first (' + (t && t.id) + ')'); }
|
|
ok(!(await kb.search('Own entry from the hub', 8)).some(h => h.entry.site === self), 'this site\'s own copy on the hub is not read back as another site');
|
|
{ const b = kb.promptBlock(await kb.context('How much is Pro on DownlineHydra', 6)); ok(/about DownlineHydra, another network site; send people to /.test(b), 'remote entries labelled with site and link'); }
|
|
{ const r = await bot.answer('How much is Pro on DownlineHydra?'); ok(!r.canned, 'naming another site skips this site\'s instant answers (' + r.kb + ')'); }
|
|
{ const r = await bot.answer('How do I withdraw?'); ok(r.canned, 'this site\'s own question keeps its instant answer'); }
|
|
{ const r = await bot.answer('I need a real person, my DownlineHydra pro is missing'); ok(r.handoff === true, 'a hand-off still wins when another site is named'); }
|
|
{ const own = await kb.own(); ok(own.length > 10 && own.every(e => !e.site), 'own(): this site\'s entries only (' + own.length + ')'); }
|
|
ok(kb.namesOther('what is 5xYourTeam', self).includes('fivex') && !kb.namesOther('what is this site', self).length, 'namesOther finds a network site by name');
|
|
for (const e of await kb.own()) ok(!/\bmetamask\b/i.test(e.answer.replace(/never recommend MetaMask/gi, '')), e.id + ': no MetaMask recommendation in a shared answer');
|
|
console.log((fail ? 'FAILED ' : 'all network KB checks passed: ') + pass + ' passed, ' + fail + ' failed');
|
|
process.exit(fail ? 1 : 0);
|
|
})().catch(e => { console.error(e); process.exit(1); });
|