Something went wrong. Try again.
A live media wall for your Bluesky follows
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338import assert from 'node:assert/strict';import { test } from 'node:test';import type { Agent, AppBskyActorDefs, ModerationOpts } from '@atproto/api';import { PROFILE_CONTEXT, buildProfileCard, createProfileStore, profileFromUrl, profileUrl} from './profiles.js';
void test('profile URLs round-trip DIDs and preserve unrelated query parameters and hashes', () => { const home = new URL('https://example.com/?theme=dark#wall'); for (const did of ['did:plc:author', 'did:web:example.com%3A8443:user']) { const opened = profileUrl(home, did); assert.equal(profileFromUrl(opened), did); assert.equal(opened.searchParams.get('theme'), 'dark'); assert.equal(opened.hash, '#wall'); assert.equal(profileUrl(opened, '').href, home.href); assert.equal(home.searchParams.has('profile'), false); }});
void test('profile URLs reject malformed actors and can be replayed for history or reload', () => { for (const value of ['', 'author.test', 'javascript:alert(1)', 'did:plc:a/b', 'did:plc:a b']) { const url = new URL('https://example.com/'); url.searchParams.set('profile', value); assert.equal(profileFromUrl(url), ''); assert.equal(profileUrl(url, value).searchParams.has('profile'), false); } const home = new URL('https://example.com/'); const first = profileUrl(home, 'did:plc:first'); const second = profileUrl(first, 'did:plc:second'); assert.deepEqual( [home, first, second, first, home].map((url) => profileFromUrl(new URL(url.href))), ['', 'did:plc:first', 'did:plc:second', 'did:plc:first', ''] );});
const actor = 'did:plc:author';const moderation: ModerationOpts = { userDid: 'did:plc:viewer', prefs: { adultContentEnabled: false, labels: {}, labelers: [], mutedWords: [], hiddenPosts: [] }};
function profile(did = actor): AppBskyActorDefs.ProfileViewDetailed { return { did, handle: 'author.test', displayName: 'Author', pronouns: 'they/them', description: 'Biography', avatar: 'https://example.com/avatar', banner: 'https://example.com/banner', links: [ { uri: `at://${did}/app.bsky.actor.link/one`, cid: 'cid', url: 'https://example.com/site', title: 'Site' } ] };}
function fixture() { const calls: string[] = []; let policy: ModerationOpts | undefined = moderation; let fetch = async (did: string) => profile(did); const agent = { async getProfile(params) { assert.ok(params); calls.push(params.actor); return { success: true, headers: {}, data: await fetch(params.actor) }; } } satisfies Pick<Agent, 'getProfile'>; return { store: createProfileStore(agent, () => policy), calls, policy(value: ModerationOpts | undefined) { policy = value; }, fetch(value: typeof fetch) { fetch = value; } };}
void test('profile model preserves SDK link fields, text and raw label values and sources', () => { assert.equal(typeof PROFILE_CONTEXT, 'symbol'); const raw = profile(); raw.viewer = { following: 'at://did:plc:viewer/app.bsky.graph.follow/author' }; raw.labels = [{ val: 'unknown-label', src: actor, uri: actor, cts: '2026-01-01T00:00:00Z' }]; const card = buildProfileCard(raw, moderation); assert.equal(card.restricted, false); assert.equal(card.following, raw.viewer.following); for (const key of [ 'did', 'handle', 'displayName', 'pronouns', 'description', 'avatar', 'banner' ] as const) assert.equal(card[key], raw[key]); assert.deepEqual(card.links, [{ url: 'https://example.com/site', title: 'Site' }]); assert.deepEqual(card.labels, [{ value: 'unknown-label', source: actor }]);});
void test('URL sanitization rejects unsafe schemes and credentials, allows HTTP links and falls back to website', () => { const raw = profile(); raw.avatar = 'http://example.com/avatar'; raw.banner = 'https://user:password@example.com/banner'; raw.website = 'https://example.com/fallback'; raw.links = [ 'javascript:alert(1)', 'data:text/plain,test', '/relative', 'https://user@example.com', 'http://example.com/link' ].map((url) => ({ uri: 'at://link', cid: 'cid', url })); const card = buildProfileCard(raw, moderation); assert.equal(card.avatar, undefined); assert.equal(card.banner, undefined); assert.deepEqual(card.links, [ { url: 'http://example.com/link', title: 'http://example.com/link' } ]); raw.links.pop(); assert.deepEqual(buildProfileCard(raw, moderation).links, [ { url: raw.website, title: raw.website } ]); raw.website = 'javascript:alert(1)'; assert.deepEqual(buildProfileCard(raw, moderation).links, []);});
function assertRestricted(card: ReturnType<typeof buildProfileCard>) { assert.equal(card.restricted, true); for (const key of [ 'displayName', 'pronouns', 'description', 'avatar', 'banner', 'following' ] as const) assert.equal(card[key], undefined); assert.deepEqual(card.links, []);}
void test('undefined moderation and every account mute/block relationship fail closed', () => { assertRestricted(buildProfileCard(profile(), undefined)); const list = { uri: 'at://list', cid: 'cid', name: 'List', purpose: 'app.bsky.graph.defs#modlist', indexedAt: '2026-01-01T00:00:00Z' }; for (const viewer of [ { muted: true }, { blocking: 'at://block' }, { blockedBy: true }, { mutedByList: list }, { blockingByList: list } ]) { assertRestricted(buildProfileCard({ ...profile(), viewer }, moderation)); }});
void test('SDK moderation hides profile views, avatar/banner and display names', () => { const raw = profile(); const label = { val: '!hide', src: 'did:plc:labeler', uri: actor, cts: '2026-01-01T00:00:00Z' }; const policy = { ...moderation, prefs: { ...moderation.prefs, labelers: [{ did: label.src, labels: {} }] } }; raw.labels = [label]; assertRestricted(buildProfileCard(raw, policy)); raw.labels = [{ ...label, val: 'porn', uri: `at://${actor}/app.bsky.actor.profile/self` }]; const card = buildProfileCard(raw, policy); assert.equal(card.avatar, undefined); assert.equal(card.banner, undefined); raw.labels = [{ ...label, val: '!hide', uri: `at://${actor}/app.bsky.actor.profile/self` }]; assert.equal(buildProfileCard(raw, policy).displayName, undefined); raw.labels = [{ ...label, val: '!no-unauthenticated' }]; assertRestricted(buildProfileCard(raw, { ...policy, userDid: undefined }));});
void test('authenticated SDK calls deduplicate in-flight and re-evaluate raw cached profiles under current policy', async () => { const f = fixture(); let release!: () => void; f.fetch(async () => { await new Promise<void>((resolve) => { release = resolve; }); return profile(); }); const first = f.store.get(actor); const second = f.store.get(actor); await Promise.resolve(); assert.deepEqual(f.calls, [actor]); release(); assert.deepEqual(await first, await second); f.policy(undefined); assertRestricted(await f.store.get(actor)); f.policy(moderation); const card = await f.store.get(actor); assert.equal(card.displayName, 'Author'); card.links.length = 0; assert.equal((await f.store.get(actor)).links.length, 1); assert.equal(f.calls.length, 1);});
void test('peek synchronously remoderates cached raw profiles without fetching or exposing mutable cards', async () => { const f = fixture(); const label = { val: '!hide', src: 'did:plc:labeler', uri: actor, cts: '2026-01-01T00:00:00Z' }; f.fetch(async () => ({ ...profile(), labels: [label] })); assert.equal(f.store.peek(actor), undefined); assert.deepEqual(f.calls, []); const card = await f.store.get(actor); f.policy({ ...moderation, prefs: { ...moderation.prefs } }); assert.deepEqual(f.store.peek(actor), card); f.policy({ ...moderation, prefs: { ...moderation.prefs, labelers: [{ did: label.src, labels: {} }] } }); assertRestricted(f.store.peek(actor)!); f.policy(undefined); assertRestricted(f.store.peek(actor)!); f.policy(moderation); const restored = f.store.peek(actor)!; assert.deepEqual(restored, card); restored.links.length = 0; assert.equal(f.store.peek(actor)!.links.length, 1); assert.equal(f.store.peek('did:plc:other'), undefined); assert.deepEqual(f.calls, [actor]);});
void test('peek retains expired raw profiles during refresh and fails closed after store replacement', async (context) => { let now = 100_000; context.mock.method(Date, 'now', () => now); const a = fixture(); const b = fixture(); await a.store.get(actor); now += 60_000; let release!: () => void; a.fetch(async () => { await new Promise<void>((resolve) => { release = resolve; }); return { ...profile(), viewer: { muted: true } }; }); const refresh = a.store.get(actor); await Promise.resolve(); assert.equal(a.store.peek(actor)!.restricted, false); assert.equal(b.store.peek(actor), undefined); release(); await refresh; assertRestricted(a.store.peek(actor)!); await b.store.get(actor); assert.equal(b.store.peek(actor)!.restricted, false); a.store.close(); assert.equal(a.store.peek(actor), undefined); assert.equal(b.store.peek(actor)!.restricted, false); assert.deepEqual(a.calls, [actor, actor]); assert.deepEqual(b.calls, [actor]);});
void test('TTL is 60 seconds and cache is bounded to 100 least recently used entries', async (context) => { let now = 100_000; context.mock.method(Date, 'now', () => now); const f = fixture(); await f.store.get(actor); now += 59_999; await f.store.get(actor); assert.equal(f.calls.length, 1); now++; await f.store.get(actor); assert.equal(f.calls.length, 2); for (let i = 0; i < 99; i++) await f.store.get(`did:plc:person${i}`); await f.store.get(actor); await f.store.get('did:plc:new'); await f.store.get(actor); assert.equal(f.calls.length, 102); await f.store.get('did:plc:person0'); assert.equal(f.calls.length, 103);});
void test('invalid inputs, mismatched DIDs and failures reject without poisoning retries', async () => { const f = fixture(); await assert.rejects(f.store.get('author.test'), /DID/); assert.equal(f.calls.length, 0); f.fetch(async () => profile('did:plc:other')); await assert.rejects(f.store.get(actor), /does not match/); f.fetch(async () => { throw new Error('offline'); }); await assert.rejects(f.store.get(actor), /offline/); f.fetch(async (did) => profile(did)); assert.equal((await f.store.get(actor)).did, actor); assert.equal(f.calls.length, 3);});
void test('pending requests are bounded, deduplicated at capacity and rejected on close', async () => { const f = fixture(); let release!: () => void; const gate = new Promise<void>((resolve) => { release = resolve; }); f.fetch(async (did) => { await gate; return profile(did); }); const requests = Array.from({ length: 8 }, (_, i) => f.store.get(`did:plc:person${i}`)); requests.push(f.store.get('did:plc:person0')); const settled = Promise.allSettled(requests); await assert.rejects(f.store.get(actor), /Too many/); assert.equal(f.calls.length, 8); f.store.close(); f.store.close(); assert.ok((await settled).every((result) => result.status === 'rejected')); release(); await assert.rejects(f.store.get(actor), /closed/);});
void test('stores never share profiles between accounts and closing one leaves another usable', async () => { const a = fixture(); const b = fixture(); a.fetch(async () => ({ ...profile(), viewer: { muted: true } })); assertRestricted(await a.store.get(actor)); assert.equal((await b.store.get(actor)).restricted, false); a.store.close(); assert.equal((await b.store.get(actor)).restricted, false); assert.deepEqual(a.calls, [actor]); assert.deepEqual(b.calls, [actor]);});