import assert from 'node:assert/strict'; import { test } from 'node:test'; import { BlobRef, type AppBskyFeedDefs, type ModerationOpts } from '@atproto/api'; import { extractMedia, startFeed, type MediaItem } from './feed.js'; import type { Agent } from '@atproto/api'; import { Jetstream } from '@bsky/jetstream'; import { mediaAssetKey } from './media-identity.js'; import { openCache } from './cache.js'; import { FIREHOSE_INSTANCES, JETSTREAM_INSTANCES } from './jetstream-settings.js'; const moderation: ModerationOpts = { userDid: 'did:plc:viewer', prefs: { adultContentEnabled: false, labels: {}, labelers: [], mutedWords: [], hiddenPosts: [] } }; function fixture(): AppBskyFeedDefs.PostView { return { uri: 'at://did:plc:author/app.bsky.feed.post/example', cid: 'bafyreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku', author: { did: 'did:plc:author', handle: 'author.bsky.social' }, record: { $type: 'app.bsky.feed.post', text: 'A picture', createdAt: '2026-11-07T00:00:00Z' }, indexedAt: '2026-11-07T00:00:00Z', embed: { $type: 'app.bsky.embed.images#view', images: [0, 1].map((index) => ({ thumb: `https://example.com/thumb-${index}.jpg`, fullsize: `https://example.com/image-${index}.jpg`, alt: `Image ${index}`, aspectRatio: { width: 4, height: 3 } })) } }; } void test('each image becomes a stable, aspect-preserving tile', () => { const items = extractMedia(fixture(), moderation); assert.equal(items.length, 2); assert.notEqual(items[0].id, items[1].id); assert.equal(items[0].width / items[0].height, 4 / 3); assert.equal(items[1].alt, 'Image 1'); }); void test('author avatars accept HTTPS only and obey avatar moderation', () => { const post = fixture(); post.author.avatar = 'https://example.com/avatar.jpg'; assert.equal(extractMedia(post, moderation)[0].authorAvatar, post.author.avatar); for (const avatar of [ 'http://example.com/avatar.jpg', 'javascript:alert(1)', 'data:image/png;base64,AAAA', 'invalid' ]) { post.author.avatar = avatar; assert.equal(extractMedia(post, moderation)[0].authorAvatar, undefined); } post.author.avatar = 'https://example.com/avatar.jpg'; post.author.labels = [ { src: post.author.did, uri: post.author.did, val: 'porn', cts: post.indexedAt } ]; const items = extractMedia(post, { ...moderation, prefs: { ...moderation.prefs, labelers: [{ did: post.author.did, labels: {} }] } }); assert.ok(items.every((item) => item.authorAvatar === undefined)); }); void test('each media item carries post identity and authenticated interaction state', () => { const post = fixture(); post.author.viewer = { following: 'at://did:plc:viewer/app.bsky.graph.follow/author' }; post.viewer = { like: 'at://did:plc:viewer/app.bsky.feed.like/example', repost: 'at://did:plc:viewer/app.bsky.feed.repost/example', bookmarked: true }; for (const item of extractMedia(post, moderation)) { assert.deepEqual(item.post, { cid: post.cid, authorDid: post.author.did, authorFollowing: post.author.viewer?.following, likeUri: post.viewer.like, repostUri: post.viewer.repost, bookmarked: true }); } post.viewer = undefined; post.author.viewer = undefined; assert.deepEqual(extractMedia(post, moderation)[0].post, { cid: post.cid, authorDid: post.author.did, authorFollowing: undefined, likeUri: undefined, repostUri: undefined, bookmarked: false }); post.embed = { $type: 'app.bsky.embed.video#view', cid: post.cid, playlist: 'https://example.com/video.m3u8' }; assert.equal(extractMedia(post, moderation)[0].post?.cid, post.cid); }); void test('image fallback metadata uses original record blob CIDs rather than CDN URL parsing', () => { const post = fixture(); const image = BlobRef.fromJsonRef({ cid: post.cid, mimeType: 'image/jpeg' }); post.record = { ...(post.record as Record), embed: { $type: 'app.bsky.embed.images', images: [{ alt: 'Original', image }] } }; const items = extractMedia(post, moderation); assert.deepEqual(items[0].blob, { did: post.author.did, cid: post.cid }); assert.equal(items[1].blob, undefined); }); void test('post counts are shared across media, retaining zero and omitting missing or invalid counts', () => { const post = fixture(); assert.equal(extractMedia(post, moderation)[0].post?.counts, undefined); Object.assign(post, { likeCount: 0, repostCount: 1, replyCount: -2, quoteCount: 1.5 }); for (const item of extractMedia(post, moderation)) { assert.deepEqual(item.post?.counts, { likeCount: 0, repostCount: 1 }); } post.embed = { $type: 'app.bsky.embed.video#view', cid: post.cid, playlist: 'https://example.com/video.m3u8' }; const item = extractMedia( { ...post, replyCount: 5, quoteCount: 2, bookmarkCount: 9 }, moderation )[0]; assert.deepEqual(item.post?.counts, { likeCount: 0, repostCount: 1, replyCount: 5, quoteCount: 2, bookmarkCount: 9 }); }); void test('native video yields a playable media item', () => { const post = fixture(); post.embed = { $type: 'app.bsky.embed.video#view', cid: post.cid, playlist: 'https://example.com/video.m3u8', thumbnail: 'https://example.com/poster.jpg', aspectRatio: { width: 16, height: 9 } }; const items = extractMedia(post, moderation); assert.equal(items.length, 1); assert.equal(items[0].kind, 'video'); assert.equal(items[0].width / items[0].height, 16 / 9); }); void test('external preview thumbnails are excluded', () => { const post = fixture(); post.embed = { $type: 'app.bsky.embed.external#view', external: { uri: 'https://example.com', title: 'Link', description: '', thumb: 'https://example.com/thumb.jpg' } }; assert.deepEqual(extractMedia(post, moderation), []); }); void test('hidden and blocked posts never yield media', () => { const post = fixture(); assert.deepEqual( extractMedia(post, { ...moderation, prefs: { ...moderation.prefs, hiddenPosts: [post.uri] } }), [] ); post.author.viewer = { blocking: 'at://did:plc:viewer/app.bsky.graph.block/example' }; assert.deepEqual(extractMedia(post, moderation), []); }); void test('unsafe media URLs are excluded', () => { const post = fixture(); post.embed = { $type: 'app.bsky.embed.images#view', images: [{ thumb: 'https://example.com/thumb.jpg', fullsize: 'javascript:alert(1)', alt: '' }] }; assert.deepEqual(extractMedia(post, moderation), []); }); void test('cache fallback isolates accounts and snapshots', async () => { const cache = await openCache(); assert.equal(cache.persistent, false); assert.equal(await cache.load('alice'), null); const snapshot = { follows: ['did:plc:follow'], blocks: [], syncedAt: 1 }; await cache.save('alice', snapshot); snapshot.follows.length = 0; assert.deepEqual((await cache.load('alice'))?.follows, ['did:plc:follow']); assert.equal(await cache.load('bob'), null); await cache.close(); await assert.rejects(cache.load('alice')); }); async function until(predicate: () => boolean) { for (let attempt = 0; attempt < 100; attempt++) { if (predicate()) return; await new Promise((resolve) => setTimeout(resolve, 5)); } assert.fail('Feed did not reach expected state'); } void test('restored wall attaches hashes before emitting and waits for fresh graph and hydration', async (context) => { context.mock.method(Jetstream.prototype, 'live', async function* () {}); const cache = await openCache(); const account = moderation.userDid!; const post = fixture(); await cache.save(account, { follows: [post.author.did], blocks: [], syncedAt: Date.now() }); await cache.saveWall(account, { posts: [post], moderation, savedAt: Date.now() }); const item = extractMedia(post, moderation)[0]; await cache.saveThumbhash(account, mediaAssetKey(item), new Uint8Array([1, 2, 3, 4, 5])); let finishGraph!: (value: unknown) => void; let finishPosts!: (value: unknown) => void; const graph = new Promise((resolve) => { finishGraph = resolve; }); const posts = new Promise((resolve) => { finishPosts = resolve; }); const agent = { did: account, configureLabelers() {}, getPreferences: async () => ({ moderationPrefs: moderation.prefs }), getLabelDefinitions: async () => ({}), app: { bsky: { graph: { getFollows: () => graph, getBlocks: async () => ({ data: { blocks: [] } }) }, feed: { getPosts: () => posts, getTimeline: async () => ({ data: { feed: [] } }) } } } } as unknown as Agent; const emissions: MediaItem[][] = []; const stop = startFeed( agent, { items: (items) => emissions.push(items), status() {}, error() {}, graph() {} }, async () => cache ); try { await until(() => emissions.length > 0); assert.equal(emissions[0][0].thumbhash, 'AQIDBAU='); assert.equal(emissions[0][0].cached, true); assert.equal(emissions[0][0].liveArrival, undefined); assert.equal(emissions[0][0].provisional, true); finishPosts({ data: { posts: [post] } }); await until(() => emissions.length >= 3); assert.equal(emissions.at(-1)![0].provisional, true); finishGraph({ data: { follows: [{ did: post.author.did }] } }); await until(() => emissions.at(-1)?.[0]?.provisional === undefined); assert.equal(emissions.at(-1)![0].cached, true); assert.equal(emissions.at(-1)![0].thumbhash, 'AQIDBAU='); } finally { finishPosts({ data: { posts: [] } }); finishGraph({ data: { follows: [] } }); stop(); } }); void test('marks stream media for pacing without marking timeline history or losing provenance on updates', async (context) => { const history = fixture(); const live = { ...history, uri: history.uri.replace('/example', '/live') }; context.mock.method(Jetstream.prototype, 'live', async function* () { yield { seq: 42, did: live.author.did, kind: 'commit', commit: { collection: 'app.bsky.feed.post', rkey: 'live', operation: 'create', cid: live.cid, record: live.record } }; }); const agent = { did: moderation.userDid, configureLabelers() {}, getPreferences: async () => ({ moderationPrefs: moderation.prefs }), getLabelDefinitions: async () => ({}), app: { bsky: { graph: { getFollows: async () => ({ data: { follows: [history.author] } }), getBlocks: async () => ({ data: { blocks: [] } }) }, feed: { getPosts: async () => ({ data: { posts: [live] } }), getTimeline: async () => ({ data: { feed: [{ post: history }] } }) } } } } as unknown as Agent; let items: MediaItem[] = []; const stop = startFeed(agent, { items: (value) => { items = value; }, status() {}, error() {}, graph() {} }); try { await until(() => items.length === 4); for (const item of items) assert.equal(!!item.liveArrival, item.uri === live.uri); stop.updateSettings({ adultContent: 'account', labels: {} }); assert.equal(items.length, 4); for (const item of items) assert.equal(!!item.liveArrival, item.uri === live.uri); } finally { stop(); } }); void test('tracks all subscription recoveries and resumes a terminated stream without waiting for graph refresh', async (context) => { const post = fixture(); const dids = [ post.author.did, ...Array.from({ length: 150 }, (_, index) => `did:plc:follow${index}`) ]; const hooks: Parameters[0][] = []; const batchSizes: number[] = []; const resumes: (number | undefined)[] = []; const statuses: string[] = []; const openCounts: number[] = []; let calls = 0; context.mock.method( Jetstream.prototype, 'live', async function* (options: Parameters[0]) { const call = calls++; batchSizes.push(options.dids?.length ?? 0); resumes.push(await options.cursor!.load()); hooks[call]?.onConnect?.({} as never); if (call === 0) { yield { seq: 42, did: post.author.did, kind: 'commit', commit: { collection: 'app.bsky.feed.post', rkey: 'deleted', operation: 'delete' } }; throw new Error('terminal stream failure'); } await new Promise((resolve) => options.signal!.addEventListener('abort', () => resolve(), { once: true }) ); } ); const cache = await openCache(); const agent = { did: moderation.userDid, configureLabelers() {}, getPreferences: async () => ({ moderationPrefs: moderation.prefs }), getLabelDefinitions: async () => ({}), app: { bsky: { graph: { getFollows: async () => ({ data: { follows: dids.map((did) => ({ did })) } }), getBlocks: async () => ({ data: { blocks: [] } }) }, feed: { getPosts: async () => ({ data: { posts: [] } }), getTimeline: async () => ({ data: { feed: [] } }) } } } } as unknown as Agent; const stop = startFeed( agent, { items() {}, status: (value) => statuses.push(value), connections: (open) => openCounts.push(open), error() {}, graph() {} }, async () => cache, (options) => { hooks.push(options); return { stream: async function* () {} }; } ); try { await until(() => statuses.some((value) => value.includes('1/2 subscriptions connected'))); await new Promise((resolve) => setTimeout(resolve, 1100)); await until(() => calls === 3 && statuses.at(-1) === 'Live media feed'); assert.deepEqual(batchSizes, [150, 1, 150]); assert.equal(openCounts.at(-1), 2); assert.equal(resumes[2], 42); assert.equal(hooks[0]?.idleTimeoutMs, 300_000); hooks[1]?.onDisconnect?.(); assert.match(statuses.at(-1)!, /1\/2 subscriptions connected/); assert.equal(openCounts.at(-1), 1); hooks[2]?.onConnect?.({} as never); assert.match(statuses.at(-1)!, /1\/2 subscriptions connected/); assert.equal(openCounts.at(-1), 1); hooks[1]?.onConnect?.({} as never); assert.equal(statuses.at(-1), 'Live media feed'); assert.equal(openCounts.at(-1), 2); } finally { stop(); } assert.equal(openCounts.at(-1), 0); }); void test('changing Jetstream instances reconnects without reusing cursors or clearing the wall', async (context) => { const post = fixture(); const livePost = { ...post, uri: post.uri.replace('/example', '/live') }; const tap = FIREHOSE_INSTANCES[0].endpoint; const west = JETSTREAM_INSTANCES[1].endpoint; const custom = 'https://stream.example.com'; const tapUrls: URL[] = []; const connections: { service: string; signal: AbortSignal; cursor?: number }[] = []; context.mock.method( Jetstream.prototype, 'live', async function* (this: Jetstream, options: Parameters[0]) { connections.push({ service: this.service, signal: options.signal!, cursor: await options.cursor!.load() }); await options.cursor!.save(42); if (!options.signal!.aborted) await new Promise((resolve) => options.signal!.addEventListener('abort', () => resolve(), { once: true }) ); yield { seq: 43, did: post.author.did, kind: 'commit', commit: { collection: 'app.bsky.feed.post', rkey: 'example', operation: 'delete' } }; } ); let items: MediaItem[] = []; let historyRequests = 0; const agent = { did: moderation.userDid, configureLabelers() {}, getPreferences: async () => ({ moderationPrefs: moderation.prefs }), getLabelDefinitions: async () => ({}), app: { bsky: { graph: { getFollows: async () => ({ data: { follows: [post.author] } }), getBlocks: async () => ({ data: { blocks: [] } }) }, feed: { getPosts: async () => ({ data: { posts: [livePost] } }), getTimeline: async () => { historyRequests++; return { data: { feed: [{ post }] } }; } } } } } as unknown as Agent; const stop = startFeed( agent, { items: (value) => (items = value), status() {}, error: assert.fail, graph() {} }, undefined, () => ({ async *stream(getUrl) { tapUrls.push(new URL(getUrl())); yield JSON.stringify({ time_us: 1_800_000_000_000_000, did: post.author.did, kind: 'commit', commit: { collection: 'app.bsky.feed.post', rkey: 'live', operation: 'create', cid: post.cid, record: post.record } }); tapUrls.push(new URL(getUrl())); } }), undefined, west ); try { await until(() => connections.length === 1 && items.length === 2); stop.setJetstreamEndpoint('wss://stream.example.com/'); await until(() => connections.length === 2); assert.equal(connections[0].signal.aborted, true); assert.equal(connections[1].signal.aborted, false); assert.deepEqual( connections.map(({ service, cursor }) => [service, cursor]), [ [west, undefined], [custom, undefined] ] ); assert.equal(items.length, 2); assert.equal(historyRequests, 1); stop.setJetstreamEndpoint(custom); assert.equal(connections[1].signal.aborted, false); stop.setJetstreamEndpoint(tap); await until(() => items.some((item) => item.uri === livePost.uri)); assert.equal(connections[1].signal.aborted, true); const [initial, resume] = tapUrls; assert.equal(`${initial.origin}${initial.pathname}`, 'wss://sfo.firehose.stream/tap'); assert.deepEqual(initial.searchParams.getAll('wantedDids'), [post.author.did]); assert.deepEqual(initial.searchParams.getAll('wantedCollections'), [ 'app.bsky.feed.post', 'app.bsky.feed.repost' ]); assert.equal(initial.searchParams.get('kind'), 'commit'); assert.equal(initial.searchParams.has('cursor'), false); assert.equal(resume.searchParams.get('cursor'), '1800000000000000'); assert.equal(items.length, 4); } finally { stop(); } }); void test('local sensitive media modes respect adult gate and non-overridable restrictions', () => { const post = fixture(); post.labels = [ { src: 'did:plc:author', uri: post.uri, val: 'porn', cts: '2026-11-07T00:00:00Z' } ]; assert.deepEqual(extractMedia(post, moderation), []); assert.deepEqual( extractMedia(post, moderation, { adultContent: 'account', labels: { porn: 'show' } }), [] ); const blurred = extractMedia(post, moderation, { adultContent: 'allow', labels: { porn: 'blur' } }); assert.equal(blurred.length, 2); assert.deepEqual(blurred[0].warnings, ['porn']); assert.equal(blurred[0].sensitive, true); assert.equal( extractMedia(post, moderation, { adultContent: 'allow', labels: { porn: 'show' } })[0].warnings, undefined ); assert.equal( extractMedia(post, moderation, { adultContent: 'allow', labels: { porn: 'blur' } }, true)[0] .warnings, undefined ); assert.deepEqual( extractMedia(post, moderation, { adultContent: 'allow', labels: { porn: 'hide' } }), [] ); const settings = { adultContent: 'allow' as const, labels: { porn: 'show' as const, '!hide': 'show' as const } }; assert.deepEqual( extractMedia( post, { ...moderation, prefs: { ...moderation.prefs, hiddenPosts: [post.uri] } }, settings ), [] ); post.author.viewer = { muted: true }; assert.deepEqual(extractMedia(post, moderation, settings), []); post.author.viewer = { blocking: 'at://did:plc:viewer/app.bsky.graph.block/test' }; assert.deepEqual(extractMedia(post, moderation, settings), []); post.author.viewer = undefined; post.labels.push({ ...post.labels[0], src: 'did:plc:labeler', val: '!hide' }); assert.deepEqual( extractMedia( post, { ...moderation, prefs: { ...moderation.prefs, labelers: [{ did: 'did:plc:labeler', labels: {} }] } }, settings ), [] ); }); void test('most restrictive category wins and overrides do not mutate account preferences', () => { const post = fixture(); post.labels = ['porn', 'sexual'].map((val) => ({ src: 'did:plc:author', uri: post.uri, val, cts: '2026-11-07T00:00:00Z' })); const before = JSON.stringify(moderation); assert.deepEqual( extractMedia(post, moderation, { adultContent: 'allow', labels: { porn: 'show', sexual: 'hide' } }), [] ); assert.deepEqual( extractMedia(post, moderation, { adultContent: 'allow', labels: { porn: 'show', sexual: 'blur' } })[0].warnings, ['sexual'] ); assert.equal(JSON.stringify(moderation), before); }); void test('changing settings recovers retained hidden history and session reveals reset on policy changes', async (context) => { context.mock.method(Jetstream.prototype, 'live', async function* () {}); const post = fixture(); post.labels = [ { src: 'did:plc:author', uri: post.uri, val: 'porn', cts: '2026-11-07T00:00:00Z' } ]; const cache = await openCache(); const agent = { did: moderation.userDid, configureLabelers() {}, getPreferences: async () => ({ moderationPrefs: moderation.prefs }), getLabelDefinitions: async () => ({}), app: { bsky: { graph: { getFollows: async () => ({ data: { follows: [{ did: post.author.did }] } }), getBlocks: async () => ({ data: { blocks: [] } }) }, feed: { getPosts: async () => ({ data: { posts: [post] } }), getTimeline: async () => ({ data: { feed: [{ post }] } }) } } } } as unknown as Agent; let items: MediaItem[] = []; let loaded = false; const stop = startFeed( agent, { items: (value) => { items = value; }, status: (value) => { if ( value.startsWith('Reconnecting') || value === 'Live media feed' || value.startsWith('Follow people') ) loaded = true; }, error() {}, graph() {} }, async () => cache ); try { await until(() => loaded); assert.equal(items.length, 0); const settings = { adultContent: 'allow' as const, labels: { porn: 'blur' as const } }; stop.updateSettings(settings); assert.deepEqual(items[0].warnings, ['porn']); stop.revealPost(post.uri); assert.equal(items[0].warnings, undefined); stop.updateSettings(settings); assert.deepEqual(items[0].warnings, ['porn']); stop.updateSettings({ adultContent: 'allow', labels: { porn: 'hide' } }); assert.equal(items.length, 0); } finally { stop(); } }); void test('follow-account warning settings produce covered media rather than bypassing moderation', () => { const post = fixture(); post.labels = [ { src: 'did:plc:author', uri: post.uri, val: 'sexual', cts: '2026-11-07T00:00:00Z' } ]; const account = { ...moderation, prefs: { ...moderation.prefs, adultContentEnabled: true, labels: { sexual: 'warn' as const } } }; assert.deepEqual(extractMedia(post, account)[0].warnings, ['sexual']); assert.equal( extractMedia(post, account, { adultContent: 'account', labels: { sexual: 'show' } })[0] .warnings, undefined ); }); void test('history repost toggle retains candidates, deduplicates, moderates and avoids orphan snapshots', async (context) => { context.mock.method(Jetstream.prototype, 'live', async function* () {}); const post = fixture(); const other = { ...fixture(), uri: `${post.uri}other`, author: { did: 'did:plc:direct', handle: 'direct.test' } }; other.uri = 'at://did:plc:direct/app.bsky.feed.post/other'; other.indexedAt = '2026-11-07T01:00:00Z'; const by = { did: 'did:plc:reposter', handle: 'reposter.test' }; const reason = { $type: 'app.bsky.feed.defs#reasonRepost', by, uri: `at://${by.did}/app.bsky.feed.repost/one`, indexedAt: '2026-11-07T02:00:00Z' }; const blocked = { ...fixture(), uri: 'at://did:plc:blocked/app.bsky.feed.post/no', author: { did: 'did:plc:blocked', handle: 'blocked.test' } }; const muted = { ...fixture(), uri: `${post.uri}muted` }; const cache = await openCache(); const saved: string[][] = []; context.mock.method( cache, 'saveWall', async (_account: string, snapshot: import('./wall-snapshot.js').WallSnapshot) => { saved.push(snapshot.posts.map((value) => value.uri)); } ); let loaded = false; let items: MediaItem[] = []; const agent = { did: moderation.userDid, configureLabelers() {}, getPreferences: async () => ({ moderationPrefs: moderation.prefs }), getLabelDefinitions: async () => ({}), app: { bsky: { graph: { getFollows: async () => ({ data: { follows: [by, other.author] } }), getBlocks: async () => ({ data: { blocks: [blocked.author] } }) }, feed: { getPosts: async () => ({ data: { posts: [] } }), getTimeline: async () => ({ data: { feed: [ { post: other }, { post, reason }, { post, reason: { ...reason, uri: `${reason.uri}two` } }, { post: blocked, reason: { ...reason, uri: `${reason.uri}blocked` } }, { post: muted, reason: { ...reason, uri: `${reason.uri}muted`, by: { ...by, viewer: { muted: true } } } } ] } }) } } } } as unknown as Agent; const stop = startFeed( agent, { items: (value) => { items = value; }, status: (value) => { if ( value.startsWith('Reconnecting') || value === 'Live media feed' || value.startsWith('Follow people') ) loaded = true; }, error(error) { assert.fail(error); }, graph() {} }, async () => cache ); try { await until(() => loaded); assert.deepEqual( items.map((item) => item.uri), [other.uri, other.uri] ); stop.updateSettings({ adultContent: 'account', labels: {}, includeReposts: true }); assert.deepEqual( items.map((item) => item.uri), [post.uri, post.uri, other.uri, other.uri] ); assert.equal(items[0].sensitive, true); assert.equal(items[0].repostedBy, by.handle); stop.updateSettings({ adultContent: 'account', labels: {}, includeReposts: false }); assert.equal(items.length, 2); stop.updateSettings({ adultContent: 'account', labels: {}, includeReposts: true }); assert.equal(items.length, 4); } finally { stop(); } await until(() => saved.length > 0); assert.deepEqual(saved.at(-1), [other.uri]); }); void test('live repost create/delete handles multiple reposters, updates and hydration deletion races', async (context) => { const post = fixture(); const reposters = ['did:plc:one', 'did:plc:two']; type Event = { seq: number; did: string; kind: 'commit'; commit: Record }; const events: Event[] = []; let wake: (() => void) | undefined; let seq = 0; let loaded = false; let items: MediaItem[] = []; let requests = 0; let resolvePosts: ((value: unknown) => void) | undefined; let delay = false; context.mock.method( Jetstream.prototype, 'live', async function* (options: Parameters[0]) { assert.ok(options.collections?.includes('app.bsky.feed.repost')); while (!options.signal?.aborted) { if (events.length) yield events.shift()!; else await new Promise((resolve) => { wake = resolve; options.signal?.addEventListener('abort', () => resolve(), { once: true }); }); } } ); const cache = await openCache(); const agent = { did: moderation.userDid, configureLabelers() {}, getPreferences: async () => ({ moderationPrefs: moderation.prefs }), getLabelDefinitions: async () => ({}), app: { bsky: { graph: { getFollows: async () => ({ data: { follows: reposters.map((did) => ({ did, handle: did })) } }), getBlocks: async () => ({ data: { blocks: [] } }) }, feed: { getPosts: async () => { requests++; return delay ? new Promise((resolve) => { resolvePosts = resolve; }) : { data: { posts: [post] } }; }, getTimeline: async () => ({ data: { feed: [] } }) } } } } as unknown as Agent; const stop = startFeed( agent, { items: (value) => { items = value; }, status: (value) => { if ( value.startsWith('Reconnecting') || value === 'Live media feed' || value.startsWith('Follow people') ) loaded = true; }, error(error) { assert.fail(error); }, graph() {} }, async () => cache, () => ({ stream: async function* () {} }), { adultContent: 'account', labels: {}, includeReposts: true } ); const send = ( did: string, operation: string, record: unknown = { $type: 'app.bsky.feed.repost', subject: { uri: post.uri, cid: post.cid }, createdAt: '2026-11-07T02:00:00Z' } ) => { events.push({ seq: ++seq, did, kind: 'commit', commit: { collection: 'app.bsky.feed.repost', rkey: 'test', operation, record, cid: post.cid } }); wake?.(); }; try { await until(() => loaded); send(reposters[0], 'create'); await until(() => items.length === 2); send(reposters[1], 'create'); await until(() => requests === 2); send(reposters[0], 'delete'); await new Promise((resolve) => setTimeout(resolve, 20)); assert.equal(items.length, 2); send(reposters[1], 'update', { invalid: true }); await until(() => items.length === 0); delay = true; send(reposters[0], 'create'); await until(() => !!resolvePosts); send(reposters[0], 'delete'); await new Promise((resolve) => setTimeout(resolve, 20)); resolvePosts!({ data: { posts: [post] } }); await new Promise((resolve) => setTimeout(resolve, 20)); assert.equal(items.length, 0); } finally { stop(); } }); void test('confirmed post state and counts merge across gallery tiles and refreshes but not CIDs', async (context) => { context.mock.method(Jetstream.prototype, 'live', async function* () {}); const post = fixture(); post.author.viewer = { following: 'at://did:plc:viewer/app.bsky.graph.follow/author' }; post.viewer = { like: 'at://did:plc:viewer/app.bsky.feed.like/old', repost: 'at://did:plc:viewer/app.bsky.feed.repost/old', bookmarked: false }; Object.assign(post, { likeCount: 2, repostCount: 1, bookmarkCount: 0, replyCount: 3 }); const cache = await openCache(); const account = moderation.userDid!; await cache.save(account, { follows: [post.author.did], blocks: [], syncedAt: Date.now() }); await cache.saveWall(account, { posts: [post], moderation, savedAt: Date.now() }); let hydrate!: (value: unknown) => void; const hydration = new Promise((resolve) => { hydrate = resolve; }); let history!: (value: unknown) => void; let pages = 0; let items: MediaItem[] = []; let loaded = false; const saved: AppBskyFeedDefs.PostView[][] = []; context.mock.method( cache, 'saveWall', async (_account: string, wall: import('./wall-snapshot.js').WallSnapshot) => { saved.push(wall.posts); } ); const agent = { did: account, configureLabelers() {}, getPreferences: async () => ({ moderationPrefs: moderation.prefs }), getLabelDefinitions: async () => ({}), app: { bsky: { graph: { getFollows: async () => ({ data: { follows: [post.author] } }), getBlocks: async () => ({ data: { blocks: [] } }) }, feed: { getPosts: () => hydration, getTimeline: () => { pages++; return new Promise((resolve) => { history = resolve; }); } } } } } as unknown as Agent; const stop = startFeed( agent, { items: (value) => { items = value; }, status: (value) => { if ( value.startsWith('Reconnecting') || value === 'Live media feed' || value.startsWith('Follow people') ) loaded = true; }, error(error) { assert.fail(error); }, graph() {} }, async () => cache ); try { await until(() => items.length === 2 && pages === 1); const likeUri = 'at://did:plc:viewer/app.bsky.feed.like/confirmed'; stop.reconcileInteraction({ kind: 'post', uri: post.uri, cid: post.cid, changes: { likeUri, bookmarked: true } }); stop.reconcileInteraction({ kind: 'post', uri: post.uri, cid: post.cid, changes: { repostUri: null } }); const expected = { cid: post.cid, authorDid: post.author.did, authorFollowing: post.author.viewer?.following, likeUri, repostUri: undefined, bookmarked: true, counts: { likeCount: 2, repostCount: 0, bookmarkCount: 1, replyCount: 3 } }; assert.deepEqual( items.map((item) => item.post), [expected, expected] ); assert.equal(items[0].post, items[1].post); hydrate({ data: { posts: [post] } }); await until(() => items[0]?.provisional === undefined); assert.deepEqual(items[0].post, expected); history({ data: { feed: [{ post }], cursor: 'next' } }); await until(() => pages === 2); assert.deepEqual(items[1].post, expected); const changed = { ...post, cid: 'different-cid' }; history({ data: { feed: [{ post: changed }], cursor: 'last' } }); await until(() => pages === 3); assert.equal(items[0].post?.cid, changed.cid); assert.equal(items[0].post?.likeUri, post.viewer.like); assert.equal(items[0].post?.bookmarked, false); assert.equal(items[0].post?.counts?.repostCount, 1); const indexed = { ...post, ...expected.counts, viewer: { like: likeUri, bookmarked: true } }; history({ data: { feed: [{ post: indexed }] } }); await until(() => loaded); assert.deepEqual(items[0].post, expected); stop.reconcileInteraction({ kind: 'post', uri: post.uri, cid: post.cid, changes: { likeUri: null, bookmarked: false } }); await until(() => saved.at(-1)?.[0]?.viewer?.bookmarked === false); assert.equal(saved.at(-1)![0].viewer?.like, undefined); assert.equal(saved.at(-1)![0].viewer?.repost, undefined); assert.deepEqual(items[0].post?.counts, { ...expected.counts, likeCount: 1, bookmarkCount: 0 }); assert.equal(post.viewer.like, 'at://did:plc:viewer/app.bsky.feed.like/old'); } finally { stop(); } const count = saved.length; stop.reconcileInteraction({ kind: 'post', uri: post.uri, cid: post.cid, changes: { bookmarked: true } }); await new Promise((resolve) => setTimeout(resolve, 10)); assert.equal(saved.length, count); }); for (const action of ['mute', 'block', 'unfollow'] as const) { void test(`${action} removes cached authors immediately, flushes empty wall and survives stale graph and arrivals`, async (context) => { context.mock.method(Jetstream.prototype, 'live', async function* () {}); const post = fixture(); const cache = await openCache(); const account = moderation.userDid!; await cache.save(account, { follows: [post.author.did], blocks: [], syncedAt: 123 }); await cache.saveWall(account, { posts: [post], moderation, savedAt: Date.now() }); let graph!: (value: unknown) => void; let hydrate!: (value: unknown) => void; const graphTask = new Promise((resolve) => { graph = resolve; }); const hydration = new Promise((resolve) => { hydrate = resolve; }); let items: MediaItem[] = []; let loaded = false; let emissions = 0; const graphs: import('./cache.js').GraphSnapshot[] = []; const agent = { did: account, configureLabelers() {}, getPreferences: async () => ({ moderationPrefs: moderation.prefs }), getLabelDefinitions: async () => ({}), app: { bsky: { graph: { getFollows: () => graphTask, getBlocks: async () => ({ data: { blocks: [] } }) }, feed: { getPosts: () => hydration, getTimeline: async () => ({ data: { feed: [{ post }] } }) } } } } as unknown as Agent; const stop = startFeed( agent, { items: (value) => { items = value; emissions++; }, status: (value) => { if ( value.startsWith('Reconnecting') || value === 'Live media feed' || value.startsWith('Follow people') ) loaded = true; }, error(error) { assert.fail(error); }, graph: (value) => graphs.push(value) }, async () => cache ); try { await until(() => items.length === 2); stop.reconcileInteraction({ kind: 'actor', did: post.author.did, ...(action === 'mute' ? { muted: true } : action === 'block' ? { blocking: 'confirmed-block' } : { following: null }) }); assert.equal(items.length, 0); await until(() => emissions > 1); for ( let attempt = 0; attempt < 10 && (await cache.loadWall(account))?.posts.length; attempt++ ) await new Promise((resolve) => setTimeout(resolve, 5)); assert.deepEqual((await cache.loadWall(account))?.posts, []); if (action === 'block') { await until(() => graphs.at(-1)?.blocks.includes(post.author.did) === true); assert.equal((await cache.load(account))?.blocks.includes(post.author.did), true); } if (action === 'unfollow') { assert.equal(graphs.at(-1)?.follows.includes(post.author.did), false); await until(() => graphs.length > 1); assert.equal((await cache.load(account))?.follows.includes(post.author.did), false); } hydrate({ data: { posts: [post] } }); graph({ data: { follows: [post.author] } }); await until(() => loaded); assert.equal(items.length, 0); assert.equal( (await cache.load(account))?.blocks.includes(post.author.did), action === 'block' ); assert.equal( (await cache.load(account))?.follows.includes(post.author.did), action !== 'unfollow' ); assert.deepEqual((await cache.loadWall(account))?.posts, []); stop.reconcileInteraction({ kind: 'actor', did: post.author.did, ...(action === 'mute' ? { muted: false } : action === 'block' ? { blocking: null } : { following: 'at://did:plc:viewer/app.bsky.graph.follow/confirmed-follow' }) }); assert.equal(items.length, 0); } finally { stop(); } const count = emissions; stop.reconcileInteraction({ kind: 'actor', did: post.author.did, muted: true, blocking: 'ignored' }); assert.equal(emissions, count); }); } for (const action of ['mute', 'block'] as const) { void test(`${action} strips reposter reasons without hiding direct authors and excludes repost-sourced authors`, async (context) => { context.mock.method(Jetstream.prototype, 'live', async function* () {}); const direct = fixture(); const outside = { ...fixture(), uri: 'at://did:plc:outside/app.bsky.feed.post/one', author: { did: 'did:plc:outside', handle: 'outside.test' } }; const by = { did: 'did:plc:reposter', handle: 'reposter.test' }; const reason = { $type: 'app.bsky.feed.defs#reasonRepost', by, uri: `at://${by.did}/app.bsky.feed.repost/one`, indexedAt: '2026-11-07T02:00:00Z' }; let nextPage!: (value: unknown) => void; let pages = 0; let items: MediaItem[] = []; let loaded = false; const cache = await openCache(); const agent = { did: moderation.userDid, configureLabelers() {}, getPreferences: async () => ({ moderationPrefs: moderation.prefs }), getLabelDefinitions: async () => ({}), app: { bsky: { graph: { getFollows: async () => ({ data: { follows: [direct.author, by] } }), getBlocks: async () => ({ data: { blocks: [] } }) }, feed: { getPosts: async () => ({ data: { posts: [] } }), getTimeline: () => { pages++; return pages === 1 ? Promise.resolve({ data: { feed: [ { post: direct, reason }, { post: outside, reason: { ...reason, uri: `${reason.uri}two` } } ], cursor: 'next' } }) : new Promise((resolve) => { nextPage = resolve; }); } } } } } as unknown as Agent; const stop = startFeed( agent, { items: (value) => { items = value; }, status: (value) => { if ( value.startsWith('Reconnecting') || value === 'Live media feed' || value.startsWith('Follow people') ) loaded = true; }, error(error) { assert.fail(error); }, graph() {} }, async () => cache, undefined, { adultContent: 'account', labels: {}, includeReposts: true } ); try { await until(() => pages === 2); assert.equal(items.length, 4); stop.reconcileInteraction({ kind: 'actor', did: outside.author.did, ...(action === 'mute' ? { muted: true } : { blocking: 'author-block' }) }); assert.equal(items.length, 2); assert.equal(items[0].uri, direct.uri); assert.equal(items[0].repostedBy, by.handle); stop.reconcileInteraction({ kind: 'actor', did: outside.author.did, ...(action === 'mute' ? { muted: false } : { blocking: null }) }); assert.equal(items.length, 2); stop.reconcileInteraction({ kind: 'actor', did: by.did, ...(action === 'mute' ? { muted: true } : { blocking: 'block' }) }); assert.equal(items.length, 2); assert.equal(items[0].uri, direct.uri); assert.equal(items[0].repostedBy, undefined); nextPage({ data: { feed: [ { post: outside, reason }, { post: direct, reason } ] } }); await until(() => loaded); assert.equal(items.length, 2); assert.equal(items[0].repostedBy, undefined); } finally { stop(); } }); } void test('unmute and unblock never clear list restrictions on authors or reposters', async (context) => { context.mock.method(Jetstream.prototype, 'live', async function* () {}); const post = fixture(); const list = { uri: 'at://did:plc:list/app.bsky.graph.list/one', cid: post.cid, name: 'Restricted', purpose: 'app.bsky.graph.defs#modlist' }; post.author.viewer = { muted: true, blocking: 'at://did:plc:viewer/app.bsky.graph.block/one', mutedByList: list, blockingByList: list }; const outside = { ...fixture(), uri: 'at://did:plc:outside/app.bsky.feed.post/one', author: { did: 'did:plc:outside', handle: 'outside.test' } }; const by = { did: 'did:plc:reposter', handle: 'reposter.test', viewer: { muted: true, mutedByList: list } }; const reason = { $type: 'app.bsky.feed.defs#reasonRepost', by, uri: `at://${by.did}/app.bsky.feed.repost/one`, indexedAt: '2026-11-07T02:00:00Z' }; const cache = await openCache(); let items: MediaItem[] = []; let loaded = false; const agent = { did: moderation.userDid, configureLabelers() {}, getPreferences: async () => ({ moderationPrefs: moderation.prefs }), getLabelDefinitions: async () => ({}), app: { bsky: { graph: { getFollows: async () => ({ data: { follows: [post.author, by] } }), getBlocks: async () => ({ data: { blocks: [] } }) }, feed: { getPosts: async () => ({ data: { posts: [] } }), getTimeline: async () => ({ data: { feed: [{ post }, { post: outside, reason }] } }) } } } } as unknown as Agent; const stop = startFeed( agent, { items: (value) => { items = value; }, status: (value) => { if (value.startsWith('Reconnecting')) loaded = true; }, error(error) { assert.fail(error); }, graph() {} }, async () => cache, undefined, { adultContent: 'account', labels: {}, includeReposts: true } ); try { await until(() => loaded); stop.reconcileInteraction({ kind: 'actor', did: post.author.did, muted: false, blocking: null, following: 'at://did:plc:viewer/app.bsky.graph.follow/author' }); stop.reconcileInteraction({ kind: 'actor', did: by.did, muted: false, blocking: null, following: 'at://did:plc:viewer/app.bsky.graph.follow/reposter' }); assert.deepEqual(items, []); stop.updateSettings({ adultContent: 'account', labels: {}, includeReposts: true }); assert.deepEqual(items, []); } finally { stop(); } }); void test('confirmed follows promote retained reposts, start streams and survive stale graph refresh without bypassing moderation', async (context) => { const post = fixture(); post.author.viewer = { following: 'at://did:plc:viewer/app.bsky.graph.follow/stale-follow' }; const hidden = { ...fixture(), uri: `${post.uri}hidden`, labels: [{ src: post.author.did, uri: `${post.uri}hidden`, val: 'porn', cts: post.indexedAt }] }; const by = { did: 'did:plc:reposter', handle: 'reposter.test' }; const reason = { $type: 'app.bsky.feed.defs#reasonRepost', by, uri: `at://${by.did}/app.bsky.feed.repost/one`, indexedAt: '2026-11-07T02:00:00Z' }; const subscriptions: Parameters[0][] = []; context.mock.method( Jetstream.prototype, 'live', async function* (options: Parameters[0]) { subscriptions.push(options); await new Promise((resolve) => options.signal!.addEventListener('abort', () => resolve(), { once: true }) ); yield* [] as never[]; } ); const cache = await openCache(); const account = moderation.userDid!; await cache.save(account, { follows: [by.did], blocks: [], syncedAt: 123 }); let finishGraph!: (value: unknown) => void; const graphTask = new Promise((resolve) => { finishGraph = resolve; }); let finishHistory!: (value: unknown) => void; let pages = 0; let items: MediaItem[] = []; let loaded = false; const graphs: import('./cache.js').GraphSnapshot[] = []; const agent = { did: account, configureLabelers() {}, getPreferences: async () => ({ moderationPrefs: moderation.prefs }), getLabelDefinitions: async () => ({}), app: { bsky: { graph: { getFollows: () => graphTask, getBlocks: async () => ({ data: { blocks: [] } }) }, feed: { getPosts: async () => ({ data: { posts: [] } }), getTimeline: () => { pages++; return pages === 1 ? Promise.resolve({ data: { feed: [ { post, reason }, { post: hidden, reason: { ...reason, uri: `${reason.uri}hidden` } } ], cursor: 'next' } }) : new Promise((resolve) => { finishHistory = resolve; }); } } } } } as unknown as Agent; const stop = startFeed( agent, { items: (value) => { items = value; }, status: (value) => { if ( value.startsWith('Reconnecting') || value === 'Live media feed' || value.startsWith('Follow people') ) loaded = true; }, error(error) { assert.fail(error); }, graph: (value) => graphs.push(value) }, async () => cache ); try { await until(() => graphs.length === 1); stop.reconcileInteraction({ kind: 'actor', did: post.author.did, following: 'at://did:plc:viewer/app.bsky.graph.follow/confirmed-follow' }); assert.ok(graphs.at(-1)?.follows.includes(post.author.did)); assert.ok(subscriptions.at(-1)?.dids?.includes(post.author.did as `did:${string}:${string}`)); assert.ok(subscriptions[0].signal?.aborted); finishGraph({ data: { follows: [by] } }); await until(() => pages === 2); assert.equal(items.length, 2); assert.equal( items[0].post?.authorFollowing, 'at://did:plc:viewer/app.bsky.graph.follow/confirmed-follow' ); assert.equal(items[0].authorNotFollowed, undefined); assert.ok(graphs.at(-1)?.follows.includes(post.author.did)); stop.reconcileInteraction({ kind: 'actor', did: post.author.did, following: null }); assert.equal(items.length, 0); stop.updateSettings({ adultContent: 'account', labels: {}, includeReposts: true }); assert.equal(items.length, 2); assert.equal(items[0].repostedBy, by.handle); assert.equal(items[0].post?.authorFollowing, undefined); assert.ok(items.every((item) => item.authorNotFollowed === true)); stop.updateSettings({ adultContent: 'account', labels: {}, includeReposts: false }); assert.equal(items.length, 0); stop.reconcileInteraction({ kind: 'actor', did: post.author.did, following: 'at://did:plc:viewer/app.bsky.graph.follow/new-follow' }); assert.equal(items.length, 2); assert.equal( items[0].post?.authorFollowing, 'at://did:plc:viewer/app.bsky.graph.follow/new-follow' ); assert.equal(items[0].authorNotFollowed, undefined); stop.reconcileInteraction({ kind: 'actor', did: by.did, following: null }); assert.equal(items.length, 2); assert.equal(items[0].repostedBy, undefined); assert.equal(items[0].sensitive, undefined); finishHistory({ data: { feed: [{ post, reason }] } }); await until(() => loaded); assert.equal(pages, 2); assert.equal( items[0].post?.authorFollowing, 'at://did:plc:viewer/app.bsky.graph.follow/new-follow' ); assert.equal(items[0].authorNotFollowed, undefined); assert.equal(items[0].repostedBy, undefined); for ( let attempt = 0; attempt < 20 && (await cache.loadWall(account))?.posts[0]?.author.viewer?.following !== 'at://did:plc:viewer/app.bsky.graph.follow/new-follow'; attempt++ ) await new Promise((resolve) => setTimeout(resolve, 5)); assert.equal( (await cache.loadWall(account))?.posts[0]?.author.viewer?.following, 'at://did:plc:viewer/app.bsky.graph.follow/new-follow' ); assert.deepEqual((await cache.load(account))?.follows, [post.author.did]); stop.reconcileInteraction({ kind: 'actor', did: post.author.did, following: null }); assert.equal(items.length, 0); for (let attempt = 0; attempt < 20 && (await cache.loadWall(account))?.posts.length; attempt++) await new Promise((resolve) => setTimeout(resolve, 5)); assert.deepEqual((await cache.loadWall(account))?.posts, []); } finally { finishGraph({ data: { follows: [] } }); finishHistory?.({ data: { feed: [] } }); stop(); } }); void test('repost cooldown retains originals and accepted reasons, promotes distinct events only at the boundary', async (context) => { const post = fixture(); const reposters = ['did:plc:one', 'did:plc:two']; let now = Date.now(); context.mock.method(Date, 'now', () => now); type Event = { seq: number; did: string; kind: 'commit'; commit: Record }; const events: Event[] = []; let wake: (() => void) | undefined; let seq = 0; let loaded = false; let items: MediaItem[] = []; let requests = 0; context.mock.method( Jetstream.prototype, 'live', async function* (options: Parameters[0]) { assert.ok(options.collections?.includes('app.bsky.feed.repost')); while (!options.signal?.aborted) { if (events.length) yield events.shift()!; else await new Promise((resolve) => { wake = resolve; options.signal?.addEventListener('abort', () => resolve(), { once: true }); }); } } ); const cache = await openCache(); const agent = { did: moderation.userDid, configureLabelers() {}, getPreferences: async () => ({ moderationPrefs: moderation.prefs }), getLabelDefinitions: async () => ({}), app: { bsky: { graph: { getFollows: async () => ({ data: { follows: [...reposters, post.author.did].map((did) => ({ did, handle: did })) } }), getBlocks: async () => ({ data: { blocks: [] } }) }, feed: { getPosts: async () => { requests++; return { data: { posts: [post] } }; }, getTimeline: async () => ({ data: { feed: [{ post }] } }) } } } } as unknown as Agent; const stop = startFeed( agent, { items: (value) => { items = value; }, status: (value) => { if ( value.startsWith('Reconnecting') || value === 'Live media feed' || value.startsWith('Follow people') ) loaded = true; }, error(error) { assert.fail(error); }, graph() {} }, async () => cache, () => ({ stream: async function* () {} }), { adultContent: 'account', labels: {}, includeReposts: true, repostCooldownHours: 1 } ); const send = ( did: string, operation: string, record: unknown = { $type: 'app.bsky.feed.repost', subject: { uri: post.uri, cid: post.cid }, createdAt: new Date(now).toISOString() } ) => { events.push({ seq: ++seq, did, kind: 'commit', commit: { collection: 'app.bsky.feed.repost', rkey: 'test', operation, record, cid: post.cid } }); wake?.(); }; try { await until(() => loaded); assert.equal(items.length, 2); stop.markDisplayed(post.uri); send(reposters[0], 'create'); await until(() => requests === 1); assert.equal(items[0].repostedBy, undefined); now += 3_600_000 - 1; send(reposters[1], 'create'); await until(() => requests === 2); assert.equal(items[0].repostedBy, undefined); now += 1; stop.updateSettings({ adultContent: 'account', labels: {}, includeReposts: true, repostCooldownHours: 1 }); assert.equal(items[0].repostedBy, undefined); send(reposters[0], 'update'); await until(() => requests === 3); assert.equal(items[0].repostedBy, reposters[0]); stop.markDisplayed(post.uri); now += 1; send(reposters[1], 'update'); await until(() => requests === 4); assert.equal(items[0].repostedBy, reposters[0]); for (let i = 0; i < 2001; i++) { now++; send(reposters[1], 'update'); } await until(() => requests === 5); assert.equal(items[0].repostedBy, reposters[0]); now += 3_600_000; stop.updateSettings({ adultContent: 'account', labels: {}, includeReposts: true, repostCooldownHours: 1 }); assert.equal(items[0].repostedBy, reposters[0]); send(reposters[1], 'update'); await until(() => requests === 6); assert.equal(items[0].repostedBy, reposters[1]); stop.markDisplayed(post.uri); now += 1_800_000; send(reposters[1], 'delete'); send(reposters[0], 'delete'); await until(() => items[0].repostedBy === undefined); stop.markDisplayed(post.uri); now += 1_800_000; send(reposters[0], 'create'); await until(() => requests === 7); assert.equal(items[0].repostedBy, reposters[0]); } finally { stop(); } });