Michael Camire fixes + hub shells in the tank (Marty 2026-11-14, LinkSpin Support)
1. Top-up across positions: an ad burns from ONE position, and topUpCampaign only looked at the ad's
own position (or the main one when the list row had no memberId), so credits bought on a linked
position could never top up the ad. Ported from InstantAdPay 2026-09-27 (Jim Watts): the ad's real
member id is read from the campaign row; when it cannot cover, the refusal names where the free
credits are and offers switchOptions; with the member's yes (switchTo, only a position on the
account) moveFunding settles what the ad already ran up on the OLD position, moves the ad, then
tops up. Ads screen asks in-page (own dialog) and retries. Create already had the largest-position guard.
2. Toasts: errors stay until closed (close button, role=alert), other notes 3.5 to 9 s by length.
3. Banner Spin per-banner clicks: his 3 clicks were all unmatched (no view on record for that browser),
so they landed on the fallback row and every banner said 0. Click matching now also tries the same
connection (daily-salted IP-only hash) when the browser key finds nothing (mail/exchange app view,
click opened in the phone browser), view notes last 60 min instead of 15, and the stats split
'Fallback shown' from 'Clicks not tied to a banner' so the rows add up to the total. History is not
backfilled: views were never stored per visitor, so old clicks cannot be tied reliably.
4. Holding tank: hub-made waiting accounts with no sponsor are in the tank (waiting, rescue, readyTick
read listAll with { shells: true }; 'hub-shell' no longer holds anyone back). Locked / sponsored /
unknown, grace, 2-adoption cap unchanged; readyTick still never switches a shell on;
accounts.listAll default unchanged (mailings skip shells).
Assets: cr.css, cr-shell.js, ads-screen.js ?v=20261114tu, banner-spin.js ?v=20261114bc.
QA: walk member 0 bugs (36 ok), netconv 57/57, networksso ALL PASSED, tank-hold all passed (new hub
shell part), profile policy 16/16, new topup-positions 8/8, new bannerspin-attrib 7/7, bannerspin e2e
75/75, hubsync 15 checks, tank-cap 15/15, sponsorfollow 30/30.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
// Banner Spin click attribution (Michael Camire 2026-11-14: his "Login Ad Explosion" showed Clicks 3 overall while every
|
||||
// banner's own Clicks said 0. All three clicks came in with no view on record for that visitor, so they were counted on
|
||||
// the fallback and no banner got them). Checks, on bannerspin.js directly (throwaway DATA_DIR, fake rotator, no server):
|
||||
// impression -> click from the same browser credits that banner (note), the script embed's ?x= credits exactly,
|
||||
// a click from the same connection in ANOTHER browser (mail app / exchange app view, click opens in the phone browser)
|
||||
// credits the banner it was shown (ip), a click with no view anywhere stays "not tied to a banner",
|
||||
// and banner rows + fallback shown + not tied add up to the Banner Spin totals.
|
||||
// node qa/bannerspin-attrib.test.cjs
|
||||
'use strict';
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const SITE = path.join(__dirname, '..');
|
||||
const DATA = fs.mkdtempSync(path.join(os.tmpdir(), 'bs-attrib-'));
|
||||
const bs = require(path.join(SITE, 'bannerspin.js'));
|
||||
const rotator = { cellAt: () => 0, zoneFor: () => 'UTC', isOn: () => true, rawRotations: () => [], cleanHours: () => ({}), cleanTz: () => ({ tz: 'visitor' }) };
|
||||
const OWNER = 'owner@bs.test';
|
||||
|
||||
let passed = 0, failed = 0; const results = [];
|
||||
async function t(name, fn) { try { await fn(); passed++; results.push('ok ' + name); } catch (e) { failed++; results.push('FAIL ' + name + '\n ' + String(e && e.stack || e).split('\n').slice(0, 4).join('\n ')); } }
|
||||
const req = (url, ip, ua, referer) => ({ url, headers: Object.assign({ 'x-forwarded-for': ip, 'user-agent': ua }, referer ? { referer } : {}), socket: {} });
|
||||
const TG = n => 'https://offer.example/b' + n;
|
||||
|
||||
(async () => {
|
||||
bs.init({ dataDir: DATA, rotator, adminEmail: OWNER, schedule: false });
|
||||
let S, code;
|
||||
await t('a Banner Spin with 3 banners (one target each) and a fallback', async () => {
|
||||
const c = await bs.create(OWNER, { name: 'Attrib', size: '468x60', fallback: 'https://fallback.example/' }); assert.ok(!c.error, c.error);
|
||||
S = c.spin; code = S.code;
|
||||
for (const n of [1, 2, 3]) { const r = await bs.addBanner(OWNER, S.id, { image: 'https://img.example/' + n + '.png', target: TG(n), weight: 10 }); assert.ok(!r.error, r.error); }
|
||||
});
|
||||
const shown = async (ip, ua, ref) => { const im = await bs.image(code, req('/i/' + code + '.gif', ip, ua, ref), null); const n = Number(/\/(\d)\.png$/.exec(im.url)[1]); return n; };
|
||||
const clickAs = (ip, ua, ref, q) => bs.click(code, req('/c/' + code + (q || ''), ip, ua, ref), 'linkspin.app');
|
||||
const want = { 1: 0, 2: 0, 3: 0 };
|
||||
await t('impression -> click, same browser, with a referrer: that banner, matched by note', async () => {
|
||||
for (let i = 0; i < 6; i++) {
|
||||
const ip = '10.9.0.' + i, ua = 'Mozilla/5.0 Desktop' + i; const n = await shown(ip, ua, 'https://exchange-a.example/surf');
|
||||
const c = await clickAs(ip, ua, 'https://exchange-a.example/surf');
|
||||
assert.strictEqual(c.url, TG(n)); assert.strictEqual(c.matched, 'note'); assert.strictEqual(c.banner.id, n); want[n]++;
|
||||
}
|
||||
});
|
||||
await t('impression -> click, same browser, no referrer on either (mailer, privacy settings): that banner', async () => {
|
||||
const n = await shown('10.9.1.1', 'Mozilla/5.0 Quiet', ''); const c = await clickAs('10.9.1.1', 'Mozilla/5.0 Quiet', '');
|
||||
assert.strictEqual(c.banner && c.banner.id, n); assert.strictEqual(c.matched, 'note'); want[n]++;
|
||||
});
|
||||
await t('viewed in a mail or exchange app, clicked in the phone browser (same IP, other UA): that banner, matched by ip', async () => {
|
||||
const n = await shown('10.9.2.2', 'MailApp/3.1 (Android) WebView', ''); const c = await clickAs('10.9.2.2', 'Mozilla/5.0 (Linux; Android 14) Chrome/130 Mobile', '');
|
||||
assert.strictEqual(c.banner && c.banner.id, n); assert.strictEqual(c.matched, 'ip'); assert.strictEqual(c.url, TG(n)); want[n]++;
|
||||
});
|
||||
await t('script embed click (?x=2) credits banner 2 exactly', async () => {
|
||||
const c = await clickAs('10.9.3.3', 'Mozilla/5.0 Script', 'https://blog.example/', '?x=2'); assert.strictEqual(c.banner.id, 2); assert.strictEqual(c.matched, 'exact'); want[2]++;
|
||||
});
|
||||
await t('a click with no view anywhere: fallback link, not tied to a banner', async () => {
|
||||
const c = await clickAs('10.9.4.4', 'Mozilla/5.0 NeverSaw', ''); assert.strictEqual(c.banner, null); assert.strictEqual(c.matched, 'none'); assert.strictEqual(c.url, 'https://fallback.example/');
|
||||
});
|
||||
await t('stats: per-banner clicks match what was shown, and banners + fallback shown + not tied = the total', async () => {
|
||||
bs.flush();
|
||||
const st = await bs.stats(OWNER, S.id);
|
||||
for (const b of st.banners) assert.strictEqual(b.clicks, want[b.id], 'banner ' + b.id + ' clicks ' + b.clicks + ' want ' + want[b.id]);
|
||||
assert.strictEqual(st.unmatched.clicks, 1); assert.strictEqual(st.fallback.clicks, 0);
|
||||
const sum = st.banners.reduce((n, b) => n + b.clicks, 0) + st.fallback.clicks + st.unmatched.clicks;
|
||||
assert.strictEqual(sum, st.totals.clicks); assert.strictEqual(st.totals.clicks, 10);
|
||||
assert.strictEqual(st.totals.matched, 9); assert.strictEqual(st.totals.unmatched, 1);
|
||||
const views = st.banners.reduce((n, b) => n + b.imps, 0) + st.fallback.imps; assert.strictEqual(views, st.totals.imps); assert.strictEqual(st.totals.imps, 8);
|
||||
});
|
||||
|
||||
console.log(results.join('\n'));
|
||||
console.log('\nbannerspin-attrib: ' + passed + ' passed, ' + failed + ' failed');
|
||||
try { fs.rmSync(DATA, { recursive: true, force: true }); } catch (e) {}
|
||||
process.exit(failed ? 1 : 0);
|
||||
})();
|
||||
+2
-1
@@ -192,7 +192,8 @@ const W = n => '0x' + String(n).padStart(40, '0');
|
||||
assert.deepStrictEqual([...held.entries()].sort(), [[E('hs'), 'hub-shell'], [E('tk1'), 'sponsored'], [E('tk2'), 'locked']]);
|
||||
let w = (await tank.waiting()).map(x => x.email);
|
||||
assert.ok(w.includes(E('tk3')), 'a free member is offered');
|
||||
for (const n of ['tk1', 'tk2', 'hs']) assert.ok(!w.includes(E(n)), n + ' is not offered: ' + w.join(','));
|
||||
for (const n of ['tk1', 'tk2']) assert.ok(!w.includes(E(n)), n + ' is not offered: ' + w.join(','));
|
||||
assert.ok(w.includes(E('hs')), 'a hub waiting copy with no sponsor IS offered (Marty 2026-11-14: unsponsored old members go in the tank)');
|
||||
await accounts.setSponsorRef(E('tk2'), 'zed');
|
||||
const rel = await tank.release(E('zed'), E('tk2'));
|
||||
assert.ok(rel.error && /locked/.test(rel.error), JSON.stringify(rel)); assert.strictEqual((await accounts.sponsorOf(E('tk2'))).email, E('zed'));
|
||||
|
||||
@@ -76,6 +76,8 @@ elif [ "$MODE" = "member" ]; then
|
||||
node qa/tank-hold.test.mjs || status=1
|
||||
node qa/profile-policy.test.cjs || status=1
|
||||
node qa/netconv.test.mjs || status=1
|
||||
node qa/topup-positions.test.cjs || status=1 # a top-up the ad's position cannot cover offers the position that can, then moves the ad there (Michael Camire 2026-11-14)
|
||||
node qa/bannerspin-attrib.test.cjs || status=1 # Banner Spin: impression -> click -> the banner shown gets the click (same browser, same connection, script ?x=), rows add up (Michael Camire 2026-11-14)
|
||||
elif [ "$MODE" = "policy" ]; then
|
||||
node qa/profile-policy.test.cjs || status=1
|
||||
elif [ "$MODE" = "sponsorfollow" ]; then
|
||||
|
||||
@@ -479,8 +479,31 @@ async function partB() {
|
||||
}
|
||||
}
|
||||
|
||||
// hub-made waiting accounts (Marty 2026-11-14: "Yes to the unsponsored old members going in the holding tank"): a hub shell
|
||||
// with no sponsor is in the waiting list even though accounts.listAll leaves shells out by default (mailings); the hub's
|
||||
// locked / sponsored answers still hold people back, and readyTick still never switches a shell on.
|
||||
async function partShells() {
|
||||
console.log('-- Part S: hub shells in the tank');
|
||||
const B = bench(); const { tank, accounts } = B;
|
||||
const shell = o => Object.assign({ joinedVia: 'carried', joinedRef: 'hub', lastSeen: 0 }, o || {});
|
||||
accounts.add('shell@x.co', shell()); accounts.add('shellsp@x.co', shell()); accounts.add('shellkid@x.co', shell({ sponsorRef: 'someone' })); accounts.add('plain@x.co');
|
||||
const isShell = a => a.joinedVia === 'carried' && a.joinedRef === 'hub' && !a.lastSeen && !a.memberId;
|
||||
const all0 = accounts.listAll; accounts.listAll = async (limit, opts) => (await all0.call(accounts)).filter(a => (opts && opts.shells) || !isShell(a));
|
||||
tank.init({ dataDir: B.dir, accounts, chain: { recentEvents: () => [], getConfig: () => ({}) }, messages: { sendChat: async () => {}, lastFrom: async () => 0 }, mailer: { hasKey: () => false, send: async () => {} }, site: 'https://linkspin.test',
|
||||
hooks: { networkHeld: async list => new Map(list.filter(a => isShell(a)).map(a => [a.email, a.email === 'shellsp@x.co' ? 'sponsored' : 'hub-shell'])), companyId: () => 1 } });
|
||||
const w = (await tank.waiting()).map(x => x.email);
|
||||
ok(w.includes('shell@x.co'), 'a hub shell with no sponsor is in the waiting list', JSON.stringify(w));
|
||||
ok(w.includes('plain@x.co'), 'a normal tank member still is');
|
||||
ok(!w.includes('shellsp@x.co'), 'a shell the hub says is sponsored elsewhere stays out (rule 3)');
|
||||
ok(!w.includes('shellkid@x.co'), 'a shell with a sponsor here is not in the tank');
|
||||
ok((await accounts.listAll(100)).every(a => !isShell(a)), 'accounts.listAll default still leaves shells out (mailings)');
|
||||
await tank.readyTick();
|
||||
ok(!tank.readyRec('shell@x.co'), 'readyTick never marks a shell ready (quiet)');
|
||||
}
|
||||
|
||||
await partA();
|
||||
await partGrace();
|
||||
await partShells();
|
||||
if (process.argv[2] !== 'unit') await partB();
|
||||
console.log(fails ? '\n' + fails + ' FAILED' : '\nall passed');
|
||||
process.exit(fails ? 1 : 0);
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
// Top-up across positions (Michael Camire 2026-11-14, LinkSpin Support): he bought credits on his linked position,
|
||||
// the dashboard showed them, but adding 1000 credits to his text ad failed. An ad burns from ONE member id, and the
|
||||
// top-up only ever looked at that one (or, with no memberId on the list row, the main position). Same fix as
|
||||
// InstantAdPay 2026-09-27 (Jim Watts): say where the free credits are, offer the position that can pay, and on the
|
||||
// member's yes move the ad's funding there (old charges settle on the old position first) and top up.
|
||||
// Unit test on ads.js directly: throwaway DATA_DIR, JSON store, a fake chain. No server, no mail, no network.
|
||||
// node qa/topup-positions.test.cjs
|
||||
'use strict';
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
for (const k of ['DATABASE_URL', 'NAS_DB_HOST', 'NAS_DB_USER', 'NAS_DB_PASSWORD', 'NAS_DB_NAME', 'OUTBOUND', 'ENGINE_KEY']) delete process.env[k];
|
||||
const SITE = path.join(__dirname, '..');
|
||||
const DATA = fs.mkdtempSync(path.join(os.tmpdir(), 'topup-pos-'));
|
||||
const ads = require(path.join(SITE, 'ads.js'));
|
||||
const ONCHAIN = { 101: 300, 202: 6000, 303: 40 }; // main position, the linked one he bought on, a small third
|
||||
const chain = { creditBalance: async id => ONCHAIN[id] || 0 };
|
||||
const OWNER = 'mc@topup.test', OTHER = 'someone@topup.test';
|
||||
|
||||
let passed = 0, failed = 0; const results = [];
|
||||
async function t(name, fn) { try { await fn(); passed++; results.push('ok ' + name); } catch (e) { failed++; results.push('FAIL ' + name + '\n ' + String(e && e.stack || e).split('\n').slice(0, 4).join('\n ')); } }
|
||||
const text = extra => Object.assign({ type: 'text', name: 'My text ad', targetUrl: 'https://example.com/offer', title: 'A good offer', body: 'Read about it here.', budget: 200 }, extra || {});
|
||||
const rowOf = id => JSON.parse(fs.readFileSync(path.join(DATA, 'campaigns.json'), 'utf8')).campaigns.find(c => c.id === id);
|
||||
|
||||
(async () => {
|
||||
ads.init({ dataDir: DATA, chain });
|
||||
let C;
|
||||
await t('a text ad created on the main position pays from it', async () => {
|
||||
const r = await ads.createCampaign(OWNER, 101, text(), [101, 202, 303]);
|
||||
assert.ok(!r.error, r.error); C = r.campaign || r; assert.ok(C.id, 'campaign id');
|
||||
assert.strictEqual(rowOf(C.id).memberId, 101);
|
||||
});
|
||||
await t('1000 credits from a position that has 100 free: refused with where the credits are, nothing moved', async () => {
|
||||
const r = await ads.topUpCampaign(OWNER, 101, C.id, 1000, { positions: [101, 202, 303] });
|
||||
assert.ok(r.error, 'refused');
|
||||
assert.match(r.error, /position #101, which has 100 credits free/);
|
||||
assert.match(r.error, /#202 has 6,000 free/);
|
||||
assert.match(r.error, /from #202 instead/);
|
||||
assert.deepStrictEqual(r.switchOptions, [{ memberId: 202, free: 6000 }]); // #303 (40) cannot cover 1000
|
||||
assert.strictEqual(rowOf(C.id).memberId, 101); assert.strictEqual(rowOf(C.id).budget, 200);
|
||||
});
|
||||
await t('switchTo a position not on the account is ignored (no move, same refusal)', async () => {
|
||||
const r = await ads.topUpCampaign(OWNER, 101, C.id, 1000, { positions: [101, 303], switchTo: 202 });
|
||||
assert.ok(r.error); assert.ok(!r.switchOptions.length);
|
||||
assert.strictEqual(rowOf(C.id).memberId, 101); assert.strictEqual(rowOf(C.id).budget, 200);
|
||||
});
|
||||
await t('another member cannot top up or move the ad', async () => {
|
||||
const r = await ads.topUpCampaign(OTHER, 202, C.id, 1000, { positions: [202], switchTo: 202 });
|
||||
assert.ok(r.error); assert.strictEqual(rowOf(C.id).memberId, 101);
|
||||
});
|
||||
await t('with the member\'s yes (switchTo 202): the ad moves to #202, old charges settle on #101, 1000 added', async () => {
|
||||
// 30 credits of views the ad already ran up on #101, not yet burned: they must burn from #101, never #202
|
||||
const F = path.join(DATA, 'campaigns.json'); const db = JSON.parse(fs.readFileSync(F, 'utf8'));
|
||||
db.campaigns.find(c => c.id === C.id).accrued = 30; fs.writeFileSync(F, JSON.stringify(db)); ads.init({ dataDir: DATA, chain });
|
||||
const r = await ads.topUpCampaign(OWNER, 101, C.id, 1000, { positions: [101, 202, 303], switchTo: 202 });
|
||||
assert.ok(!r.error, r.error);
|
||||
assert.strictEqual(r.added, 1000); assert.strictEqual(r.paidFrom, 202); assert.strictEqual(r.budget, 1200);
|
||||
const row = rowOf(C.id); assert.strictEqual(row.memberId, 202); assert.strictEqual(row.budget, 1200); assert.strictEqual(row.status, 'active');
|
||||
assert.strictEqual(row.accrued, 0); assert.strictEqual(row.spent, 30);
|
||||
const burns = JSON.parse(fs.readFileSync(F, 'utf8')).burnsPending.filter(b => b.ref === 'campaign-' + C.id);
|
||||
assert.deepStrictEqual(burns.map(b => [b.memberId, b.amount]), [[101, 30]]);
|
||||
});
|
||||
await t('balances follow the move: #101 keeps only its own 30 to burn, #202 holds the rest of the ad', async () => {
|
||||
const b = await ads.balances([101, 202, 303], OWNER);
|
||||
const per = Object.fromEntries(b.per.map(p => [p.memberId, p.avail]));
|
||||
assert.strictEqual(per[101], 300 - 30);
|
||||
assert.strictEqual(per[202], 6000 - (1200 - 30));
|
||||
assert.strictEqual(per[303], 40);
|
||||
});
|
||||
await t('a top-up the ad\'s own position covers needs no switch and stays put', async () => {
|
||||
const r = await ads.topUpCampaign(OWNER, 101, C.id, 500, { positions: [101, 202, 303] });
|
||||
assert.ok(!r.error, r.error); assert.strictEqual(r.paidFrom, 202); assert.strictEqual(rowOf(C.id).memberId, 202);
|
||||
});
|
||||
await t('no single position can cover: says the most one go can add', async () => {
|
||||
const r = await ads.topUpCampaign(OWNER, 101, C.id, 5000, { positions: [101, 202, 303] });
|
||||
assert.ok(r.error); assert.match(r.error, /No single position has 5,000 free; the most you can add in one go is 4,330/);
|
||||
assert.deepStrictEqual(r.switchOptions, []);
|
||||
});
|
||||
|
||||
console.log(results.join('\n'));
|
||||
console.log('\ntopup-positions: ' + passed + ' passed, ' + failed + ' failed');
|
||||
try { fs.rmSync(DATA, { recursive: true, force: true }); } catch (e) {}
|
||||
process.exit(failed ? 1 : 0);
|
||||
})();
|
||||
Reference in New Issue
Block a user