Network rate 4:1 (Marty approved 2026-10-27, same as InstantAdPay): views off LinkSpin cost 1/synRateDivisor of the on-site rate, going forward
rates.synRateDivisor (default 4, Admin > Rates; 1 = the old rule). Network Ad Space impressions charge 1 credit per impressionsPerCredit x N views; member campaigns shown in other members' zones on their own sites (zones.js serve, offsite) are counted in the new synImps (not Views here) and charged one batch per N x the on-site batch (2 credits per 40 banner views at N=4) through the same spend path, so burns follow what was charged. Fractions are exact (the cumulative served count / the syn_batch counter carry the remainder). The budget is the limit: bookings, resume, top-up and daily allowances are sized at the network rate, and a live ad booked at the old rate is topped up once. Nothing already charged changes; zone owners keep earning as before. Ads screen + classic Campaigns show network and partner-zone views marked at 1/4; chatbot canned answer + live AI fact; cache tags bumped. QA: qa/run.sh nas (stop 9, ratio 10), loginqueue 13, refill 12, run.sh member passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
// Network rate on LinkSpin (Marty, 2026-10-27, approved 4:1): views off LinkSpin's own pages cost 1/synRateDivisor of the
|
||||
// on-site rate. JSON store, NAS stubbed, throwaway data dir. node qa/nas-ratio.test.cjs
|
||||
// Covers: N=4 NAS views (1 credit per 20 banner views, fractions exact), partner-zone views (2 credits per 40, counted in
|
||||
// synImps, not in Views here), on-site batches unchanged, budget is the limit, a lowered rate tops NAS up once, N=1 = old rule.
|
||||
'use strict';
|
||||
delete process.env.DATABASE_URL;
|
||||
const fs = require('fs'); const os = require('os'); const path = require('path');
|
||||
const ok = [], bad = [];
|
||||
const t = (n, c, extra) => { (c ? ok : bad).push(n + (c || extra === undefined ? '' : ' -> ' + extra)); };
|
||||
const DATA = fs.mkdtempSync(path.join(os.tmpdir(), 'ls-nas-ratio-'));
|
||||
const nas = require('../nas.js');
|
||||
const rows = {}; const calls = { topUp: [], deactivate: 0 };
|
||||
nas.enabled = () => true;
|
||||
nas.impressionsPerCredit = type => type === 'banner' ? 5 : 10;
|
||||
nas.readServed = async id => { const r = rows[id]; return r ? { assigned: r.assigned, remaining: r.remaining, served: Math.max(0, Math.min(r.assigned, r.assigned - r.remaining)), clicks: 0 } : null; };
|
||||
nas.deactivate = async id => { const r = rows[id]; const served = Math.max(0, r.assigned - r.remaining); r.remaining = 0; calls.deactivate++; return { ok: true, served }; };
|
||||
nas.topUp = async (id, add) => { rows[id].assigned += add; rows[id].remaining += add; calls.topUp.push([id, add]); return { ok: true }; };
|
||||
nas.restart = async (id, base, add) => { rows[id].assigned = base + add; rows[id].remaining = add; return { ok: true }; };
|
||||
nas.updateCreative = async () => ({ ok: true });
|
||||
const ads = require('../ads.js');
|
||||
const zones = require('../zones.js');
|
||||
const ADV = 'ratio@qa.test', PUB = 'pub@qa.test', FILE = path.join(DATA, 'campaigns.json');
|
||||
const banner = (id, x) => Object.assign({ id, owner: ADV, memberId: 0, type: 'banner', name: 'QA ' + id, targetUrl: 'https://example.com/', imageUrl: 'https://example.com/b.png', width: 728, height: 90,
|
||||
budget: 1000, spent: 0, accrued: 0, imps: 0, batchImps: 0, clicks: 0, status: 'active', created: Date.now() }, x || {});
|
||||
const seed = camps => { fs.writeFileSync(FILE, JSON.stringify({ v: 1, nextId: 9100, campaigns: camps, burnsPending: [] })); ads.init({ dataDir: DATA, chain: { creditBalance: async () => 0 } }); };
|
||||
const C = id => JSON.parse(fs.readFileSync(FILE, 'utf8')).campaigns.find(c => c.id === id);
|
||||
const used = c => (c.spent || 0) + (c.accrued || 0);
|
||||
const req = { headers: { referer: 'https://pubsite.org/page', 'user-agent': 'Mozilla/5.0 (QA)', 'x-forwarded-for': '203.0.113.9' }, socket: {} };
|
||||
(async () => {
|
||||
t('default divisor is 4', ads.synRateDivisor() === 4, String(ads.synRateDivisor()));
|
||||
// partner zones
|
||||
seed([banner(9001)]);
|
||||
fs.writeFileSync(path.join(DATA, 'zone-rates.json'), JSON.stringify({ nasOn: 0 }));
|
||||
zones.init({ dataDir: DATA, ads, siteHost: 'linkspin.test' });
|
||||
await ads.addEarned(ADV, 100000);
|
||||
const z = (await zones.create(PUB, { name: 'QA zone', site: 'pubsite.org', size: '728x90' })).zone;
|
||||
for (let i = 0; i < 39; i++) await zones.serve(z.id, req, {});
|
||||
let c = C(9001);
|
||||
t('N=4: 39 partner-zone views charge nothing yet', used(c) === 0, String(used(c)));
|
||||
await zones.serve(z.id, req, {}); c = C(9001);
|
||||
t('the 40th completes one batch: 2 credits (1/4 of 2 per 10)', used(c) === 2, String(used(c)));
|
||||
t('partner-zone views counted in synImps, not in Views here', c.synImps === 40 && c.imps === 0, JSON.stringify({ syn: c.synImps, imps: c.imps }));
|
||||
for (let i = 0; i < 10; i++) await ads.serve('banner', { width: 728, height: 90 });
|
||||
c = C(9001);
|
||||
t('on-site: 10 views still charge 2 credits', used(c) === 4 && c.imps === 10, JSON.stringify({ used: used(c), imps: c.imps }));
|
||||
// NAS
|
||||
rows[9002] = { assigned: 20000, remaining: 20000 };
|
||||
seed([C(9001), banner(9002, { nasAdId: 9002, nasServed: 0 })]);
|
||||
rows[9002].remaining -= 1010; await ads.reconcileNas();
|
||||
t('N=4: 1,010 network views charge 50 credits (1 per 20)', used(C(9002)) === 50, String(used(C(9002))));
|
||||
rows[9002].remaining -= 10; await ads.reconcileNas();
|
||||
t('10 more complete the 51st credit (fraction carried)', used(C(9002)) === 51, String(used(C(9002))));
|
||||
// budget is the limit
|
||||
rows[9003] = { assigned: 200, remaining: 200 };
|
||||
seed([C(9001), C(9002), banner(9003, { budget: 10, nasAdId: 9003, nasServed: 0 })]);
|
||||
rows[9003].remaining -= 200; await ads.reconcileNas();
|
||||
const x = C(9003);
|
||||
t('budget is the limit: 10 credits, ad out, NAS stopped', used(x) === 10 && x.status === 'out' && calls.deactivate >= 1, JSON.stringify({ used: used(x), st: x.status }));
|
||||
// old rule, then the rate lowered
|
||||
ads.setRates({ synRateDivisor: 1 });
|
||||
rows[9004] = { assigned: 1000, remaining: 1000 };
|
||||
seed([C(9001), C(9002), C(9003), banner(9004, { nasAdId: 9004, nasServed: 0 })]);
|
||||
rows[9004].remaining -= 500; await ads.reconcileNas();
|
||||
t('N=1 (old rule): 500 network views charge 100 credits', used(C(9004)) === 100, String(used(C(9004))));
|
||||
ads.setRates({ synRateDivisor: 4 });
|
||||
const b0 = calls.topUp.length; await ads.reconcileNas(); await ads.reconcileNas();
|
||||
const tu = calls.topUp.slice(b0).filter(q => q[0] === 9004);
|
||||
t('rate lowered to 1/4: NAS topped up once to what 900 credits now buy (18,000)', tu.length === 1 && rows[9004].remaining === 18000, JSON.stringify({ tu, row: rows[9004] }));
|
||||
console.log('PASS ' + ok.length);
|
||||
for (const b of bad) console.log('FAIL ' + b);
|
||||
try { fs.rmSync(DATA, { recursive: true, force: true }); } catch (e) {}
|
||||
process.exit(bad.length ? 1 : 0);
|
||||
})().catch(e => { console.error(e); process.exit(1); });
|
||||
+56
-55
@@ -1,55 +1,56 @@
|
||||
// NAS stop trap on LinkSpin (fixed 2026-10-27; the InstantAdPay 2026-09-17 fix was never ported). NAS has no stop flag,
|
||||
// a stop zeroes `remaining`, and served = assigned - remaining then reads the undelivered rest as DELIVERED. Before the fix:
|
||||
// pause/end/exhaustion called nas.deactivate with no snapshot, reconcileNas read EVERY status, so a paused ad was charged
|
||||
// for its zeroed remainder, and a resume/top-up of a stopped ad counted it again. JSON store, NAS stubbed, throwaway data.
|
||||
// node qa/nas-stop.test.cjs
|
||||
'use strict';
|
||||
delete process.env.DATABASE_URL;
|
||||
const fs = require('fs'); const os = require('os'); const path = require('path');
|
||||
const ok = [], bad = [];
|
||||
const t = (n, c, extra) => { (c ? ok : bad).push(n + (c || extra === undefined ? '' : ' -> ' + extra)); };
|
||||
const DATA = fs.mkdtempSync(path.join(os.tmpdir(), 'ls-nas-stop-'));
|
||||
const nas = require('../nas.js');
|
||||
const rows = {}; const calls = { restart: 0, deactivate: 0 };
|
||||
nas.enabled = () => true;
|
||||
nas.impressionsPerCredit = type => type === 'banner' ? 5 : 10;
|
||||
nas.readServed = async id => { const r = rows[id]; return r ? { assigned: r.assigned, remaining: r.remaining, served: Math.max(0, Math.min(r.assigned, r.assigned - r.remaining)), clicks: 0 } : null; };
|
||||
nas.deactivate = async id => { const r = rows[id]; const served = Math.max(0, r.assigned - r.remaining); r.remaining = 0; calls.deactivate++; return { ok: true, served }; };
|
||||
nas.topUp = async (id, add) => { rows[id].assigned += add; rows[id].remaining += add; return { ok: true }; };
|
||||
nas.restart = async (id, base, add) => { rows[id].assigned = base + add; rows[id].remaining = add; calls.restart++; return { ok: true }; };
|
||||
nas.updateCreative = async () => ({ ok: true });
|
||||
const ads = require('../ads.js');
|
||||
const ADV = 'stop@qa.test', FILE = path.join(DATA, 'campaigns.json');
|
||||
const banner = (id, x) => Object.assign({ id, owner: ADV, memberId: 0, type: 'banner', name: 'QA ' + id, targetUrl: 'https://example.com/', imageUrl: 'https://example.com/b.png', width: 728, height: 90,
|
||||
budget: 1000, spent: 0, accrued: 0, imps: 0, batchImps: 0, clicks: 0, status: 'active', nasAdId: id, nasServed: 0, created: Date.now() }, x || {});
|
||||
const seed = camps => { fs.writeFileSync(FILE, JSON.stringify({ v: 1, nextId: 9100, campaigns: camps, burnsPending: [] })); ads.init({ dataDir: DATA, chain: { creditBalance: async () => 0 } }); };
|
||||
const C = id => JSON.parse(fs.readFileSync(FILE, 'utf8')).campaigns.find(c => c.id === id);
|
||||
const used = c => (c.spent || 0) + (c.accrued || 0);
|
||||
(async () => {
|
||||
seed([banner(9001), banner(9002, { budget: 100 })]);
|
||||
await ads.addEarned(ADV, 10000);
|
||||
rows[9001] = { assigned: 5000, remaining: 5000 }; rows[9002] = { assigned: 500, remaining: 500 };
|
||||
rows[9001].remaining -= 1000; await ads.reconcileNas();
|
||||
t('1,000 real NAS views charge 200 credits', used(C(9001)) === 200, String(used(C(9001))));
|
||||
await ads.setStatus(ADV, 9001, 'paused');
|
||||
t('pause records the TRUE 1,000 served, not the 5,000 allocation', C(9001).nasServed === 1000, String(C(9001).nasServed));
|
||||
await ads.reconcileNas();
|
||||
t('a paused ad is not charged for its zeroed remainder', used(C(9001)) === 200, String(used(C(9001))));
|
||||
const r0 = calls.restart; await ads.setStatus(ADV, 9001, 'active'); await ads.reconcileNas();
|
||||
t('resume restarts the stopped ad from the true count', calls.restart === r0 + 1 && rows[9001].assigned === 5000 && rows[9001].remaining === 4000, JSON.stringify(rows[9001]));
|
||||
t('no phantom delivery or charge after the resume', C(9001).nasServed === 1000 && used(C(9001)) === 200, C(9001).nasServed + ' / ' + used(C(9001)));
|
||||
rows[9001].remaining -= 500; await ads.reconcileNas();
|
||||
t('real views after the resume still charge (500 = 100 credits)', used(C(9001)) === 300, String(used(C(9001))));
|
||||
// exhaustion: budget 100 = 500 views; NAS serves 300, a budget top-up of on-site spend exhausts it on the next reconcile
|
||||
const c2 = C(9002); c2.spent = 60; const s = JSON.parse(fs.readFileSync(FILE, 'utf8')); s.campaigns[s.campaigns.findIndex(x => x.id === 9002)] = c2; fs.writeFileSync(FILE, JSON.stringify(s)); ads.init({ dataDir: DATA, chain: { creditBalance: async () => 0 } });
|
||||
rows[9002].remaining -= 300; const d0 = calls.deactivate; await ads.reconcileNas();
|
||||
const x = C(9002);
|
||||
t('exhausted: charge capped at the budget and the NAS ad stopped', used(x) === 100 && x.status === 'out' && calls.deactivate === d0 + 1, JSON.stringify({ used: used(x), st: x.status }));
|
||||
t('exhausted: served kept at the TRUE 300', x.nasServed === 300, String(x.nasServed));
|
||||
await ads.reconcileNas();
|
||||
t('an exhausted (out) ad is never reconciled again', C(9002).nasServed === 300 && used(C(9002)) === 100, String(C(9002).nasServed));
|
||||
console.log('PASS ' + ok.length);
|
||||
for (const b of bad) console.log('FAIL ' + b);
|
||||
try { fs.rmSync(DATA, { recursive: true, force: true }); } catch (e) {}
|
||||
process.exit(bad.length ? 1 : 0);
|
||||
})().catch(e => { console.error(e); process.exit(1); });
|
||||
// NAS stop trap on LinkSpin (fixed 2026-10-27; the InstantAdPay 2026-09-17 fix was never ported). NAS has no stop flag,
|
||||
// a stop zeroes `remaining`, and served = assigned - remaining then reads the undelivered rest as DELIVERED. Before the fix:
|
||||
// pause/end/exhaustion called nas.deactivate with no snapshot, reconcileNas read EVERY status, so a paused ad was charged
|
||||
// for its zeroed remainder, and a resume/top-up of a stopped ad counted it again. JSON store, NAS stubbed, throwaway data.
|
||||
// node qa/nas-stop.test.cjs
|
||||
'use strict';
|
||||
delete process.env.DATABASE_URL;
|
||||
const fs = require('fs'); const os = require('os'); const path = require('path');
|
||||
const ok = [], bad = [];
|
||||
const t = (n, c, extra) => { (c ? ok : bad).push(n + (c || extra === undefined ? '' : ' -> ' + extra)); };
|
||||
const DATA = fs.mkdtempSync(path.join(os.tmpdir(), 'ls-nas-stop-'));
|
||||
const nas = require('../nas.js');
|
||||
const rows = {}; const calls = { restart: 0, deactivate: 0 };
|
||||
nas.enabled = () => true;
|
||||
nas.impressionsPerCredit = type => type === 'banner' ? 5 : 10;
|
||||
nas.readServed = async id => { const r = rows[id]; return r ? { assigned: r.assigned, remaining: r.remaining, served: Math.max(0, Math.min(r.assigned, r.assigned - r.remaining)), clicks: 0 } : null; };
|
||||
nas.deactivate = async id => { const r = rows[id]; const served = Math.max(0, r.assigned - r.remaining); r.remaining = 0; calls.deactivate++; return { ok: true, served }; };
|
||||
nas.topUp = async (id, add) => { rows[id].assigned += add; rows[id].remaining += add; return { ok: true }; };
|
||||
nas.restart = async (id, base, add) => { rows[id].assigned = base + add; rows[id].remaining = add; calls.restart++; return { ok: true }; };
|
||||
nas.updateCreative = async () => ({ ok: true });
|
||||
const ads = require('../ads.js');
|
||||
const ADV = 'stop@qa.test', FILE = path.join(DATA, 'campaigns.json');
|
||||
const banner = (id, x) => Object.assign({ id, owner: ADV, memberId: 0, type: 'banner', name: 'QA ' + id, targetUrl: 'https://example.com/', imageUrl: 'https://example.com/b.png', width: 728, height: 90,
|
||||
budget: 1000, spent: 0, accrued: 0, imps: 0, batchImps: 0, clicks: 0, status: 'active', nasAdId: id, nasServed: 0, created: Date.now() }, x || {});
|
||||
const seed = camps => { fs.writeFileSync(FILE, JSON.stringify({ v: 1, nextId: 9100, campaigns: camps, burnsPending: [] })); ads.init({ dataDir: DATA, chain: { creditBalance: async () => 0 } }); };
|
||||
const C = id => JSON.parse(fs.readFileSync(FILE, 'utf8')).campaigns.find(c => c.id === id);
|
||||
const used = c => (c.spent || 0) + (c.accrued || 0);
|
||||
(async () => {
|
||||
seed([banner(9001), banner(9002, { budget: 100 })]);
|
||||
await ads.addEarned(ADV, 10000);
|
||||
ads.setRates({ synRateDivisor: 1 }); // the stop/restart logic at the on-site rate (qa/nas-ratio.test.cjs covers the network rate)
|
||||
rows[9001] = { assigned: 5000, remaining: 5000 }; rows[9002] = { assigned: 500, remaining: 500 };
|
||||
rows[9001].remaining -= 1000; await ads.reconcileNas();
|
||||
t('1,000 real NAS views charge 200 credits', used(C(9001)) === 200, String(used(C(9001))));
|
||||
await ads.setStatus(ADV, 9001, 'paused');
|
||||
t('pause records the TRUE 1,000 served, not the 5,000 allocation', C(9001).nasServed === 1000, String(C(9001).nasServed));
|
||||
await ads.reconcileNas();
|
||||
t('a paused ad is not charged for its zeroed remainder', used(C(9001)) === 200, String(used(C(9001))));
|
||||
const r0 = calls.restart; await ads.setStatus(ADV, 9001, 'active'); await ads.reconcileNas();
|
||||
t('resume restarts the stopped ad from the true count', calls.restart === r0 + 1 && rows[9001].assigned === 5000 && rows[9001].remaining === 4000, JSON.stringify(rows[9001]));
|
||||
t('no phantom delivery or charge after the resume', C(9001).nasServed === 1000 && used(C(9001)) === 200, C(9001).nasServed + ' / ' + used(C(9001)));
|
||||
rows[9001].remaining -= 500; await ads.reconcileNas();
|
||||
t('real views after the resume still charge (500 = 100 credits)', used(C(9001)) === 300, String(used(C(9001))));
|
||||
// exhaustion: budget 100 = 500 views; NAS serves 300, a budget top-up of on-site spend exhausts it on the next reconcile
|
||||
const c2 = C(9002); c2.spent = 60; const s = JSON.parse(fs.readFileSync(FILE, 'utf8')); s.campaigns[s.campaigns.findIndex(x => x.id === 9002)] = c2; fs.writeFileSync(FILE, JSON.stringify(s)); ads.init({ dataDir: DATA, chain: { creditBalance: async () => 0 } });
|
||||
rows[9002].remaining -= 300; const d0 = calls.deactivate; await ads.reconcileNas();
|
||||
const x = C(9002);
|
||||
t('exhausted: charge capped at the budget and the NAS ad stopped', used(x) === 100 && x.status === 'out' && calls.deactivate === d0 + 1, JSON.stringify({ used: used(x), st: x.status }));
|
||||
t('exhausted: served kept at the TRUE 300', x.nasServed === 300, String(x.nasServed));
|
||||
await ads.reconcileNas();
|
||||
t('an exhausted (out) ad is never reconciled again', C(9002).nasServed === 300 && used(C(9002)) === 100, String(C(9002).nasServed));
|
||||
console.log('PASS ' + ok.length);
|
||||
for (const b of bad) console.log('FAIL ' + b);
|
||||
try { fs.rmSync(DATA, { recursive: true, force: true }); } catch (e) {}
|
||||
process.exit(bad.length ? 1 : 0);
|
||||
})().catch(e => { console.error(e); process.exit(1); });
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
# bash qa/run.sh tankhold # holding tank: network alignment first, plain-activation hold (never a purchase), 24-hour rotation, payouts on at assignment (unit with a mocked clock + fake engine, then a local copy with a mock InstantAdPay)
|
||||
# bash qa/run.sh lsid # page-builder lead -> rotator conversion + postback, audience pixel events and cookieless hits
|
||||
# bash qa/run.sh convpixel # conversion pixel: ad click ids, landing tag + goal pixel (url/stored/cookie/soft), dedupe, window, owner check, cost per goal, IAP partner calls, browser + framed
|
||||
# bash qa/run.sh nas # Network Ad Space billing: stop snapshot, active-only reconcile, restart without phantom delivery, the 1/N network + partner-zone rate (stubbed NAS, throwaway data)
|
||||
# bash qa/run.sh loginqueue # prepaid login-slot queue: ads.js unit test (two app copies promoting at once) + HTTP/Ads-screen e2e on a local copy
|
||||
# bash qa/run.sh override # level-4 override: week math, hunt, house, dust carry, cap, balance, two concurrent payers (fake chain + signer, throwaway data)
|
||||
# bash qa/run.sh fuel # Fuel Your Offers: refill notices, refuel streak, Refuel Kit, Engine Room (unit + two-copy tests, throwaway data)
|
||||
@@ -49,6 +50,9 @@ elif [ "$MODE" = "sponsorfollow" ]; then
|
||||
node qa/carry-activate.test.cjs || status=1
|
||||
elif [ "$MODE" = "tankhold" ]; then
|
||||
node qa/tank-hold.test.mjs || status=1
|
||||
elif [ "$MODE" = "nas" ]; then
|
||||
node qa/nas-stop.test.cjs || status=1
|
||||
node qa/nas-ratio.test.cjs || status=1
|
||||
elif [ "$MODE" = "loginqueue" ]; then
|
||||
node qa/loginqueue.test.cjs || status=1
|
||||
node qa/loginqueue.e2e.mjs || status=1
|
||||
|
||||
Reference in New Issue
Block a user