diff --git a/src/lib/api/__tests__/assembly-publish.test.ts b/src/lib/api/__tests__/assembly-publish.test.ts index 58afd2e0f..a2fc53266 100644 --- a/src/lib/api/__tests__/assembly-publish.test.ts +++ b/src/lib/api/__tests__/assembly-publish.test.ts @@ -1,6 +1,7 @@ import {type Client} from '@atproto/lex' import {type QueryClient} from '@tanstack/react-query' +import {app, com} from '#/lexicons' import {logger} from '#/logger' import {fetchResolveLinkQuery} from '#/state/queries/resolve-link' import {AssemblyError, ensureAssembly} from '../assembly' @@ -118,19 +119,17 @@ function setup() { const getPosts = jest.fn(() => { events.push('getPosts') return Promise.resolve({ - data: { - posts: [ - { - uri: PUBLIC_PARENT, - cid: 'bafyreiparent', - record: { - $type: 'app.bsky.feed.post', - text: 'hi', - createdAt: '2026-09-27T11:00:00.000Z', - }, + posts: [ + { + uri: PUBLIC_PARENT, + cid: 'bafyreiparent', + record: { + $type: 'app.bsky.feed.post', + text: 'hi', + createdAt: '2026-09-27T11:00:00.000Z', }, - ], - }, + }, + ], }) }) const onStateChange = jest.fn((state: string) => { @@ -138,12 +137,29 @@ function setup() { }) const onAssembly = jest.fn() const client = { + did: 'did:plc:alice', assertDid: 'did:plc:alice', + agent: {fetchHandler}, + call: (method: unknown, input: never) => { + if (method === com.atproto.repo.applyWrites) return applyWrites(input) + if (method === app.bsky.feed.getPosts) return getPosts(input) + throw new Error('unexpected call') + }, + } as unknown as Client + const clients = { + appviewClient: client, + chatClient: client, + pdsClient: client, + } + return { + client, + clients, fetchHandler, - com: {atproto: {repo: {applyWrites}}}, - app: {bsky: {feed: {getPosts}}}, - } as unknown as AtpAgent - return {client, fetchHandler, applyWrites, getPosts, onStateChange, onAssembly} + applyWrites, + getPosts, + onStateChange, + onAssembly, + } } function draft(embed: Record, text = TOPIC, id = 'post-1') { @@ -221,7 +237,7 @@ beforeEach(() => { }) mockUploadBlob.mockImplementation(() => { events.push('uploadBlob') - return Promise.resolve({data: {blob: THUMB_BLOB}} as never) + return Promise.resolve({blob: THUMB_BLOB} as never) }) mockPostToSpace.mockResolvedValue({uris: ['at://space/post']}) }) @@ -235,7 +251,8 @@ describe('publishing a post with a poll', () => { it('writes the post with a link card to the assembly', async () => { const ctx = setup() - const result = await post(ctx.agent, queryClient, { + const result = await post(queryClient, { + ...ctx.clients, thread: thread([ draft( {poll: {statements: [' Yes, until sunset ', 'Only on weekends']}}, @@ -264,7 +281,8 @@ describe('publishing a post with a poll', () => { it('starts the assembly with the topic, statements and stored reference', async () => { const ctx = setup() - await post(ctx.agent, queryClient, { + await post(queryClient, { + ...ctx.clients, thread: thread([ draft( { @@ -279,7 +297,7 @@ describe('publishing a post with a poll', () => { }) expect(mockEnsureAssembly).toHaveBeenCalledTimes(1) - expect(mockEnsureAssembly).toHaveBeenCalledWith(ctx.agent, { + expect(mockEnsureAssembly).toHaveBeenCalledWith(ctx.client, { topic: TOPIC, statements: STATEMENTS, ref: REF, @@ -290,7 +308,8 @@ describe('publishing a post with a poll', () => { it('creates the assembly and its thumbnail before writing the post', async () => { const ctx = setup() - await post(ctx.agent, queryClient, { + await post(queryClient, { + ...ctx.clients, thread: pollThread(), onStateChange: ctx.onStateChange, }) @@ -306,7 +325,7 @@ describe('publishing a post with a poll', () => { ]) expect(mockImageToThumb).toHaveBeenCalledWith(THUMB_URL) expect(mockUploadBlob).toHaveBeenCalledWith( - ctx.agent, + ctx.client, 'file:///cache/thumb.png', 'image/png', ) @@ -317,7 +336,8 @@ describe('publishing a post with a poll', () => { it('reports every change of the reference with the id of the poll post', async () => { const ctx = setup() - await post(ctx.agent, queryClient, { + await post(queryClient, { + ...ctx.clients, thread: pollThread(), onAssembly: ctx.onAssembly, }) @@ -333,7 +353,8 @@ describe('publishing a post with a poll', () => { const stored = {...REF, conversationId: '1stale'} mockEnsureAssembly.mockResolvedValue({ref: CREATED_REF, isReplay: true}) - const result = await post(ctx.agent, queryClient, { + const result = await post(queryClient, { + ...ctx.clients, thread: thread([ draft({poll: {statements: STATEMENTS, assembly: stored}}), ]), @@ -341,7 +362,7 @@ describe('publishing a post with a poll', () => { }) expect(mockEnsureAssembly).toHaveBeenCalledWith( - ctx.agent, + ctx.client, expect.objectContaining({ref: stored}), ) expect(writesOf(ctx.applyWrites)[0].value.embed?.external.uri).toBe( @@ -364,7 +385,8 @@ describe('publishing a post with a poll', () => { }) await expect( - post(ctx.agent, queryClient, { + post(queryClient, { + ...ctx.clients, thread: pollThread(), onAssembly: ctx.onAssembly, }), @@ -379,7 +401,8 @@ describe('publishing a post with a poll', () => { it('leaves a post without a poll alone', async () => { const ctx = setup() - const result = await post(ctx.agent, queryClient, { + const result = await post(queryClient, { + ...ctx.clients, thread: thread([draft({})]), onStateChange: ctx.onStateChange, onAssembly: ctx.onAssembly, @@ -399,7 +422,8 @@ describe('publishing a post with a poll', () => { it('uses the text of the post that carries the poll as the topic', async () => { const ctx = setup() - const result = await post(ctx.agent, queryClient, { + const result = await post(queryClient, { + ...ctx.clients, thread: thread([ draft({}, 'Some context first', 'post-1'), draft({poll: {statements: STATEMENTS}}, TOPIC, 'post-2'), @@ -408,7 +432,7 @@ describe('publishing a post with a poll', () => { }) expect(mockEnsureAssembly).toHaveBeenCalledWith( - ctx.agent, + ctx.client, expect.objectContaining({topic: TOPIC, statements: STATEMENTS}), ) expect(ctx.onAssembly.mock.calls).toEqual([ @@ -430,7 +454,8 @@ describe('publishing a post with a poll', () => { const ctx = setup() const target = feedTarget('publicRecord') - const result = await post(ctx.agent, queryClient, { + const result = await post(queryClient, { + ...ctx.clients, thread: pollThread({communityFeed: target}), }) @@ -439,7 +464,7 @@ describe('publishing a post with a poll', () => { ) expect(mockAdmitFeedPost).toHaveBeenCalledTimes(1) expect(mockAdmitFeedPost).toHaveBeenCalledWith( - ctx.agent, + ctx.client, target, result.uris[0], 'bafyreifake', @@ -458,7 +483,8 @@ describe('replying with a poll', () => { }) as never }) - const pending = post(ctx.agent, queryClient, { + const pending = post(queryClient, { + ...ctx.clients, thread: pollThread(), replyTo: PUBLIC_PARENT, onStateChange: ctx.onStateChange, @@ -467,7 +493,7 @@ describe('replying with a poll', () => { expect(events).toEqual(['stage:Processing...', 'getPosts']) - release({data: {posts: [{uri: PUBLIC_PARENT, cid: 'bafyreiparent'}]}}) + release({posts: [{uri: PUBLIC_PARENT, cid: 'bafyreiparent'}]}) await pending expect(events).toEqual([ @@ -490,11 +516,12 @@ describe('replying with a poll', () => { it('starts no assembly when the parent is gone', async () => { const ctx = setup() ctx.getPosts.mockImplementation(() => - Promise.resolve({data: {posts: []}} as never), + Promise.resolve({posts: []} as never), ) await expect( - post(ctx.agent, queryClient, { + post(queryClient, { + ...ctx.clients, thread: pollThread(), replyTo: PUBLIC_PARENT, onStateChange: ctx.onStateChange, @@ -533,7 +560,7 @@ describe('the poll thumbnail', () => { const ctx = setup() arrange() - const result = await post(ctx.agent, queryClient, {thread: pollThread()}) + const result = await post(queryClient, {...ctx.clients, thread: pollThread()}) expect(mockUploadBlob).toHaveBeenCalledTimes(uploads) expect(ctx.applyWrites).toHaveBeenCalledTimes(1) @@ -554,7 +581,7 @@ describe('the poll thumbnail', () => { const ctx = setup() mockImageToThumb.mockImplementation(() => new Promise(() => {})) - const pending = post(ctx.agent, queryClient, {thread: pollThread()}) + const pending = post(queryClient, {...ctx.clients, thread: pollThread()}) await jest.advanceTimersByTimeAsync(4999) expect(mockImageToThumb).toHaveBeenCalledWith(THUMB_URL) @@ -575,7 +602,7 @@ describe('the poll thumbnail', () => { jest.useFakeTimers() const ctx = setup() - await post(ctx.agent, queryClient, {thread: pollThread()}) + await post(queryClient, {...ctx.clients, thread: pollThread()}) expect(mockUploadBlob).toHaveBeenCalledTimes(1) expect(jest.getTimerCount()).toBe(0) @@ -600,7 +627,8 @@ describe('a poll outside the public path', () => { const ctx = setup() await expect( - post(ctx.agent, queryClient, { + post(queryClient, { + ...ctx.clients, thread: pollThread(input.extra), replyTo: input.replyTo, onAssembly: ctx.onAssembly, @@ -615,7 +643,8 @@ describe('a poll outside the public path', () => { const ctx = setup() await expect( - post(ctx.agent, queryClient, { + post(queryClient, { + ...ctx.clients, thread: thread( [ draft({}, 'Some context first', 'post-1'), @@ -633,7 +662,8 @@ describe('a poll outside the public path', () => { const ctx = setup() await expect( - post(ctx.agent, queryClient, { + post(queryClient, { + ...ctx.clients, thread: thread([ draft({ poll: {statements: STATEMENTS}, @@ -653,12 +683,13 @@ describe('a poll outside the public path', () => { ) await expect( - post(ctx.agent, queryClient, { + post(queryClient, { + ...ctx.clients, thread: pollThread({communityFeedUri: FEED}), }), ).rejects.toThrow(new Error(POLLS_ARE_PUBLIC)) - expect(mockFetchFeedTarget).toHaveBeenCalledWith(ctx.agent, FEED) + expect(mockFetchFeedTarget).toHaveBeenCalledWith(ctx.client, FEED) expectNothingStarted(ctx) }) }) @@ -686,7 +717,8 @@ describe('a poll with another attachment', () => { const ctx = setup() await expect( - post(ctx.agent, queryClient, { + post(queryClient, { + ...ctx.clients, thread: thread([draft({poll: {statements: STATEMENTS}, ...extra})]), }), ).rejects.toThrow(new Error(COMBINED)) @@ -702,7 +734,9 @@ describe('a poll with another attachment', () => { await expect( resolveEmbed( - ctx.agent, + ctx.client, + ctx.client, + ctx.client, queryClient, draft({ poll: {statements: STATEMENTS, assembly: CREATED_REF}, @@ -723,7 +757,8 @@ describe('poll invariants', () => { const ctx = setup() await expect( - post(ctx.agent, queryClient, { + post(queryClient, { + ...ctx.clients, thread: thread([ draft({poll: {statements: STATEMENTS}}, TOPIC, 'post-1'), draft({poll: {statements: ['Another']}}, 'Second', 'post-2'), @@ -742,7 +777,9 @@ describe('poll invariants', () => { await expect( resolveEmbed( - ctx.agent, + ctx.client, + ctx.client, + ctx.client, queryClient, draft({poll: {statements: STATEMENTS, assembly}}) as never, undefined, diff --git a/src/lib/api/__tests__/assembly.test.ts b/src/lib/api/__tests__/assembly.test.ts index d0bdba4bb..14815fdb2 100644 --- a/src/lib/api/__tests__/assembly.test.ts +++ b/src/lib/api/__tests__/assembly.test.ts @@ -16,6 +16,7 @@ import { } from '#/lib/api/assembly' import {type AssemblyRef} from '#/lib/api/poll' import {parseEmbedPlayerFromUrl} from '#/lib/strings/embed-player' +import {com} from '#/lexicons' jest.mock('#/env', () => mockEnv('https://assembly.blacksky.community')) @@ -74,24 +75,20 @@ function setup() { const putRecord = jest.fn((input: RecordInput) => { events.push('putRecord') return Promise.resolve({ - data: { - uri: `at://${input.repo}/${input.collection}/${input.rkey}`, - cid: CID, - }, + uri: `at://${input.repo}/${input.collection}/${input.rkey}`, + cid: CID, }) }) - const deleteRecord = jest.fn<(input: RecordInput) => Promise<{data: object}>>( - () => { - events.push('deleteRecord') - return Promise.resolve({data: {}}) - }, - ) + const deleteRecord = jest.fn<(input: RecordInput) => Promise>(() => { + events.push('deleteRecord') + return Promise.resolve({}) + }) const getServiceAuth = jest.fn< - (input: TokenInput) => Promise<{data: {token: string}}> + (input: TokenInput) => Promise<{token: string}> >(() => { events.push('getServiceAuth') tokens += 1 - return Promise.resolve({data: {token: `token-${tokens}`}}) + return Promise.resolve({token: `token-${tokens}`}) }) const onRef = jest.fn((ref: AssemblyRef) => { events.push('onRef') @@ -103,14 +100,20 @@ function setup() { }) const client = { assertDid: DID, - dispatchUrl: 'https://pds.example/', - com: { - atproto: { - repo: {putRecord, deleteRecord}, - server: {getServiceAuth}, - }, + // Matched by name: a test that reloads modules gets its own lexicons. + call: (method: {$lxm: string}, input: never) => { + switch (method.$lxm) { + case com.atproto.repo.putRecord.$lxm: + return putRecord(input) + case com.atproto.repo.deleteRecord.$lxm: + return deleteRecord(input) + case com.atproto.server.getServiceAuth.$lxm: + return getServiceAuth(input) + default: + throw new Error('unexpected call') + } }, - } as unknown as AtpAgent + } as unknown as Client return { client, events, diff --git a/src/lib/api/__tests__/event-publish.test.ts b/src/lib/api/__tests__/event-publish.test.ts index 13c3507c0..5438ff91d 100644 --- a/src/lib/api/__tests__/event-publish.test.ts +++ b/src/lib/api/__tests__/event-publish.test.ts @@ -64,10 +64,17 @@ function setup() { Promise.resolve({}), ) const client = { + did: 'did:plc:alice', assertDid: 'did:plc:alice', - com: {atproto: {repo: {applyWrites}}}, - } as unknown as AtpAgent - return {client, applyWrites} + call: (_method: unknown, input: {writes: Write[]; validate?: boolean}) => + applyWrites(input), + } as unknown as Client + const clients = { + appviewClient: client, + chatClient: client, + pdsClient: client, + } + return {client, clients, applyWrites} } function thread(embed: Record, extra = {}) { @@ -90,9 +97,12 @@ function thread(embed: Record, extra = {}) { describe('publishing a post with an event', () => { it('writes the event and the post together, linking the post to it', async () => { - const {client, applyWrites} = setup() + const {client, clients, applyWrites} = setup() - const result = await post(client, queryClient, {thread: thread({event})}) + const result = await post(queryClient, { + ...clients, + thread: thread({event}), + }) expect(applyWrites).toHaveBeenCalledTimes(1) const [{writes, validate}] = applyWrites.mock.calls[0] @@ -129,19 +139,20 @@ describe('publishing a post with an event', () => { }) it('still asks the PDS to validate posts without an event', async () => { - const {client, applyWrites} = setup() + const {client, clients, applyWrites} = setup() - const result = await post(client, queryClient, {thread: thread({})}) + const result = await post(queryClient, {...clients, thread: thread({})}) expect(applyWrites.mock.calls[0][0].validate).toBe(true) expect(result).not.toHaveProperty('event') }) it('refuses an event on a Blacksky-only post', async () => { - const {client, applyWrites} = setup() + const {client, clients, applyWrites} = setup() await expect( - post(client, queryClient, { + post(queryClient, { + ...clients, thread: thread({event}, {blackskyOnly: true}), }), ).rejects.toThrow('Events are only available on public posts.') @@ -149,10 +160,11 @@ describe('publishing a post with an event', () => { }) it('refuses an event in a private space', async () => { - const {client} = setup() + const {clients} = setup() await expect( - post(client, queryClient, { + post(queryClient, { + ...clients, thread: thread({event}, {communitySpaceUri: SPACE}), }), ).rejects.toThrow('Events are only available on public posts.') @@ -164,16 +176,15 @@ describe('publishing a post with an event', () => { beforeEach(() => { jest.mocked(uploadBlob).mockReset() jest.mocked(imageToThumb).mockReset() - jest - .mocked(uploadBlob) - .mockResolvedValue({data: {blob: COVER_BLOB}} as never) + jest.mocked(uploadBlob).mockResolvedValue({blob: COVER_BLOB} as never) warn = jest.spyOn(logger, 'warn').mockImplementation(() => {}) }) afterEach(() => warn.mockRestore()) async function publish(cover: EventDraft['cover']) { - const {client, applyWrites} = setup() - await post(client, queryClient, { + const {client, clients, applyWrites} = setup() + await post(queryClient, { + ...clients, thread: thread({event: {...event, cover}}), }) const [eventWrite, postWrite] = applyWrites.mock.calls[0][0].writes @@ -230,10 +241,11 @@ describe('publishing a post with an event', () => { it('stops the post with an error when the upload fails', async () => { jest.mocked(uploadBlob).mockRejectedValue(new Error('offline')) - const {client, applyWrites} = setup() + const {client, clients, applyWrites} = setup() await expect( - post(client, queryClient, { + post(queryClient, { + ...clients, thread: thread({ event: { ...event, @@ -255,10 +267,11 @@ describe('publishing a post with an event', () => { it('stops the post when a link image cannot be read', async () => { jest.mocked(imageToThumb).mockResolvedValue(undefined) - const {client, applyWrites} = setup() + const {client, clients, applyWrites} = setup() await expect( - post(client, queryClient, { + post(queryClient, { + ...clients, thread: thread({ event: {...event, cover: {url: 'https://x.test/a.jpg'}}, }), diff --git a/src/lib/api/__tests__/post-routing.test.ts b/src/lib/api/__tests__/post-routing.test.ts index 9bd3e127a..9d249108c 100644 --- a/src/lib/api/__tests__/post-routing.test.ts +++ b/src/lib/api/__tests__/post-routing.test.ts @@ -6,7 +6,10 @@ import {postToSpace} from '../space-post' // `post()`'s module graph reaches the image picker, which pulls in native UI // modules that cannot load under jest. Only the write routing is under test. -jest.mock('react-native-uuid', () => ({default: {v4: () => 'test-device-id'}})) +jest.mock('react-native-uuid', () => ({ + __esModule: true, + default: {v4: () => 'test-device-id'}, +})) jest.mock('#/state/gallery', () => ({compressImage: jest.fn()})) jest.mock('#/state/queries/resolve-link', () => ({ fetchResolveGifQuery: jest.fn(), @@ -57,15 +60,18 @@ const threadWith = (space?: string) => }, }) as never -function mockAgent() { +function mockClient() { const fetchHandler = jest.fn() - const applyWrites = jest.fn(() => Promise.resolve({})) + const applyWrites = jest.fn((_input: unknown) => Promise.resolve({})) + const client = { + did: 'did:plc:alice', + assertDid: 'did:plc:alice', + agent: {fetchHandler}, + call: (_method: unknown, input: unknown) => applyWrites(input), + } as unknown as Client return { - agent: { - assertDid: 'did:plc:alice', - fetchHandler, - com: {atproto: {repo: {applyWrites}}}, - } as unknown as AtpAgent, + client, + clients: {appviewClient: client, chatClient: client, pdsClient: client}, fetchHandler, applyWrites, } @@ -77,11 +83,12 @@ describe('post routing', () => { beforeEach(() => jest.clearAllMocks()) it('sends a space-backed feed down the space write path', async () => { - const {client, fetchHandler, applyWrites} = mockAgent() + const {clients, fetchHandler, applyWrites} = mockClient() - await post(client, queryClient, {thread: threadWith(SPACE)}) + await post(queryClient, {...clients, thread: threadWith(SPACE)}) - expect(postToSpace).toHaveBeenCalledWith(client, queryClient, SPACE, { + expect(postToSpace).toHaveBeenCalledWith(queryClient, SPACE, { + ...clients, thread: threadWith(SPACE), }) // Nothing may reach the appview or the public repo on this path. @@ -90,9 +97,9 @@ describe('post routing', () => { }) it('leaves a feed without a space on the community path', async () => { - const {client, applyWrites} = mockAgent() + const {clients, applyWrites} = mockClient() - await post(client, queryClient, {thread: threadWith(undefined)}) + await post(queryClient, {...clients, thread: threadWith(undefined)}) expect(postToSpace).not.toHaveBeenCalled() expect(applyWrites).toHaveBeenCalled() @@ -103,9 +110,10 @@ describe('self labels', () => { beforeEach(() => jest.clearAllMocks()) it('publishes a text-only post with its self labels', async () => { - const {client, applyWrites} = mockAgent() + const {clients, applyWrites} = mockClient() - await post(client, queryClient, { + await post(queryClient, { + ...clients, thread: { posts: [ { @@ -160,10 +168,10 @@ describe('quoting a space post from outside the space', () => { ])( 'refuses %s rather than writing it to the public repo', async (_n, uri) => { - const {client, applyWrites, fetchHandler} = mockAgent() + const {clients, applyWrites, fetchHandler} = mockClient() await expect( - post(client, queryClient, {thread: threadQuoting(uri)}), + post(queryClient, {...clients, thread: threadQuoting(uri)}), ).rejects.toThrow(/private post/) expect(applyWrites).not.toHaveBeenCalled() @@ -178,9 +186,10 @@ describe('quoting a space post from outside the space', () => { ])( 'allows the quote when the post goes into that space (%s)', async (_n, extra) => { - const {client} = mockAgent() + const {clients} = mockClient() - await post(client, queryClient, { + await post(queryClient, { + ...clients, thread: { ...(threadQuoting(permalink, SPACE) as object), ...extra, @@ -218,30 +227,33 @@ describe('quotedSpace', () => { describe('space replies', () => { it('passes the reply target down to the space write path', async () => { - const {client} = mockAgent() + const {clients} = mockClient() const parent = `${SPACE}/did:plc:bob/app.bsky.feed.post/3kparent` - await post(client, queryClient, { + await post(queryClient, { + ...clients, thread: threadWith(SPACE), replyTo: parent, }) // postToSpace resolves the parent itself; what matters here is that the // reply is routed into the space at all rather than posted publicly. - expect(postToSpace).toHaveBeenCalledWith(client, queryClient, SPACE, { + expect(postToSpace).toHaveBeenCalledWith(queryClient, SPACE, { + ...clients, thread: threadWith(SPACE), replyTo: parent, }) }) it('reconstructs the space target when the reply view omitted it', async () => { - const {client} = mockAgent() + const {clients} = mockClient() const parent = `${SPACE}/did:plc:bob/app.bsky.feed.post/3kparent` const thread = threadWith(undefined) - await post(client, queryClient, {thread, replyTo: parent}) + await post(queryClient, {...clients, thread, replyTo: parent}) - expect(postToSpace).toHaveBeenCalledWith(client, queryClient, SPACE, { + expect(postToSpace).toHaveBeenCalledWith(queryClient, SPACE, { + ...clients, thread, replyTo: parent, }) @@ -252,47 +264,39 @@ describe('resolveReply public-path guard', () => { const publicParent = 'at://did:plc:bob/app.bsky.feed.post/3kparent' const spaceRecord = `${SPACE}/did:plc:bob/app.bsky.feed.post/3kroot` - const agentReturningRoot = (rootUri: string) => + const clientReturningRoot = (rootUri: string) => ({ - app: { - bsky: { - feed: { - getPosts: jest.fn(() => - Promise.resolve({ - data: { - posts: [ - { - uri: publicParent, - cid: 'bafyreiparent', - record: { - $type: 'app.bsky.feed.post', - text: 'hi', - createdAt: '2026-08-09T12:00:00.000Z', - reply: { - root: {uri: rootUri, cid: 'bafyreiroot'}, - parent: {uri: publicParent, cid: 'bafyreiparent'}, - }, - }, - }, - ], + call: jest.fn(() => + Promise.resolve({ + posts: [ + { + uri: publicParent, + cid: 'bafyreiparent', + record: { + $type: 'app.bsky.feed.post', + text: 'hi', + createdAt: '2026-08-09T12:00:00.000Z', + reply: { + root: {uri: rootUri, cid: 'bafyreiroot'}, + parent: {uri: publicParent, cid: 'bafyreiparent'}, }, - }), - ), - }, - }, - }, - }) as unknown as AtpAgent + }, + }, + ], + }), + ), + }) as unknown as Client it('refuses to hand a space thread root to the public write path', async () => { await expect( - resolveReply(agentReturningRoot(spaceRecord), publicParent), + resolveReply(clientReturningRoot(spaceRecord), publicParent), ).rejects.toThrow(/private post/i) }) it('passes an ordinary thread root through', async () => { const root = 'at://did:plc:bob/app.bsky.feed.post/3kroot' await expect( - resolveReply(agentReturningRoot(root), publicParent), + resolveReply(clientReturningRoot(root), publicParent), ).resolves.toEqual({ root: {uri: root, cid: 'bafyreiroot'}, parent: {uri: publicParent, cid: 'bafyreiparent'},