From 24215b1c1e417787b30985f4ee377c381bd0fc21 Mon Sep 17 00:00:00 2001 From: Rudy Fraser Date: Tue, 21 Jul 2026 07:37:50 -0600 Subject: [PATCH] test(feed): add merged community post tuner regression tests --- __tests__/lib/feed-manip-community.test.ts | 149 +++++++++++++++++++++ package.json | 2 +- src/view/screens/Profile.tsx | 3 +- 3 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 __tests__/lib/feed-manip-community.test.ts diff --git a/__tests__/lib/feed-manip-community.test.ts b/__tests__/lib/feed-manip-community.test.ts new file mode 100644 index 000000000..8350acef5 --- /dev/null +++ b/__tests__/lib/feed-manip-community.test.ts @@ -0,0 +1,149 @@ +import { + type AppBskyActorDefs, + type AppBskyFeedDefs, + type AppBskyFeedPost, +} from '@atproto/api' + +import {FeedTuner} from '#/lib/api/feed-manip' + +// The repo-wide manual mock stubs CID.parse away, which makes every +// cid-format validation fail; these tests exercise real record validation. +jest.unmock('multiformats/cid') + +// Merged community posts arrive from the appview as standard FeedViewPosts +// whose post URIs use the community.blacksky.feed.post collection but whose +// records carry $type app.bsky.feed.post. These tests encode the invariants +// the appview merge must uphold for the standard Following tuner stack to +// render them: record $type normalization and hydrated reply parent/root. + +const VIEWER_DID = 'did:plc:viewer' +const MEMBER_DID = 'did:plc:member' +const COLLECTION = 'community.blacksky.feed.post' +const CID = 'bafyreihhl5mpvjkrhnnagen2fomozzhnhhdq2jr6cego2nzbvmwewv5rd4' + +function author( + did: string, + opts?: {following?: boolean}, +): AppBskyActorDefs.ProfileViewBasic { + return { + $type: 'app.bsky.actor.defs#profileViewBasic', + did, + handle: `${did.split(':').pop()}.blacksky.app`, + viewer: opts?.following + ? {following: `at://${VIEWER_DID}/app.bsky.graph.follow/abc`} + : {}, + } +} + +function communityPost(opts: { + rkey: string + authorDid?: string + reply?: {rootUri: string; parentUri: string} + threadMuted?: boolean + recordType?: string +}): AppBskyFeedDefs.PostView { + const did = opts.authorDid ?? MEMBER_DID + const record: AppBskyFeedPost.Record = { + $type: (opts.recordType ?? 'app.bsky.feed.post') as 'app.bsky.feed.post', + text: `post ${opts.rkey}`, + createdAt: '2026-07-17T12:00:00.000Z', + ...(opts.reply + ? { + reply: { + root: {uri: opts.reply.rootUri, cid: CID}, + parent: {uri: opts.reply.parentUri, cid: CID}, + }, + } + : {}), + } + return { + $type: 'app.bsky.feed.defs#postView', + uri: `at://${did}/${COLLECTION}/${opts.rkey}`, + cid: CID, + author: author(did, {following: did !== VIEWER_DID}), + record, + indexedAt: '2026-07-17T12:00:00.000Z', + viewer: opts.threadMuted ? {threadMuted: true} : {}, + } +} + +function followingTuner() { + return new FeedTuner([ + FeedTuner.removeOrphans, + FeedTuner.followedRepliesOnly({userDid: VIEWER_DID}), + FeedTuner.dedupThreads, + FeedTuner.removeMutedThreads, + ]) +} + +describe('FeedTuner with merged community posts', () => { + it('keeps a top-level community post', () => { + const feed: AppBskyFeedDefs.FeedViewPost[] = [ + {post: communityPost({rkey: 'aaa'})}, + ] + const slices = followingTuner().tune(feed) + expect(slices).toHaveLength(1) + expect(slices[0].items[0].post.uri).toContain(COLLECTION) + }) + + it('keeps a community self-reply with hydrated parent and root', () => { + const root = communityPost({rkey: 'root'}) + const reply = communityPost({ + rkey: 'reply', + reply: {rootUri: root.uri, parentUri: root.uri}, + }) + const feed: AppBskyFeedDefs.FeedViewPost[] = [ + { + post: reply, + reply: {root, parent: root}, + }, + ] + const slices = followingTuner().tune(feed) + expect(slices).toHaveLength(1) + expect(slices[0].isOrphan).toBe(false) + expect(slices[0].items.map(i => i.post.uri)).toEqual([root.uri, reply.uri]) + }) + + it('drops a community reply whose parent was not hydrated (orphan)', () => { + const rootUri = `at://${MEMBER_DID}/${COLLECTION}/root` + const reply = communityPost({ + rkey: 'reply', + reply: {rootUri, parentUri: rootUri}, + }) + const feed: AppBskyFeedDefs.FeedViewPost[] = [{post: reply}] + const slices = followingTuner().tune(feed) + expect(slices).toHaveLength(0) + }) + + it('dedupes slices sharing a community thread root', () => { + const root = communityPost({rkey: 'root'}) + const reply = communityPost({ + rkey: 'reply', + reply: {rootUri: root.uri, parentUri: root.uri}, + }) + const feed: AppBskyFeedDefs.FeedViewPost[] = [ + {post: reply, reply: {root, parent: root}}, + {post: root}, + ] + const slices = followingTuner().tune(feed) + expect(slices).toHaveLength(1) + }) + + it('drops a thread-muted community post', () => { + const feed: AppBskyFeedDefs.FeedViewPost[] = [ + {post: communityPost({rkey: 'muted', threadMuted: true})}, + ] + const slices = followingTuner().tune(feed) + expect(slices).toHaveLength(0) + }) + + it('drops items whose record $type is not app.bsky.feed.post', () => { + // Encodes the appview invariant: buildCommunityPostView must normalize + // record $type, or merged items silently vanish from feeds. + const feed: AppBskyFeedDefs.FeedViewPost[] = [ + {post: communityPost({rkey: 'raw', recordType: COLLECTION})}, + ] + const slices = followingTuner().tune(feed) + expect(slices).toHaveLength(0) + }) +}) diff --git a/package.json b/package.json index bc858b0cf..d13487e37 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blacksky.community", - "version": "1.127.0", + "version": "1.127.1", "private": true, "packageManager": "pnpm@11.7.0", "engines": { diff --git a/src/view/screens/Profile.tsx b/src/view/screens/Profile.tsx index 0bfad9dd4..5b703f67a 100644 --- a/src/view/screens/Profile.tsx +++ b/src/view/screens/Profile.tsx @@ -243,7 +243,8 @@ function ProfileScreenLoaded({ const hasLabeler = !!profile.associated?.labeler const showFiltersTab = hasLabeler const showPostsTab = true - // Community posts surface on the home Community tab only, not profiles. + // Community posts are merged into the Posts tab server-side for member + // viewers, so the dedicated profile Community tab stays off. const showCommunityTab = false const showRepliesTab = hasSession const showMediaTab = !hasLabeler -- knotmirror 0.0.1