Hub activity from every signed-in LinkSpin use (Marty 2026-11-16: "LinkSpin never reports activity", DownlineHydra Wake it)
The page-load ping (networksso.page) only fires on a full top-level navigation with Sec-Fetch-Dest: document and a
member session that carries an email. It never fired for a Control Room tab kept open (client-side moves and the
/api/my/ping heartbeat), browsers that send no Sec-Fetch headers, wallet-only sessions, or the owner working in the
admin portal. Live finding: Marty has had no LinkSpin member session since 2026-11-15 20:20 UTC, before the ping
shipped (b2669cf, 21:36 UTC); 16 other members already had linkspin rows.
- networksso.seen(s): the same once-a-day ping for any signed-in request; called from /api/me (email or wallet),
the dashboard heartbeat /api/my/ping and the admin portal page (/admin, the owner's email; hub activity only,
the admin session is never shared).
- qa/networksso-activity.test.mjs (13 checks, real hub, in run.sh sso + member): a signed-in page load records
site linkspin, once a day, never API/assets/bots/fetches/signed-out, seen() for an open tab and a wallet session.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+12
-1
@@ -167,6 +167,17 @@ function activity(w) {
|
||||
const k = w.email || w.wallet; if (pinged.has(k)) return; pinged.set(k, 1);
|
||||
hubCall('/v1/activity', Object.assign({ kind: 'visit' }, w), 5000).then(r => { if (r.status >= 500) pinged.delete(k); }).catch(() => { pinged.delete(k); });
|
||||
}
|
||||
// a signed-in request the site already answers (2026-11-16, Marty: "LinkSpin never reports activity"): /api/me, the dashboard
|
||||
// heartbeat (/api/my/ping) and the admin portal call this, so a Control Room tab kept open for days, a browser that sends no
|
||||
// Sec-Fetch headers and a wallet-only session still count the day's visit. The page-load ping in page() only sees full navigations.
|
||||
// s = {email} and/or {address}. Same once-a-day rule as page(). -> true when a ping was due or already sent today.
|
||||
function seen(s) {
|
||||
try {
|
||||
if (!C || !hubCreds()) return false;
|
||||
const w = who(s && s.email ? s : s && s.address ? { address: s.address } : null); if (!w) return false;
|
||||
activity(w); return true;
|
||||
} catch (e) { return false; }
|
||||
}
|
||||
// a real top-level page load of a page (never an API call, an asset, a fetch, a bot or one of our own hops)
|
||||
function pageLoad(req, p) {
|
||||
if (req.method !== 'GET' || isBot(req)) return false;
|
||||
@@ -352,4 +363,4 @@ async function page(req, res, u) {
|
||||
// true when this browser came here from a deliberate network tap and still has to finish it after signing in
|
||||
const pendingBack = req => !!cookies(req)['nsso.back'];
|
||||
|
||||
module.exports = { init, handle, page, enabled, pendingBack, mint, verify, spend, safePath, isBot, offCookie, mask, TTL, NAMES, hubOn, hubCreds, signOutEverywhere, mintHub, verifyHub, _hubSeen: t => { hubSeen = t == null ? Date.now() : t; hubChecked = Date.now(); }, _pinged: pinged };
|
||||
module.exports = { init, handle, page, seen, enabled, pendingBack, mint, verify, spend, safePath, isBot, offCookie, mask, TTL, NAMES, hubOn, hubCreds, signOutEverywhere, mintHub, verifyHub, _hubSeen: t => { hubSeen = t == null ? Date.now() : t; hubChecked = Date.now(); }, _pinged: pinged };
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
// LinkSpin -> network hub activity (Marty 2026-11-16: "LinkSpin never reports activity", DownlineHydra "Wake it").
|
||||
// node qa/networksso-activity.test.mjs (needs ../../network-hub beside this repo; skips otherwise)
|
||||
// Boots the REAL hub (JSON store, throwaway dir) and drives networksso.js in this process the way server.js does:
|
||||
// 1. a signed-in member's real page load (/links, Sec-Fetch-Dest: document) records site 'linkspin' on the hub
|
||||
// 2. a second page load the same day sends nothing more (once a day)
|
||||
// 3. API calls, assets, bots and signed-out page loads never ping
|
||||
// 4. seen() (what /api/me, /api/my/ping and the admin portal call): a tab kept open, a browser with no Sec-Fetch headers,
|
||||
// and a wallet-only session all record the day's visit
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import crypto from 'node:crypto';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { createRequire } from 'node:module';
|
||||
|
||||
const HERE = path.resolve(path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1')), '..');
|
||||
const HUB_DIR = [process.env.HUB_DIR, path.resolve(HERE, '../../network-hub')].filter(Boolean).find(d => fs.existsSync(path.join(d, 'lib', 'activity.js')));
|
||||
if (!HUB_DIR) { console.log('SKIP activity test: needs ../../network-hub'); process.exit(0); }
|
||||
const require = createRequire(import.meta.url);
|
||||
let fails = 0; const ok = (c, label, extra) => { console.log((c ? 'PASS ' : 'FAIL ') + label + (extra ? ' ' + extra : '')); if (!c) fails++; };
|
||||
const sleep = ms => new Promise(r => setTimeout(r, ms));
|
||||
|
||||
const KEY = crypto.randomBytes(24).toString('hex'); const HP = Number(process.env.ACT_HUB_PORT || 8871); const HUB = 'http://127.0.0.1:' + HP;
|
||||
const TMP = fs.mkdtempSync(path.join(os.tmpdir(), 'ls-act-'));
|
||||
let hubLog = '';
|
||||
const hub = spawn(process.execPath, ['server.js'], { cwd: HUB_DIR, stdio: ['ignore', 'pipe', 'pipe'],
|
||||
env: Object.assign({}, process.env, { PORT: String(HP), DATA_DIR: TMP, DATABASE_URL: '', HUB_ADMIN_SECRET: '', HUB_FORUM_URL: '', HUB_FORUM_API_KEY: '', HUB_SITES: JSON.stringify({ linkspin: { secret: KEY } }) }) });
|
||||
hub.stdout.on('data', d => hubLog += d); hub.stderr.on('data', d => hubLog += d);
|
||||
const done = code => { try { hub.kill(); } catch (e) {} try { fs.rmSync(TMP, { recursive: true, force: true }); } catch (e) {} process.exit(code); };
|
||||
|
||||
async function call(route, body) {
|
||||
const raw = JSON.stringify(body); const ts = String(Date.now());
|
||||
const r = await fetch(HUB + route, { method: 'POST', body: raw, headers: { 'Content-Type': 'application/json', 'X-Hub-Site': 'linkspin', 'X-Hub-Ts': ts, 'X-Hub-Sig': crypto.createHmac('sha256', KEY).update(ts + '\n' + raw).digest('hex') } });
|
||||
return { status: r.status, body: await r.json().catch(() => null) };
|
||||
}
|
||||
const lsAt = async id => { const r = await call('/v1/activity/person', { id }); return r.body && r.body.sites && r.body.sites.linkspin ? r.body.sites.linkspin : null; };
|
||||
|
||||
try {
|
||||
for (let i = 0; i < 40; i++) { try { if ((await fetch(HUB + '/health')).ok) break; } catch (e) {} await sleep(250); }
|
||||
// members on the hub (joined from LinkSpin), one with a wallet
|
||||
const a = (await call('/v1/join', { email: 'ann@example.com', username: 'annls' })).body.person;
|
||||
const b = (await call('/v1/join', { email: 'ben@example.com', username: 'benls' })).body.person;
|
||||
const c = (await call('/v1/join', { email: 'cat@example.com', username: 'catls' })).body.person;
|
||||
const W = '0x' + '7'.repeat(40);
|
||||
const wr = await call('/v1/wallet', { email: 'cat@example.com', wallet: W });
|
||||
ok(a && a.id && b && b.id && c && c.id && wr.status === 200, 'the hub is up with three LinkSpin members (one with a wallet)', JSON.stringify(wr.body).slice(0, 160));
|
||||
|
||||
process.env.HUB_URL = HUB; process.env.HUB_SECRET = KEY; process.env.HUB_SITE = 'linkspin'; process.env.HUB_SSO = ''; process.env.HUB_ACTIVITY = '';
|
||||
const nsso = require(path.join(HERE, 'networksso.js'));
|
||||
const sessions = { 'tok-ann': { email: 'ann@example.com' }, 'tok-ben': { email: 'ben@example.com' } };
|
||||
nsso.init({ self: 'linkspin', peer: 'iap', peerBase: () => 'http://127.0.0.1:1', isProd: false, dataDir: TMP, db: null, defaultPath: '/ads',
|
||||
member: async req => { const m = /sid=([^;]+)/.exec(req.headers.cookie || ''); return m ? sessions[m[1]] || null : null; } });
|
||||
const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36';
|
||||
const req = (url, sid, h) => ({ method: 'GET', url, headers: Object.assign({ 'user-agent': UA, 'sec-fetch-dest': 'document', 'sec-fetch-mode': 'navigate' }, sid ? { cookie: 'sid=' + sid } : {}, h || {}) });
|
||||
const res = () => ({ writeHead() { this.redirected = true; }, end() {} });
|
||||
const load = async (url, sid, h) => { const r = res(); const answered = await nsso.page(req(url, sid, h), r, new URL(url, 'http://x')); return answered || !!r.redirected; };
|
||||
|
||||
// 1. a signed-in page load records 'linkspin'
|
||||
ok((await lsAt(a.id)) === null, 'before: ann has no LinkSpin activity on the hub');
|
||||
ok((await load('/links', 'tok-ann')) === false, 'the page load is served normally (no redirect with the hub sign-in off)');
|
||||
await sleep(500);
|
||||
const r1 = await lsAt(a.id);
|
||||
ok(r1 && r1.lastKind === 'visit' && Date.now() - r1.lastAt < 10000, 'a signed-in LinkSpin page load records site linkspin on the hub', JSON.stringify(r1));
|
||||
// 2. once a day
|
||||
ok(nsso._pinged.has('ann@example.com'), 'ann is marked pinged for today');
|
||||
await load('/ads', 'tok-ann'); await sleep(300);
|
||||
ok((await lsAt(a.id)).lastAt === r1.lastAt, 'a second page load the same day sends nothing more');
|
||||
// 3. never for API calls, assets, bots or signed-out loads
|
||||
await load('/api/me', 'tok-ben'); await load('/assets/site.css', 'tok-ben'); await load('/links', 'tok-ben', { 'user-agent': 'curl/8.0' });
|
||||
await load('/links', 'tok-ben', { 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors' }); await load('/links', null); await sleep(400);
|
||||
ok((await lsAt(b.id)) === null && !nsso._pinged.has('ben@example.com'), 'API calls, assets, bots, fetches and signed-out loads never ping');
|
||||
// 4. seen(): /api/me and the heartbeat (no Sec-Fetch headers needed), the admin portal, a wallet-only session
|
||||
ok(nsso.seen({ email: 'Ben@Example.com' }) === true, 'seen() (the /api/me and /api/my/ping hook) takes a signed-in session');
|
||||
ok(nsso.seen({ address: W }) === true && nsso.seen(null) === false && nsso.seen({}) === false, 'seen(): a wallet-only session pings by wallet; nobody signed in pings nothing');
|
||||
await sleep(600);
|
||||
const rb = await lsAt(b.id), rc = await lsAt(c.id);
|
||||
ok(rb && rb.lastKind === 'visit', 'a Control Room tab kept open (no page load) still records the day on the hub', JSON.stringify(rb));
|
||||
ok(rc && rc.lastKind === 'visit', 'a wallet-only session records the day for the person who owns the wallet', JSON.stringify(rc));
|
||||
const n = nsso._pinged.size; nsso.seen({ email: 'ben@example.com' }); ok(nsso._pinged.size === n, 'seen() keeps the once-a-day rule');
|
||||
const srv = fs.readFileSync(path.join(HERE, 'server.js'), 'utf8');
|
||||
ok(/networksso\.seen\(\{ email: s\.email \|\| \(acct && acct\.email\)/.test(srv) && /touchSeen\(s\.email\)\.catch\(\(\) => \{\}\); networksso\.seen\(s\)/.test(srv) && /adminFromRequest\(req\); if \(adm && adm\.email\) networksso\.seen/.test(srv), 'server.js calls seen() from /api/me, the dashboard heartbeat and the admin portal');
|
||||
} catch (e) { ok(false, 'test crashed', String(e && e.stack || e).slice(0, 400)); }
|
||||
if (fails) console.log('hub log:\n' + hubLog.slice(-1500));
|
||||
console.log(fails ? fails + ' failed' : 'all passed');
|
||||
done(fails ? 1 : 0);
|
||||
@@ -71,12 +71,14 @@ elif [ "$MODE" = "sso" ]; then
|
||||
node qa/networksso.e2e.mjs || status=1
|
||||
node qa/networksso-partner.e2e.mjs || status=1 # a partner wallet site (5xYourTeam pattern) through this site: signed in -> straight back; signed out -> sign-in, login ad, Continue -> back; the login-ad clock
|
||||
node qa/networksso-hub.e2e.mjs || status=1 # the network hub as the sign-in provider: push, hub sign-in on another site, wallet partner, sign out everywhere, blocked, replay (skips without ../../network-hub)
|
||||
node qa/networksso-activity.test.mjs || status=1 # the hub activity ping: a signed-in page load, /api/me + heartbeat + admin portal (seen), once a day, never API/bots (real hub, skips without ../../network-hub)
|
||||
elif [ "$MODE" = "member" ]; then
|
||||
start_local 8796 && { LOCAL=http://127.0.0.1:8796 node qa/walk.mjs member || status=1; LOCAL=http://127.0.0.1:8796 node qa/member-extra.mjs || status=1; SUGGEST_SEND=0 LOCAL=http://127.0.0.1:8796 node qa/support-suggest.mjs || status=1; }; stop_local 8796
|
||||
node qa/networksso.test.cjs || status=1 # network sign-in with the other site: tokens, replay, open redirects, loop guard
|
||||
node qa/networksso.e2e.mjs || status=1 # both servers locally, a real browser across them (skips if the other repo is not beside this one)
|
||||
node qa/networksso-partner.e2e.mjs || status=1 # a partner wallet site (5xYourTeam pattern) through this site: signed in -> straight back; signed out -> sign-in, login ad, Continue -> back; the login-ad clock
|
||||
node qa/networksso-hub.e2e.mjs || status=1 # the network hub as the sign-in provider: push, hub sign-in on another site, wallet partner, sign out everywhere, blocked, replay (skips without ../../network-hub)
|
||||
node qa/networksso-activity.test.mjs || status=1 # the hub activity ping: a signed-in page load, /api/me + heartbeat + admin portal (seen), once a day, never API/bots (real hub, skips without ../../network-hub)
|
||||
node qa/tank-hold.test.mjs || status=1
|
||||
node qa/profile-policy.test.cjs || status=1
|
||||
node qa/netconv.test.mjs || status=1
|
||||
|
||||
@@ -2127,6 +2127,7 @@ const server = http.createServer(async (req, res) => {
|
||||
if (!s) return json(res, 200, { signedIn: false });
|
||||
const memberId = await auth.refreshMemberId(s);
|
||||
let acct = (s.email && await accounts.byEmail(s.email)) || (s.address && await accounts.byAddress(s.address)) || null;
|
||||
networksso.seen({ email: s.email || (acct && acct.email) || null, address: s.address || null }); // the hub's daily activity (DownlineHydra "Wake it"), once a day
|
||||
// Who the member sees as their sponsor (2026-11-02, Orlando saw a stranger): a member who is on the chain shows the sponsor the
|
||||
// contract bound, never the referral cookie from the last link they clicked; the cookie only speaks for accounts not on chain yet.
|
||||
let spdMe = await sponsorByChain(acct && acct.memberId); if (!spdMe) spdMe = await resolveSponsorDetailed((acct && acct.sponsorRef) || (!(acct && Number(acct.memberId) > 0) ? parseCookies(req)['iap.sponsor'] : '')); let sponsorId = spdMe.id;
|
||||
@@ -3580,7 +3581,7 @@ const server = http.createServer(async (req, res) => {
|
||||
if (p === '/api/my/ping' && req.method === 'GET') {
|
||||
const s = await auth.fromRequest(req);
|
||||
if (!s || !s.email) return json(res, 200, { ok: true, chatUnread: 0 });
|
||||
accounts.touchSeen(s.email).catch(() => {});
|
||||
accounts.touchSeen(s.email).catch(() => {}); networksso.seen(s); // a tab kept open: still one hub activity ping a day
|
||||
return json(res, 200, { ok: true, chatUnread: await messages.chatUnread(s.email) });
|
||||
}
|
||||
// training center content (admin-curated via data/training.json)
|
||||
@@ -4559,7 +4560,7 @@ const server = http.createServer(async (req, res) => {
|
||||
if (p === '/help') return sendFile(res, path.join(PUBLIC_DIR, 'help.html')); // Control Room: Help, the member's support tickets (2026-10-16)
|
||||
if (p === '/support' || /^\/support\/t\/[A-Za-z0-9_.-]{20,80}$/.test(p)) return sendFile(res, path.join(PUBLIC_DIR, 'support.html')); // public form + private ticket link, open past the curtain
|
||||
if (p === '/join') return serveJoinPage(res, '', '', null, []); // bare join: sponsor from the cookie if any (home-page CTAs)
|
||||
if (p === '/admin') return sendFile(res, path.join(PUBLIC_DIR, 'admin.html'));
|
||||
if (p === '/admin') { const adm = adminFromRequest(req); if (adm && adm.email) networksso.seen({ email: adm.email }); return sendFile(res, path.join(PUBLIC_DIR, 'admin.html')); } // the owner working in the admin portal is using LinkSpin too (hub activity only; the admin session is never shared)
|
||||
if (p === '/shorts') return sendFile(res, path.join(PUBLIC_DIR, 'shorts.html'));
|
||||
if (p === '/plays') return sendFile(res, path.join(PUBLIC_DIR, 'plays.html'));
|
||||
if (p === '/partners') return sendFile(res, path.join(PUBLIC_DIR, 'partners.html')); // site-owner kit (Marty, 2026-09-12)
|
||||
|
||||
Reference in New Issue
Block a user