// Help desk suggestions (2026-11-16): POST /api/my/support/suggest on a LOCAL copy (bash qa/run.sh member starts it; no hub there, // so the answers come from the BM25 fallback, the path members get when the hub or the model is down). Checks: signed out is refused, // a typed problem gets the matching help answer, short text asks nothing, the contact-support entry is never offered, and a ticket // still sends right after (a suggestion never blocks Send). LinkSpin ships the same file (SUGGEST_SEND=0 there: its desk is IAP's). const B = process.env.LOCAL || 'http://127.0.0.1:8796'; let pass = 0, fail = 0; const ok = (c, m, x) => { if (c) pass++; else { fail++; console.log('[bug] support-suggest ' + m + (x ? ' :: ' + x : '')); } }; const email = 'sg' + Date.now() + '@example.com'; const ip = '198.51.100.' + (20 + Math.floor(Math.random() * 200)); const H = { 'Content-Type': 'application/json', 'X-Forwarded-For': ip, 'User-Agent': 'Mozilla/5.0 SupportSuggestQA' }; let cookie = ''; async function post(p, b) { const r = await fetch(B + p, { method: 'POST', headers: Object.assign({}, H, cookie ? { Cookie: cookie } : {}), body: JSON.stringify(b) }); const sc = typeof r.headers.getSetCookie === 'function' ? r.headers.getSetCookie() : []; if (sc.length) cookie = sc.map(c => c.split(';')[0]).join('; '); return { status: r.status, j: await r.json().catch(() => ({})) }; } try { ok((await post('/api/my/support/suggest', { subject: 'my payout', body: 'never arrived' })).status === 401, 'signed out is refused'); const st = await post('/api/auth/email/start', { email, fts: Date.now() - 8000, fage: 8000 }); if (st.j.devCode) await post('/api/auth/email/verify', { email, code: st.j.devCode }); ok(!!cookie, 'signed in for the test'); let r = await post('/api/my/support/suggest', { subject: 'Coinbase', body: 'Can I hook up my Coinbase account to pay for a package?' }); ok(r.status === 200 && Array.isArray(r.j.items) && r.j.items.length > 0, 'a typed problem gets suggestions', JSON.stringify(r.j).slice(0, 200)); ok(r.j.items && r.j.items.some(i => /coinbase/i.test(i.title + ' ' + i.answer)), 'the matching help answer is offered', (r.j.items || []).map(i => i.id).join()); ok(['semantic', 'bm25'].includes(r.j.via), 'answered by the hub or the BM25 fallback (' + r.j.via + ')'); ok(r.j.items.every(i => !/(^|[-:])support$/.test(i.id) && i.title && i.answer), 'no contact-support entry, every item has a title and an answer'); r = await post('/api/my/support/suggest', { subject: 'hi', body: '' }); ok(r.status === 200 && r.j.items.length === 0, 'short text asks nothing'); r = await post('/api/my/support/suggest', { subject: 'I want to talk to a real person', body: 'please contact me, I need support from a human' }); ok(r.status === 200 && r.j.items.every(i => !/(^|[-:])support$/.test(i.id)), 'asking for a person never suggests the contact-support entry'); if (process.env.SUGGEST_SEND !== '0') { const t = await post('/api/my/support', { category: 'Other', subject: 'Coinbase question (QA)', body: 'Can I hook up my Coinbase account to pay for a package? (support-suggest QA)' }); ok(t.status === 200 && /^IAP-\d+$/.test(String(t.j.ref || '')), 'the ticket still sends after suggestions', JSON.stringify(t.j).slice(0, 160)); } } catch (e) { fail++; console.log('[bug] support-suggest crashed :: ' + e.message); } console.log('support-suggest: ' + pass + ' passed, ' + fail + ' failed'); process.exit(fail ? 1 : 0);