diff options
| author | Adam Soltys <[email protected]> | 2026-10-10 07:45:07 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-10-10 07:45:07 -0700 |
| commit | 9abd654e8ef57de59a4f4bd5cbfbba560ed7e523 (patch) | |
| tree | 364dfe926baef25784c68a3c8af632ba789755e6 /tools | |
| parent | 79b09acc3c4c471fb29bb8d6994c26e849b90bb9 (diff) | |
| download | coinosv3-9abd654e8ef57de59a4f4bd5cbfbba560ed7e523.tar.gz coinosv3-9abd654e8ef57de59a4f4bd5cbfbba560ed7e523.zip | |
Feed: reposts. Amethyst showed Zapstore's repost of LWB's "Tankful" post in Adam's follows; we showed nothing ā a feed asked only for posts (kinds 1, 1068). A feed of people now asks for their reposts too (NIP-18 kind 6; topic and firehose asks stay posts-only), and a repost shows as the note itself, under "š <name> reposted" ā its reactions, zaps, ⯠and thread are the note's. Only reposts that carry the note and whose copy checks out (kind 1/1068, the id the e tag names, a valid signature); a muted author's note stays out. A note shows once: as itself, or under the first repost of it to arrive, counting rows still warming at the door. Media grids skip reposts. tools/feed-repost-test.js
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vps2H27rhbG9ZqseGfMrc3
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/feed-repost-test.js | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tools/feed-repost-test.js b/tools/feed-repost-test.js new file mode 100644 index 0000000..7bc43aa --- /dev/null +++ b/tools/feed-repost-test.js @@ -0,0 +1,76 @@ +// Reposts in a feed: someone you follow reposting a note (NIP-18 kind 6, +// the note embedded) shows the note under "<name> reposted" ā Amethyst +// showed Zapstore's repost of LWB's post, we showed nothing. A repost whose +// copy doesn't check out is left out, and a note already in the feed isn't +// shown twice. +// Run: bun tools/feed-repost-test.js +import puppeteer from './puppeteer.js'; +import { cacheKeyFor } from '../src/wallet.js'; +import { generateSecretKey, getPublicKey, finalizeEvent } from 'nostr-tools/pure'; +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 key = () => { const sk = generateSecretKey(); return { sk, pk: getPublicKey(sk) }; }; +const ZAPSTORE = key(), LWB = key(), OTHER = key(); +const now = Math.floor(Date.now() / 1000); +const note = (who, content, ago) => finalizeEvent({ kind: 1, created_at: now - ago, tags: [], content }, who.sk); +const repost = (who, ev, ago, content = JSON.stringify(ev)) => finalizeEvent({ kind: 6, created_at: now - ago, tags: [['e', ev.id, '', 'mention'], ['p', ev.pubkey]], content }, who.sk); +const TANKFUL = note(LWB, 'Tankful is a vehicle logbook that stays on your phone', 900); +const FORGED = { ...note(OTHER, 'the real words', 950) }; +const forgedCopy = JSON.stringify({ ...FORGED, content: 'words swapped after signing' }); +const OWN = note(ZAPSTORE, 'zapstore says hello itself', 300); +const POSTS = [ + OWN, + repost(ZAPSTORE, TANKFUL, 200), + repost(ZAPSTORE, FORGED, 250, forgedCopy), + repost(ZAPSTORE, OWN, 100), // its own note, already in the feed +]; +const html = await buildHtml({ minify: true, pwa: false }); +const server = Bun.serve({ port: 5316, fetch: (req) => { const p = new URL(req.url).pathname; if (p === '/verify-worker.js' || p.startsWith('/punks')) return new Response(Bun.file('dist' + p)); return 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(); +await page.evaluateOnNewDocument((fx) => { + const Real = window.WebSocket; + const fits = (ev, f) => (!f.kinds || f.kinds.includes(ev.kind)) && (!f.authors || f.authors.includes(ev.pubkey)) && (!f.ids || f.ids.includes(ev.id)); + window.WebSocket = function (...a) { const ws = new Real(...a); const send = ws.send.bind(ws); ws.send = (d) => { try { const m = JSON.parse(d); if (m[0] === 'REQ') { const fs = m.slice(2); setTimeout(() => { if (window.__live) for (const ev of fx.filter((e) => fs.some((f) => fits(e, f)))) ws.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(['EVENT', m[1], ev]) })); ws.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(['EOSE', m[1]]) })); }, 0); return; } if (m[0] === 'EVENT') return; } catch {} return send(d); }; return ws; }; + window.WebSocket.prototype = Real.prototype; Object.assign(window.WebSocket, Real); +}, POSTS); +const errs = []; +page.on('pageerror', (e) => errs.push(String(e))); +const click = (t) => page.evaluate((x) => { const e = [...document.querySelectorAll('button')].find((n) => n.textContent.trim().toLowerCase().includes(x)); if (e) { e.click(); return true; } return false; }, t); +const text = () => page.evaluate(() => document.body.innerText); +const waitText = async (x, ms = 25000) => { for (let i = 0; i < ms / 250; i++) { if ((await text()).toLowerCase().includes(x.toLowerCase())) return true; await sleep(250); } return false; }; +try { + await page.setViewport({ width: 390, height: 844 }); + await page.goto('http://localhost:5316/', { waitUntil: 'domcontentloaded' }); + await page.evaluate(() => localStorage.setItem('btc-wallet-network', 'regtest')); + await page.reload({ waitUntil: 'domcontentloaded' }); await sleep(400); + await click('create a new wallet'); await sleep(600); + await page.waitForSelector('.words .w .t'); + const mn = (await page.$$eval('.words .w .t', (l) => l.map((e) => e.textContent.trim()))).join(' '); + await click('skip verification'); + await waitText('receive', 20000); + const base = cacheKeyFor(mn + '\n'); + await page.evaluate(([k, z, l, o]) => { + localStorage.setItem(k + ':follows', JSON.stringify({ tags: [['p', z]], c: '', at: Math.floor(Date.now() / 1000) })); + localStorage.setItem(k + ':profiles', JSON.stringify({ [z]: { name: 'Zapstore', t: Date.now() }, [l]: { name: 'LWB', t: Date.now() }, [o]: { name: 'Other', t: Date.now() } })); + localStorage.setItem('btc-wallet-feed:' + k, 'following'); + }, [base, ZAPSTORE.pk, LWB.pk, OTHER.pk]); + await page.evaluateOnNewDocument(() => { window.__live = true; }); + await page.reload({ waitUntil: 'domcontentloaded' }); + await waitText('receive', 20000); + await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Feed"]')?.click()); + check('the reposted note shows', await waitText('Tankful is a vehicle logbook', 30000)); + const row = await page.evaluate(() => { const r = [...document.querySelectorAll('[data-zap-post]')].find((n) => n.textContent.includes('Tankful')); return r && { text: r.innerText, post: r.getAttribute('data-zap-post') }; }); + check('...under "Zapstore reposted", as LWB\'s post', !!row && /Zapstore reposted/.test(row.text) && /LWB/.test(row.text) && row.post === TANKFUL.id, JSON.stringify(row)); + await sleep(1500); + const t = await text(); + check('a repost whose copy was tampered with is left out', !t.includes('words swapped') && !t.includes('the real words')); + check('a note already in the feed isn\'t shown again for its repost', (t.match(/zapstore says hello itself/g) || []).length === 1); + await page.evaluate(() => [...document.querySelectorAll('[data-zap-post]')].find((n) => n.textContent.includes('Tankful')).querySelector('.note-text, .note-content').click()); + check('a tap opens the reposted note\'s thread', await page.evaluate(async () => { for (let i = 0; i < 20; i++) { if (location.pathname.includes('nevent') || document.querySelector('.thread-reply-send, .thread-view')) return true; await new Promise((r) => setTimeout(r, 200)); } return false; })); + check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | ')); +} finally { await browser.close(); server.stop(true); } +console.log(ok ? '\nā
reposts show in the feed' : '\nā failed'); +process.exit(ok ? 0 : 1); |
