1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
// A profile's older posts, page after page, with no months skipped. Relays
// hold different parts of an author's history: paging "older than the oldest
// post on the page" jumped from late September to April on Ben Arc's profile
// because one relay held six stray copies reaching back that far, and the
// posts around his Napstr launch (2026-08-21) are on none of the relays we
// ask — only in Primal's cache. Reads real relays (relays: 'read'; nothing
// is published).
// Run: bun tools/profile-depth-test.js
import puppeteer from './puppeteer.js';
import { buildHtml } from '../build.js';
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
let ok = true;
const check = (n, c, d = '') => { console.log(` ${c ? '✓' : '✗'} ${n}${d ? ' — ' + d : ''}`); if (!c) ok = false; };
const NPUB = process.env.NPUB || 'npub1c878wu04lfqcl5avfy3p5x83ndpvedaxv0dg7pxthakq3jqdyzcs2n8avm';
const WANT = process.env.WANT || 'For all the seeders out there';
const html = await buildHtml({ minify: true, pwa: false });
const server = Bun.serve({ port: 0, fetch: () => new Response(html, { headers: { 'content-type': 'text/html' } }) });
const browser = await puppeteer.launch({ relays: 'read', executablePath: '/usr/bin/google-chrome', headless: 'new', args: ['--no-sandbox'] });
const page = await browser.newPage();
const errs = [];
page.on('pageerror', (e) => errs.push(String(e.stack || e).slice(0, 600)));
try {
await page.setViewport({ width: 390, height: 844 });
await page.goto(server.url.href + NPUB, { waitUntil: 'domcontentloaded' });
await page.waitForSelector('.notes-feed:not(.note-ghosts) > [data-key]', { timeout: 20000 });
const seen = new Map(); // key -> text
let found = false, still = 0, last = 0;
const t0 = Date.now();
for (let i = 0; i < 400 && !found && still < 40; i++) {
const rows = await page.evaluate(() => [...document.querySelectorAll('.notes-feed > [data-key]')].map((r) => [r.dataset.key, r.textContent.slice(0, 300)]));
for (const [k, t] of rows) seen.set(k, t);
found = [...seen.values()].some((t) => t.includes(WANT));
still = seen.size === last ? still + 1 : 0;
last = seen.size;
await page.evaluate(() => window.scrollBy(0, 1400));
await sleep(350);
}
console.log(` ${seen.size} posts read in ${((Date.now() - t0) / 1000).toFixed(1)} s`);
check('scrolling back reaches the Napstr launch post', found, WANT);
check('...past more than a first page', seen.size > 40, seen.size + ' posts');
check('no page errors', !errs.length, errs.join(' | '));
} catch (e) { console.error(e); ok = false; } finally { await browser.close(); server.stop(); }
console.log(ok ? '\nPASS' : '\nFAIL');
process.exit(ok ? 0 : 1);
|