diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/poll-test.js | 2 | ||||
| -rw-r--r-- | tools/topic-depth-test.js | 36 |
2 files changed, 37 insertions, 1 deletions
diff --git a/tools/poll-test.js b/tools/poll-test.js index e9cb0d6..b88a4db 100644 --- a/tools/poll-test.js +++ b/tools/poll-test.js @@ -15,7 +15,7 @@ const check = (n, c, d = '') => { console.log(` ${c ? '✓' : '✗'} ${n}${d ? ' const POLL_ID = '000002f7c6a38223a9843d6e93ce8c15a3048bc95003690d74341cf9de372bfc'; const pool = new SimplePool(); -const [poll] = await pool.querySync(['wss://relay.coinos.io', 'wss://relay.damus.io', 'wss://nos.lol', 'wss://relay.primal.net'], { ids: [POLL_ID] }, { maxWait: 6000 }); +const [poll] = await pool.querySync(['wss://relay.coinos.io', 'wss://relay.damus.io', 'wss://nos.lol', 'wss://relay.primal.net', 'wss://relay.ditto.pub', 'wss://relay.nostrplebs.com'], { ids: [POLL_ID] }, { maxWait: 6000 }); if (!poll) { console.log(' ✗ the poll is not on the relays'); process.exit(1); } const labels = poll.tags.filter((x) => x[0] === 'option').map((x) => x[2]); diff --git a/tools/topic-depth-test.js b/tools/topic-depth-test.js new file mode 100644 index 0000000..9876224 --- /dev/null +++ b/tools/topic-depth-test.js @@ -0,0 +1,36 @@ +// A topic feed (#gardenstr) goes back as far as the relays remember: the +// big relays prune, so topics also ask archive-keeping ones, and a page +// whose posts were all filtered out (replies, muted, spam) is not the end. +// Before: ~5 posts, then "You're all caught up". +// +// Run: bun tools/topic-depth-test.js +import puppeteer from 'puppeteer-core'; +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 html = await buildHtml({ minify: true, pwa: false }); +const server = Bun.serve({ port: 5285, fetch: () => new Response(html, { headers: { 'content-type': 'text/html' } }) }); +const browser = await puppeteer.launch({ executablePath: '/usr/bin/google-chrome', headless: 'new', args: ['--no-sandbox'] }); +const page = await browser.newPage(); +try { + await page.setViewport({ width: 390, height: 844 }); + await page.goto('http://localhost:5285/feed/t/gardenstr', { waitUntil: 'domcontentloaded' }); + const count = () => page.evaluate(() => new Set([...document.querySelectorAll('.notes-feed [data-key]')].map((n) => n.getAttribute('data-key'))).size); + for (let i = 0; i < 60 && (await count()) < 3; i++) await sleep(500); + const first = await count(); + check('the topic opens with posts', first >= 3, first + ' posts'); + let seen = new Set(), ended = false; + const t0 = Date.now(); + while (Date.now() - t0 < 90_000 && seen.size < 60) { + for (const k of await page.evaluate(() => [...document.querySelectorAll('.notes-feed [data-key]')].map((n) => n.getAttribute('data-key')))) seen.add(k); + ended = await page.evaluate(() => document.body.innerText.includes('all caught up')); + if (ended) break; + await page.evaluate(() => window.scrollTo(0, document.documentElement.scrollHeight)); + await sleep(1500); + } + check('scrolling keeps finding older posts', seen.size >= 40, seen.size + ' posts' + (ended ? ', then "caught up"' : '')); + check('...without claiming to be caught up after a handful', !ended || seen.size >= 40); +} finally { await browser.close(); server.stop(true); } +console.log(ok ? '\n✅ a topic goes back' : '\n❌ failed'); +process.exit(ok ? 0 : 1); |
