From 7b2c4626ae67f9d337d285bdd9170f511a9c14aa Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 17 Nov 2026 13:14:03 -0700 Subject: People search looks among the people you follow first. "derek ross leaked his key and started a new npub. i tried searching him up and found this … it says no posts" … "Did we get our search to bring up his new account … as the top result?" (Adam, 2026-11-17). Search for "derek ross" came up with an empty impostor key: Primal's user search (our main source) doesn't index his new key yet and ranks by its own trust score, and only one NIP-50 relay has it, 34th. Adam already follows the new key. Now a follow whose name or NIP-05 matches the query ranks with coinos usernames, above the indexes; the chat feature hands its follow list and the profiles it holds to the search, and fetches follows' profiles it has never seen once a session, the first time a search asks. Rows found while those are still loading aren't cached, so the next search sees them; older cached results are dropped (search cache v3). New search-follows-test (follow first, impostor still listed after, renamed old key not matched, NIP-05 match, partial answers not cached) passes, with search-scope, search-avatar-loading and features-smoke. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VMan6SwkivduFDDkMmnXjZ --- tools/search-follows-test.js | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tools/search-follows-test.js (limited to 'tools') diff --git a/tools/search-follows-test.js b/tools/search-follows-test.js new file mode 100644 index 0000000..c0d8673 --- /dev/null +++ b/tools/search-follows-test.js @@ -0,0 +1,53 @@ +// People search finds the people you follow first (Adam, 2026-11-17: Derek +// Ross moved to a new npub after his key leaked; searching "derek ross" came +// up with an empty impostor, because Primal doesn't index the new key yet +// and ranks by its own trust score). A follow whose name or NIP-05 matches +// outranks the search indexes; while follows' names are still loading, the +// answer isn't cached. Run: bun tools/search-follows-test.js +globalThis.localStorage = { getItem: () => null, setItem() {}, removeItem() {} }; +const NEW = '6e479b7a5671f58a7a5d04ecedb00c1345b8918a8f8e270dc807ddb2818dba28'; +const OLD = '3f770d65d3a764a9c5cb503ae123e62ec7598ad035d836e2a810f3877a745b24'; +const FAKE = '1419ab45e0bdf22b51aeb0ddf2435b568e530b8ecf6f6f82172b181302f076ee'; +// Primal's answer for "derekross": the impostor first +class FakeWS { + constructor() { this.readyState = 0; setTimeout(() => { this.readyState = 1; this._open?.(); }, 5); } + addEventListener(t, f) { if (t === 'open') this._open = f; } + send(raw) { + const [, sid, { cache: [, args] }] = JSON.parse(raw); + const evs = args.query === 'derekross' ? [{ kind: 0, pubkey: FAKE, content: JSON.stringify({ name: 'Derek Ross' }) }] : []; + setTimeout(() => { for (const e of evs) this.onmessage({ data: JSON.stringify(['EVENT', sid, e]) }); this.onmessage({ data: JSON.stringify(['EOSE', sid]) }); }, 5); + } + close() {} +} +globalThis.WebSocket = FakeWS; +globalThis.fetch = async () => ({ json: async () => ({ results: [] }) }); +const { searchRecipients, setLocalPeople } = await import('../src/recipient-search.js'); + +let fails = 0; +const check = (name, ok, extra = '') => { console.log(`${ok ? ' ✓' : ' ✗'} ${name}${extra ? ' — ' + extra : ''}`); if (!ok) fails++; }; + +let partial = true; +setLocalPeople(() => { + const out = [ + { pk: NEW, name: 'Derek Ross', nip05: '_@derekross.me' }, + { pk: OLD, name: 'nobody' }, + { pk: 'a'.repeat(64), name: 'Someone Else' }, + ]; + out.partial = partial; + return out; +}); +let rows = await searchRecipients('derek ross'); +check('a follow named Derek Ross comes first', rows[0]?.pk === NEW, rows.map((r) => r.pk.slice(0, 8)).join(',')); +check('the index result still listed after it', rows.some((r) => r.pk === FAKE)); +check('the renamed old key is not a match', !rows.some((r) => r.pk === OLD)); +partial = false; +setLocalPeople(() => [{ pk: NEW, name: 'Derek Ross (new)', nip05: '_@derekross.me' }]); +rows = await searchRecipients('derek ross'); +check('a partial answer was not cached (asks again)', rows[0]?.name === 'Derek Ross (new)', rows[0]?.name); +rows = await searchRecipients('derekross.me'); +check('NIP-05 matches too', rows[0]?.pk === NEW); +setLocalPeople(() => []); +rows = await searchRecipients('derek ross'); +check('a complete answer is cached', rows[0]?.pk === NEW); +console.log(fails ? 'FAIL' : 'PASS'); +process.exit(fails ? 1 : 0); -- cgit v1.2.3