Spot edits: unlimited, full link check on every one, every one logged; admin takedown and restore (Marty 2026-11-16)

Edits (POST /api/my/spot/<id>, /api/my/default, uploads): still any number of times. Every change now gets the full check:
checkLink, then (LINK_PROBE on) the link must answer (safety.probeLink, up to 3 redirects each checked) and an image address must
download as a real 468x60 image of 150 KB or less (safety.probeImage; the address is kept, a Banner Spin image rotates). The
Banner Spin image + click link LinkSpin just handed the member are not fetched (that would count a LinkSpin click). safety.js gains
privateIp + safeLookup with the Node 20 fix VBB/ViralAdBlitz needed (honors opts.all, answers an array). Every real change is
logged on the spot (or the default): old and new link and image, time, via edit/upload; the owner sees the newest 10. 120 changes
an hour per connection (each one fetches the link).

Admin takedown (the Viral Banner Blitz way, 8e6d2f9): /admin (new page) finds a spot by #number, wallet or network username;
POST /api/admin/spots/<id>/takedown {reason (required, the owner sees it), credit}. Hidden everywhere at once: the board shows a
house tile in its place (nobody else moves), the gate gives its step to a house site, /go/<id> goes home, its Network Ad Space
banner is paused (approved = 0) and no new one is placed. No views or clicks count while down. My Spots shows "Taken down" with
the reason and no edit controls. Restore (POST .../restore) reverses it (NAS resumed). Admin ledger: GET /api/admin/actions (who,
when, reason, credit decision). The contract is never touched.
CREDIT BACK IS NOT BUILT: a spot is a $5 on-chain purchase and this site has no free replacement spot or post credit, so
credit: "back" is refused with a note until Marty decides what it means here; takedowns are "no credit".
Chatbot: CANNED takedown + banner answer (unlimited checked, logged edits) + FACTS EDITS/TAKEDOWN lines, KNOWLEDGE_DATE 2026-11-16.
line.css?v=9, my.js?v=z3.
Tests: smoke section 10 (the lookup shape, edit log, unlimited edits, refusals: unreachable, 404, private address, http redirect,
shortener, bad image size/404/unreachable; redirect followed; same link logs nothing; upload logged; default checked + logged;
takedown: token, reason, credit choice, credit back refused, held house tile, image nowhere, /go home, gate, no views, owner view,
no edits while down, ledger, restore, /admin) against a stand-in internet preloaded into the app (qa/out/probe-stub.cjs, nothing
leaves the machine), plus phone renders of My Spots taken down and /admin: 193/193 with UI. chatbot.test 181/181.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-16 05:23:54 -06:00
parent 197aa39fca
commit a428075330
24 changed files with 499 additions and 37 deletions
+126 -1
View File
@@ -17,6 +17,42 @@ const { ethers } = require('ethers');
const APP = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const OUT = path.join(APP, 'qa', 'out'); fs.mkdirSync(OUT, { recursive: true });
// stand-in internet for the link check (2026-11-16): preloaded into the app (NODE_OPTIONS --require), it answers safety.js's https.get
// calls (the ones with a lookup) and the DNS lookups those make, so every edit gets the full check with nothing leaving this machine. Like Node 20,
// the request asks the lookup for every address (all: true) and needs an array back (the VBB/ViralAdBlitz bug of 2026-11-15).
// Hosts: private.* -> 10.0.0.5 (refused), down.* unreachable, e404.* answers 404, redir.* 302 to https://example.org/landed,
// redir-http.* 302 to an http address, small.* a 125x125 image, anything else 200 (an image path gets a real 468x60 PNG).
const PROBE_STUB = `const https = require('https'), dns = require('dns'), fs = require('fs'), zlib = require('zlib'), { EventEmitter } = require('events'), { PassThrough } = require('stream');
const LOG = process.env.PROBE_LOG;
let probing = false; const dnsLookup = dns.lookup; // only lookups made by a link check are answered here; the app's other traffic resolves as usual
dns.lookup = function (h, o, cb) { if (!probing) return dnsLookup.apply(this, arguments); if (typeof o === 'function') { cb = o; o = {}; } const list = [{ address: String(h).startsWith('private.') ? '10.0.0.5' : '93.184.216.34', family: 4 }]; setImmediate(() => o && o.all ? cb(null, list) : cb(null, list[0].address, 4)); };
function png(w, h) {
const T = Array.from({ length: 256 }, (_, n) => { let c = n; for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1; return c >>> 0; });
const crc = b => { let c = 0xffffffff; for (const x of b) c = T[(c ^ x) & 255] ^ (c >>> 8); return (c ^ 0xffffffff) >>> 0; };
const ch = (t, d) => { const l = Buffer.alloc(4); l.writeUInt32BE(d.length); const td = Buffer.concat([Buffer.from(t), d]); const c = Buffer.alloc(4); c.writeUInt32BE(crc(td)); return Buffer.concat([l, td, c]); };
const ih = Buffer.alloc(13); ih.writeUInt32BE(w, 0); ih.writeUInt32BE(h, 4); ih[8] = 8; ih[9] = 2;
return Buffer.concat([Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]), ch('IHDR', ih), ch('IDAT', zlib.deflateSync(Buffer.alloc((w * 3 + 1) * h))), ch('IEND', Buffer.alloc(0))]);
}
const orig = https.get;
https.get = function (url, opts, cb) {
if (!opts || typeof opts.lookup !== 'function') return orig.apply(this, arguments);
const u = new URL(url); const req = new EventEmitter(); req.destroy = () => {};
if (LOG) fs.appendFileSync(LOG, u.href + '\\n');
probing = true; try { opts.lookup(u.hostname, { all: true, family: 0 }, (err, list) => {
if (err) return req.emit('error', err);
if (!Array.isArray(list)) return req.emit('error', new Error('lookup answered ' + typeof list + ', not the array Node 20 asks for'));
const h = u.hostname; if (h.startsWith('down.')) return req.emit('error', new Error('ECONNREFUSED'));
const res = new PassThrough(); res.headers = {}; res.statusCode = 200; let body = Buffer.from('<!doctype html><title>ok</title>');
if (h.startsWith('e404.')) res.statusCode = 404;
else if (h.startsWith('redir-http.')) { res.statusCode = 302; res.headers.location = 'http://plain-http.com/'; }
else if (h.startsWith('redir.')) { res.statusCode = 302; res.headers.location = 'https://example.org/landed'; }
else if (/\\.(png|gif|jpe?g)$/i.test(u.pathname)) { body = h.startsWith('small.') ? png(125, 125) : png(468, 60); res.headers['content-type'] = 'image/png'; }
res.location = res.headers.location; const destroy = res.destroy.bind(res); res.destroy = () => destroy();
cb(res); res.end(body);
}); } finally { probing = false; }
return req;
};`;
const PROBE_LOG = path.join(OUT, 'probe-' + Date.now() + '.log'); const PROBE_FILE = path.join(OUT, 'probe-stub.cjs'); fs.writeFileSync(PROBE_FILE, PROBE_STUB);
const ART = path.resolve(APP, '..', 'contracts', 'out');
const ANVIL = process.env.ANVIL || path.join(os.homedir(), '.foundry', 'bin', 'anvil.exe');
const PW = process.env.PLAYWRIGHT || 'D:/Projects/MarketingAgent/qa-tester/node_modules/playwright';
@@ -117,7 +153,8 @@ async function main() {
const env = Object.assign({}, process.env, { PORT: String(APP_PORT), DATA_DIR: DATA, CHAIN_ID: '31337', RPC_URLS: 'http://127.0.0.1:' + RPC_PORT, CONTRACT_ADDRESS: CA,
DEPLOY_BLOCK: String(deployBlock), POLL_MS: '1000', ADMIN_TOKEN: ADMIN, KEEPER_ENABLED: '1', KEEPER_KEY: W[7].signer.privateKey, KEEPER_STALL_HOURS: '0.01', KEEPER_EVERY_MIN: '0.25', NODE_ENV: 'development',
HUB_URL: 'http://127.0.0.1:' + HUB_PORT, HUB_SECRET, HUB_SITE: 'bannerline', HUB_ENABLED: '0', NETKB: '0', HUB_DOWN_MS: '400', NETWORK_LOOKUP_URL: 'http://127.0.0.1:' + IAP_PORT + '/api/network/member',
TG_TOKEN: 'standin-token', TG_CHAT: '-100123', TG_PAY_TOPIC: '632242', TG_API: 'http://127.0.0.1:' + TG_PORT });
TG_TOKEN: 'standin-token', TG_CHAT: '-100123', TG_PAY_TOPIC: '632242', TG_API: 'http://127.0.0.1:' + TG_PORT,
PROBE_LOG, NODE_OPTIONS: '--require ' + JSON.stringify(PROBE_FILE).slice(1, -1) }); // the link check runs on every edit against the stand-in internet (probe-stub.cjs)
startStandIns();
const hid = n => 'h_' + String(n).padStart(16, '0');
const ZW = ethers.Wallet.createRandom().address.toLowerCase(); // a network member with no spot here
@@ -396,6 +433,94 @@ async function main() {
ok(st2.hubEvents && st2.hubEvents.on && st2.hubEvents.stats.ended >= 5 && st2.hubEvents.stats.refused >= 2 && !JSON.stringify(st2.hubEvents).includes(HUB_SECRET), 'admin status shows the hub events (counts only, no secret)', st2.hubEvents);
}
console.log('10. spot edits (unlimited, full check, logged) + admin takedown and restore');
{ const ADM = (q, body) => u.json(q, body, { 'x-admin-token': ADMIN });
const probes = () => { try { return fs.readFileSync(PROBE_LOG, 'utf8').split('\n').filter(Boolean); } catch (e) { return []; } };
// the Node 20 lookup shape (VBB and ViralAdBlitz broke on it 2026-11-15): this copy answers an array when asked for all
const safety = require(path.join(APP, 'safety.js')); const dns = require('node:dns'); const dl = dns.lookup;
dns.lookup = (h, o, cb) => { const list = [{ address: String(h).startsWith('private.') ? '10.0.0.5' : '93.184.216.34', family: 4 }]; cb(null, o && o.all ? list : list[0].address, 4); };
const look = (h, o) => new Promise(r => safety.safeLookup(h, o, (e, a, f) => r({ e: e && e.message, a, f })));
const l1 = await look('pub.com', { all: true }), l2 = await look('pub.com', {}), l3 = await look('private.com', { all: true }); dns.lookup = dl;
ok(Array.isArray(l1.a) && l1.a[0].address === '93.184.216.34' && l2.a === '93.184.216.34' && l2.f === 4 && /private/.test(l3.e || ''), 'safeLookup: an array when asked for every address (Node 20), one address otherwise, a private address refused', { l1, l2, l3 });
const p0 = probes().length; const linkNow = async () => ((await m.json('/api/my')).spots.find(x => x.id === sid) || {}).link;
let e = await m.json('/api/my/spot/' + sid, { link: 'https://edit-one.com/a' });
ok(e.ok && e.edit && e.edit.what === 'link' && e.edit.old.link === 'https://example.org/landing' && e.edit.new.link === 'https://edit-one.com/a' && e.edit.at > 0, 'an edit is logged on the spot: old and new link, time', e.edit);
ok(probes().slice(p0).some(l => l.includes('edit-one.com')), 'the new link was fetched (the full check ran on the edit)');
let all = true; for (let i = 2; i <= 6; i++) { e = await m.json('/api/my/spot/' + sid, { link: 'https://edit-' + i + '.com/p' }); all = all && !!e.ok; }
ok(all && await linkNow() === 'https://edit-6.com/p', 'edits are unlimited: five more in a row all saved');
const refuse = [['https://down.edit-x.com/', /could not reach/], ['https://e404.edit-x.com/', /error \(404\)/], ['https://private.edit-x.com/', /private network/], ['https://redir-http.edit-x.com/', /must start with https/], ['https://bit.ly/abc', /shortener/]];
for (const [l, re] of refuse) { const r = await m.json('/api/my/spot/' + sid, { link: l }); ok(r._status === 400 && re.test(r.error || ''), 'edit refused by the full check: ' + l, r); }
ok(await linkNow() === 'https://edit-6.com/p', 'a refused edit changes nothing');
e = await m.json('/api/my/spot/' + sid, { link: 'https://redir.edit-x.com/go' }); ok(e.ok && probes().some(l => l.startsWith('https://example.org/landed')), 'a redirecting link is followed and its target checked too', e);
e = await m.json('/api/my/spot/' + sid, { img: 'https://img.edit-x.com/b.png' });
ok(e.ok && e.edit.what === 'img' && e.edit.new.img === 'https://img.edit-x.com/b.png' && probes().some(l => l.includes('img.edit-x.com')), 'an image address is downloaded and checked (468x60), then saved and logged', e.edit);
for (const [im, re] of [['https://small.edit-x.com/b.png', /468x60/], ['https://e404.edit-x.com/b.png', /answered 404/], ['https://down.edit-x.com/b.png', /could not download/]]) { const r = await m.json('/api/my/spot/' + sid, { img: im }); ok(r._status === 400 && re.test(r.error || ''), 'image refused: ' + im, r); }
e = await m.json('/api/my/spot/' + sid, { link: 'https://redir.edit-x.com/go' }); ok(e.ok && !e.edit, 'saving the same link again changes nothing and logs nothing', e);
const upE = await (await m.req('/api/my/upload?for=' + sid, { method: 'POST', headers: { 'Content-Type': 'image/png' }, body: png(468, 60) })).json(); ok(upE.ok, 'upload (edit by file)');
const mine = (await m.json('/api/my')).spots.find(x => x.id === sid);
ok(mine.edits.length === 10 && mine.edits[0].via === 'upload' && mine.edits[0].old.img === 'https://img.edit-x.com/b.png' && mine.edits[0].new.img === upE.img, 'the owner sees the newest edits first (an upload is logged too)', mine.edits.slice(0, 2));
const de = await m.json('/api/my/default', { link: 'https://e404.def-x.com/' }); const de2 = await m.json('/api/my/default', { link: 'https://def-ok.com/x' });
ok(de._status === 400 && de2.ok && de2.edit && de2.edit.old.link === 'https://example.org/default', 'the default link gets the same check and log', { de, de2 });
console.log('10b. admin takedown and restore');
const tilesOf = async () => (await v.json('/api/board')).tiles;
const t0 = await tilesOf(); const i0 = t0.findIndex(x => x.id === sid);
ok(i0 >= 0, 'the spot is on the board before', t0.map(x => x.id || x.t));
let r = await u.json('/api/admin/spots?q=%23' + sid); ok(r._status === 401, 'admin find needs the token');
const f1 = await ADM('/api/admin/spots?q=%23' + sid), f2 = await ADM('/api/admin/spots?q=' + addr[A]), f3 = await ADM('/api/admin/spots?q=alpha');
ok(f1.spots && f1.spots[0].id === sid && f1.spots[0].edits.length >= 10 && f1.spots[0].defaultEdits.length >= 1 && [f2, f3].every(f => f.spots && f.spots.some(x => x.id === sid)), 'admin finds the spot by #number, wallet and username, with its edit log', { f2: f2.spots && f2.spots.length, f3: f3.error || f3.spots.length });
ok((await ADM('/api/admin/spots?q=nobodyhere')).error, 'nothing found for an unknown username');
const P = '/api/admin/spots/' + sid;
ok((await u.json(P + '/takedown', { reason: 'test', credit: 'none' }))._status === 401, 'takedown needs the token');
ok((await ADM(P + '/takedown', { reason: '', credit: 'none' }))._status === 400, 'a reason is required');
ok((await ADM(P + '/takedown', { reason: 'Broken landing page' }))._status === 400, 'a credit choice is required');
const cb = await ADM(P + '/takedown', { reason: 'Broken landing page', credit: 'back' });
ok(cb._status === 400 && /Marty decides/.test(cb.error) && !(await ADM('/api/admin/spots?q=%23' + sid)).spots[0].down, 'credit back is refused (not defined for Downline Banners yet) and nothing is taken down', cb.error);
const views0 = f1.spots[0].views;
const td = await ADM(P + '/takedown', { reason: 'Misleading offer on the landing page', credit: 'none', by: 'smoke' });
ok(td.ok && td.down.reason === 'Misleading offer on the landing page' && td.log.action === 'takedown' && td.log.credit === 'none' && td.spot.showing.from === 'down', 'taken down, no credit; the admin view shows it', td);
ok((await ADM(P + '/takedown', { reason: 'again', credit: 'none' }))._status === 400, 'a second takedown is refused');
const t1 = await tilesOf();
ok(!t1.some(x => x.id === sid) && t1.length === t0.length && t1[i0] && t1[i0].t === 'house' && t1[i0].held === true && !t1[i0].owner, 'board: the spot is gone, a house tile holds its place, same number of tiles', t1.map(x => x.id || (x.held ? 'held' : x.t)));
ok(JSON.stringify(t1).indexOf(upE.img) < 0, 'its image shows nowhere on the board');
ok((await v.req('/go/' + sid)).headers.get('location') === '/', '/go/<spot> goes home while it is down');
const gv = client('Mozilla/5.0 gate after takedown'); const gg = await gv.json('/api/gate', undefined, { 'X-Forwarded-For': '198.51.100.240' });
ok(gg.steps && !gg.steps.some(st => st.ref === String(sid) || st.img === upE.img), 'the gate never shows it (a house site takes its step)', gg.steps && gg.steps.map(st => st.ref || st.type));
const bt = await v.json('/api/board'); await sleep(4800); await v.json('/api/board/seen', { token: bt.token });
ok((await ADM('/api/admin/spots?q=%23' + sid)).spots[0].views === views0, 'no views count while it is down');
const mineD = (await m.json('/api/my')).spots.find(x => x.id === sid);
ok(mineD.down && mineD.down.reason === 'Misleading offer on the landing page' && mineD.showing.from === 'down', 'the owner sees "Taken down" with the reason', mineD.down);
const ed = await m.json('/api/my/spot/' + sid, { link: 'https://edit-7.com/' });
const upD = await (await m.req('/api/my/upload?for=' + sid, { method: 'POST', headers: { 'Content-Type': 'image/png' }, body: png(468, 60) })).json();
ok(ed._status === 400 && /taken down/.test(ed.error) && /taken down/.test(upD.error || ''), 'the owner cannot change a spot while it is down', { ed, upD });
if (!process.env.SKIP_UI) { // the pages while it is down: My Spots at phone width, and the admin page
const { chromium } = require(PW); const br = await chromium.launch(); const errs = [];
const cx = await br.newContext({ viewport: { width: 390, height: 844 } }); await cx.addCookies([{ name: 'bl.sid', value: m.jar['bl.sid'], url: BASE }]);
const pg = await cx.newPage(); pg.on('pageerror', x => errs.push(x.message));
await pg.goto(BASE + '/my', { waitUntil: 'networkidle' }); await pg.waitForSelector('.spot-down', { timeout: 8000 }).catch(() => {});
const txt = await pg.textContent('#spots'); const wide = await pg.evaluate(() => { const e = document.getElementById('spots'); return e.scrollWidth - e.clientWidth; }); // the spots card (the payments table further down is wider than a phone on its own)
ok(/Taken down/.test(txt) && txt.includes('Misleading offer on the landing page') && wide <= 1, 'My Spots (phone): "Taken down" with the reason, no sideways scroll', { wide });
ok(await pg.isVisible('#outAllBtn'), 'My Spots: Sign out everywhere button shows'); await pg.screenshot({ path: path.join(OUT, 'my-taken-down.png'), fullPage: true });
const pa = await cx.newPage(); pa.on('pageerror', x => errs.push(x.message)); await pa.goto(BASE + '/admin', { waitUntil: 'networkidle' });
await pa.fill('#tok', ADMIN); await pa.click('#tokBtn'); await pa.waitForSelector('#adm:not([hidden])', { timeout: 8000 }).catch(() => {});
await pa.fill('#spQ', '#' + sid); await pa.click('#spFind'); await pa.waitForSelector('.adm-spot', { timeout: 8000 }).catch(() => {});
const at = await pa.textContent('#spList'); const aw = await pa.evaluate(() => document.documentElement.scrollWidth - window.innerWidth);
ok(/TAKEN DOWN/.test(at) && /Restore this spot/.test(at) && /takedown/.test(await pa.textContent('#aActions')) && aw <= 1, 'admin page (phone): finds the spot, shows it taken down with Restore, ledger row', { aw });
await pa.screenshot({ path: path.join(OUT, 'admin-takedown.png'), fullPage: true });
ok(errs.length === 0, 'no page errors (taken-down views)', errs); await br.close();
}
const acts = await ADM('/api/admin/actions');
ok(acts.actions[0].action === 'takedown' && acts.actions[0].spotId === sid && acts.actions[0].reason === 'Misleading offer on the landing page' && acts.actions[0].credit === 'none' && acts.actions[0].by === 'smoke' && acts.actions[0].username === 'alpha', 'admin ledger: who, when, reason, credit decision', acts.actions[0]);
const rs = await ADM(P + '/restore', { reason: 'Owner fixed the page', by: 'smoke' });
ok(rs.ok && !rs.spot.down && rs.spot.downs.length === 1 && rs.spot.downs[0].restoreReason === 'Owner fixed the page' && rs.log.action === 'restore', 'restore: shows again, the takedown kept in its history', rs);
ok((await ADM(P + '/restore', {}))._status === 400, 'restoring a spot that is not down is refused');
const t2 = await tilesOf(); ok(t2.some(x => x.id === sid && x.img === upE.img), 'board shows the spot again after the restore');
ok((await v.req('/go/' + sid)).headers.get('location') === 'https://redir.edit-x.com/go', '/go/<spot> sends to its link again');
ok((await m.json('/api/my/spot/' + sid, { link: 'https://edit-8.com/' })).ok, 'the owner can edit again after the restore');
ok((await ADM('/api/admin/actions')).actions[0].action === 'restore', 'the restore is on the admin ledger');
const ap = await u.req('/admin'); ok(ap.status === 200 && ap.headers.get('x-frame-options') === 'DENY' && /Take a spot down/.test(await ap.text()), '/admin page served, never framed');
}
console.log('\n' + pass + ' passed, ' + fail + ' failed. Output in ' + OUT);
cleanup(); process.exit(fail ? 1 : 0);
}