Files
viraladblitz/qa/weekend.test.mjs
T
martbost b062939577 Network Weekend (Marty 2026-11-17): Boost views from the live VABShop SKU on every page, quote and chatbot, the network ribbon
chainskus.js reads skus(1) every 60 s and keeps C.boost in step (BOOST_VIEWS stays the normal 500 as normalViews), so a $5
Boost shows 750 once the owner signs setSku and 500 before or after; crediting already follows the Purchase event's views.
common.js rewrites the pages' static '500 guaranteed views' copy to the live number only when the chain differs.
weekend.js: the Fri 11-27 00:00 CT to Tue 12-01 00:00 CT gate (WEEKEND_NOW test clock) for the dated chatbot fact; the ribbon
line (netdeals.setLocal) only exists while the chain really holds the weekend Boost. chatcore render hook, live intro.
qa/weekend.test.mjs 18 pass, chatbot 206, smoke 197. common.js?v=9.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 07:39:47 -06:00

45 lines
4.2 KiB
JavaScript

// Network Weekend checks (Marty 2026-11-17): node qa/weekend.test.mjs. No network: a stand-in Polygon RPC for skus().
// Every date gate runs on the WEEKEND_NOW test clock, never the machine clock.
import http from 'node:http'; import os from 'node:os'; import fs from 'node:fs'; import path from 'node:path';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const { Interface } = require('ethers');
let pass = 0, fail = 0; const ok = (c, m) => { if (c) pass++; else { fail++; console.log('FAIL', m); } };
process.env.DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), 'vabwk-')); delete process.env.DOCSTORE_URL; process.env.NETKB = '0'; delete process.env.OPENROUTER_API_KEY;
const I = new Interface(['function skus(uint256) view returns (uint64 usdCents, uint64 views, bool active)']);
const SKUS = { 1: [500, 500, true] }; let down = false;
const rpc = http.createServer((q, r) => { let b = ''; q.on('data', c => { b += c; }); q.on('end', () => { const j = JSON.parse(b);
if (down) { r.writeHead(500); return r.end('x'); }
const sku = Number(I.decodeFunctionData('skus', j.params[0].data)[0]);
r.setHeader('Content-Type', 'application/json'); r.end(JSON.stringify({ jsonrpc: '2.0', id: j.id, result: I.encodeFunctionResult('skus', SKUS[sku] || [0, 0, false]) })); }); });
await new Promise(r => rpc.listen(0, r));
process.env.CHAIN_RPC = 'http://127.0.0.1:' + rpc.address().port; process.env.CONTRACT_ADDRESS = '0x00000000000000000000000000000000000B0B05';
const C = require('../config.js').get();
const weekend = require('../weekend.js'); const chainskus = require('../chainskus.js'); const netdeals = require('../netdeals.js');
const bot = require('../chatbot.js');
const at = iso => { process.env.WEEKEND_NOW = iso; };
const sync = async () => { await chainskus.refresh(); };
chainskus.init(C, [C.boost.sku], () => chainskus.syncBoost(C)); chainskus.syncBoost(C);
for (const [iso, want] of [['2026-11-26T23:59:59-06:00', false], ['2026-11-27T00:00:00-06:00', true], ['2026-11-30T23:59:59-06:00', true], ['2026-12-01T00:00:00-06:00', false]])
{ at(iso); ok(weekend.on() === want, 'on() at ' + iso); }
await sync(); ok(C.boost.views === 500 && C.boost.normalViews === 500 && C.boost.usd === 5, 'chain 500: normal');
const deal = { site: 'viraladblitz', name: 'ViralAdBlitz', text: 'hub text' };
at('2026-11-27T00:03:00-06:00'); ok(weekend.dealLine(C, deal) === null, 'late signature: no ribbon line');
ok(/NETWORK WEEKEND/.test(bot.FACTS()) && !/750/.test(bot.FACTS()), 'weekend fact says no 750 before the chain does');
SKUS[1] = [500, 750, true]; await sync();
ok(C.boost.views === 750 && C.boost.usd === 5 && C.boost.normalViews === 500, 'owner set 750: C.boost follows');
ok(weekend.dealLine(C, deal).text === 'A $5 Boost carries 750 guaranteed views instead of 500.', 'ribbon line from chain');
ok(/750 guaranteed views instead of 500/.test(bot.FACTS()) && /Boost for 750 guaranteed views/.test(bot.SITE.intro), 'facts + intro live');
ok(/buys 750 guaranteed network views/.test(bot.render('A $5 Boost buys 500 guaranteed network views. Each adds its own 500 views.')) && /own 750 views/.test(bot.render('its own 500 views')), 'canned rendered live');
ok(bot.render('Pick 1 to 10, $500 limit') === 'Pick 1 to 10, $500 limit', 'unrelated numbers untouched');
down = true; await sync(); ok(C.boost.views === 750, 'RPC down: last good read'); down = false;
at('2026-12-01T00:00:00-06:00'); ok(!/NETWORK WEEKEND/.test(bot.FACTS()), 'Tuesday: no weekend fact');
ok(/750/.test(bot.FACTS()), 'Tuesday before the revert is signed: the bot still says what the contract sells');
SKUS[1] = [500, 500, true]; await sync(); ok(C.boost.views === 500 && bot.render('500 guaranteed views') === '500 guaranteed views', 'reverted: 500');
netdeals.setLocal(x => weekend.dealLine(C, x)); netdeals._set({ events: [{ id: 'e', name: 'N', startsAt: '2026-11-27T06:00:00.000Z', endsAt: '2026-12-01T06:00:00.000Z', deals: [deal] }] });
let body = ''; netdeals.handle({}, { writeHead() {}, end(s) { body = s; } }, 'viraladblitz'); ok(JSON.parse(body).events[0].deals.length === 0, 'feed drops the line when chain is normal');
ok(!/\u2014/.test(bot.FACTS()), 'no em dashes');
rpc.close(); console.log('weekend: ' + pass + ' passed, ' + fail + ' failed'); process.exit(fail ? 1 : 0);