@atproto/bsky 0.0.151 → 0.0.152

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/api/app/bsky/unspecced/getPostThreadHiddenV2.d.ts +4 -0
  3. package/dist/api/app/bsky/unspecced/getPostThreadHiddenV2.d.ts.map +1 -0
  4. package/dist/api/app/bsky/unspecced/getPostThreadHiddenV2.js +76 -0
  5. package/dist/api/app/bsky/unspecced/getPostThreadHiddenV2.js.map +1 -0
  6. package/dist/api/app/bsky/unspecced/getPostThreadV2.d.ts +4 -0
  7. package/dist/api/app/bsky/unspecced/getPostThreadV2.d.ts.map +1 -0
  8. package/dist/api/app/bsky/unspecced/getPostThreadV2.js +86 -0
  9. package/dist/api/app/bsky/unspecced/getPostThreadV2.js.map +1 -0
  10. package/dist/api/index.d.ts.map +1 -1
  11. package/dist/api/index.js +4 -0
  12. package/dist/api/index.js.map +1 -1
  13. package/dist/config.d.ts +2 -0
  14. package/dist/config.d.ts.map +1 -1
  15. package/dist/config.js +7 -0
  16. package/dist/config.js.map +1 -1
  17. package/dist/hydration/feed.d.ts.map +1 -1
  18. package/dist/hydration/feed.js.map +1 -1
  19. package/dist/lexicon/index.d.ts +6 -2
  20. package/dist/lexicon/index.d.ts.map +1 -1
  21. package/dist/lexicon/index.js +12 -4
  22. package/dist/lexicon/index.js.map +1 -1
  23. package/dist/lexicon/lexicons.d.ts +498 -82
  24. package/dist/lexicon/lexicons.d.ts.map +1 -1
  25. package/dist/lexicon/lexicons.js +259 -42
  26. package/dist/lexicon/lexicons.js.map +1 -1
  27. package/dist/lexicon/types/app/bsky/unspecced/getPostThreadHiddenV2.d.ts +61 -0
  28. package/dist/lexicon/types/app/bsky/unspecced/getPostThreadHiddenV2.d.ts.map +1 -0
  29. package/dist/lexicon/types/app/bsky/unspecced/getPostThreadHiddenV2.js +25 -0
  30. package/dist/lexicon/types/app/bsky/unspecced/getPostThreadHiddenV2.js.map +1 -0
  31. package/dist/lexicon/types/app/bsky/unspecced/getPostThreadV2.d.ts +92 -0
  32. package/dist/lexicon/types/app/bsky/unspecced/getPostThreadV2.d.ts.map +1 -0
  33. package/dist/lexicon/types/app/bsky/unspecced/getPostThreadV2.js +52 -0
  34. package/dist/lexicon/types/app/bsky/unspecced/getPostThreadV2.js.map +1 -0
  35. package/dist/views/index.d.ts +35 -0
  36. package/dist/views/index.d.ts.map +1 -1
  37. package/dist/views/index.js +463 -0
  38. package/dist/views/index.js.map +1 -1
  39. package/dist/views/threads-v2.d.ts +62 -0
  40. package/dist/views/threads-v2.d.ts.map +1 -0
  41. package/dist/views/threads-v2.js +180 -0
  42. package/dist/views/threads-v2.js.map +1 -0
  43. package/package.json +4 -4
  44. package/src/api/app/bsky/unspecced/getPostThreadHiddenV2.ts +116 -0
  45. package/src/api/app/bsky/unspecced/getPostThreadV2.ts +130 -0
  46. package/src/api/index.ts +4 -0
  47. package/src/config.ts +9 -0
  48. package/src/hydration/feed.ts +1 -0
  49. package/src/lexicon/index.ts +33 -9
  50. package/src/lexicon/lexicons.ts +278 -43
  51. package/src/lexicon/types/app/bsky/unspecced/getPostThreadHiddenV2.ts +93 -0
  52. package/src/lexicon/types/app/bsky/unspecced/getPostThreadV2.ts +160 -0
  53. package/src/views/index.ts +742 -0
  54. package/src/views/threads-v2.ts +351 -0
  55. package/tests/seed/thread-v2.ts +775 -0
  56. package/tests/seed/util.ts +52 -0
  57. package/tests/views/__snapshots__/thread-v2.test.ts.snap +1091 -0
  58. package/tests/views/thread-v2.test.ts +2009 -0
  59. package/tsconfig.build.tsbuildinfo +1 -1
  60. package/tsconfig.tests.tsbuildinfo +1 -1
@@ -0,0 +1,2009 @@
1
+ import assert from 'node:assert'
2
+ import {
3
+ AppBskyUnspeccedGetPostThreadHiddenV2,
4
+ AppBskyUnspeccedGetPostThreadV2,
5
+ AtpAgent,
6
+ } from '@atproto/api'
7
+ import { SeedClient, TestNetwork } from '@atproto/dev-env'
8
+ import { ids } from '../../src/lexicon/lexicons'
9
+ import {
10
+ OutputSchema as OutputSchemaHiddenThread,
11
+ ThreadHiddenItem,
12
+ ThreadHiddenItemPost,
13
+ } from '../../src/lexicon/types/app/bsky/unspecced/getPostThreadHiddenV2'
14
+ import {
15
+ OutputSchema as OutputSchemaThread,
16
+ QueryParams as QueryParamsThread,
17
+ ThreadItemPost,
18
+ } from '../../src/lexicon/types/app/bsky/unspecced/getPostThreadV2'
19
+ import { ThreadItemValuePost } from '../../src/views/threads-v2'
20
+ import { forSnapshot } from '../_util'
21
+ import * as seeds from '../seed/thread-v2'
22
+
23
+ type PostProps = Pick<ThreadItemPost, 'moreReplies' | 'opThread'>
24
+ const props = (overrides: Partial<PostProps> = {}): PostProps => ({
25
+ moreReplies: 0,
26
+ opThread: false,
27
+ ...overrides,
28
+ })
29
+
30
+ type PostPropsHidden = Pick<
31
+ ThreadHiddenItemPost,
32
+ 'hiddenByThreadgate' | 'mutedByViewer'
33
+ >
34
+ const propsHidden = (
35
+ overrides: Partial<PostPropsHidden> = {},
36
+ ): PostPropsHidden => ({
37
+ hiddenByThreadgate: false,
38
+ mutedByViewer: false,
39
+ ...overrides,
40
+ })
41
+
42
+ describe('appview thread views v2', () => {
43
+ let network: TestNetwork
44
+ let agent: AtpAgent
45
+ let labelerDid: string
46
+ let sc: SeedClient
47
+
48
+ beforeAll(async () => {
49
+ network = await TestNetwork.create({
50
+ bsky: {
51
+ maxThreadParents: 15,
52
+ },
53
+ dbPostgresSchema: 'bsky_views_thread_v_two',
54
+ })
55
+ agent = network.bsky.getClient()
56
+ sc = network.getSeedClient()
57
+ labelerDid = network.bsky.ctx.cfg.modServiceDid
58
+ await network.processAll()
59
+ })
60
+
61
+ afterAll(async () => {
62
+ await network.close()
63
+ })
64
+
65
+ describe('not found anchor', () => {
66
+ it('returns not found error', async () => {
67
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2({
68
+ anchor: 'at://did:plc:123/app.bsky.feed.post/456',
69
+ })
70
+ const { thread: t } = data
71
+
72
+ expect(t).toEqual([
73
+ expect.objectContaining({
74
+ depth: 0,
75
+ value: {
76
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemNotFound',
77
+ },
78
+ }),
79
+ ])
80
+ })
81
+ })
82
+
83
+ describe('simple thread', () => {
84
+ let seed: Awaited<ReturnType<typeof seeds.simple>>
85
+
86
+ beforeAll(async () => {
87
+ seed = await seeds.simple(sc)
88
+ await network.processAll()
89
+ })
90
+
91
+ it('returns thread anchored on root', async () => {
92
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
93
+ { anchor: seed.root.ref.uriStr },
94
+ {
95
+ headers: await network.serviceHeaders(
96
+ seed.users.op.did,
97
+ ids.AppBskyUnspeccedGetPostThreadV2,
98
+ ),
99
+ },
100
+ )
101
+ const { thread: t, hasHiddenReplies } = data
102
+
103
+ assertPosts(t)
104
+ expect(hasHiddenReplies).toBe(false)
105
+ expect(t).toEqual([
106
+ expect.objectContaining({ depth: 0, uri: seed.root.ref.uriStr }),
107
+ expect.objectContaining({ depth: 1, uri: seed.r['0'].ref.uriStr }),
108
+ expect.objectContaining({ depth: 2, uri: seed.r['0.0'].ref.uriStr }),
109
+ expect.objectContaining({ depth: 1, uri: seed.r['1'].ref.uriStr }),
110
+ expect.objectContaining({ depth: 1, uri: seed.r['2'].ref.uriStr }),
111
+ expect.objectContaining({ depth: 2, uri: seed.r['2.0'].ref.uriStr }),
112
+ expect.objectContaining({ depth: 1, uri: seed.r['3'].ref.uriStr }),
113
+ ])
114
+ expect(forSnapshot(data)).toMatchSnapshot()
115
+ })
116
+
117
+ it('returns thread anchored on r 0', async () => {
118
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
119
+ { anchor: seed.r['0'].ref.uriStr },
120
+ {
121
+ headers: await network.serviceHeaders(
122
+ seed.users.op.did,
123
+ ids.AppBskyUnspeccedGetPostThreadV2,
124
+ ),
125
+ },
126
+ )
127
+ const { thread: t, hasHiddenReplies } = data
128
+
129
+ assertPosts(t)
130
+ expect(hasHiddenReplies).toBe(false)
131
+ expect(t).toEqual([
132
+ expect.objectContaining({ depth: -1, uri: seed.root.ref.uriStr }),
133
+ expect.objectContaining({ depth: 0, uri: seed.r['0'].ref.uriStr }),
134
+ expect.objectContaining({ depth: 1, uri: seed.r['0.0'].ref.uriStr }),
135
+ ])
136
+ expect(forSnapshot(data)).toMatchSnapshot()
137
+ })
138
+
139
+ it('returns thread anchored on r 0.0', async () => {
140
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
141
+ { anchor: seed.r['0.0'].ref.uriStr },
142
+ {
143
+ headers: await network.serviceHeaders(
144
+ seed.users.op.did,
145
+ ids.AppBskyUnspeccedGetPostThreadV2,
146
+ ),
147
+ },
148
+ )
149
+ const { thread: t, hasHiddenReplies } = data
150
+
151
+ assertPosts(t)
152
+ expect(hasHiddenReplies).toBe(false)
153
+ expect(t).toEqual([
154
+ expect.objectContaining({ depth: -2, uri: seed.root.ref.uriStr }),
155
+ expect.objectContaining({ depth: -1, uri: seed.r['0'].ref.uriStr }),
156
+ expect.objectContaining({ depth: 0, uri: seed.r['0.0'].ref.uriStr }),
157
+ ])
158
+ expect(forSnapshot(data)).toMatchSnapshot()
159
+ })
160
+
161
+ it('returns thread anchored on 1', async () => {
162
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
163
+ { anchor: seed.r['1'].ref.uriStr },
164
+ {
165
+ headers: await network.serviceHeaders(
166
+ seed.users.op.did,
167
+ ids.AppBskyUnspeccedGetPostThreadV2,
168
+ ),
169
+ },
170
+ )
171
+ const { thread: t, hasHiddenReplies } = data
172
+
173
+ assertPosts(t)
174
+ expect(hasHiddenReplies).toBe(false)
175
+ expect(t).toEqual([
176
+ expect.objectContaining({ depth: -1, uri: seed.root.ref.uriStr }),
177
+ expect.objectContaining({ depth: 0, uri: seed.r['1'].ref.uriStr }),
178
+ ])
179
+ expect(forSnapshot(data)).toMatchSnapshot()
180
+ })
181
+
182
+ it('returns thread anchored on 2', async () => {
183
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
184
+ { anchor: seed.r['2'].ref.uriStr },
185
+ {
186
+ headers: await network.serviceHeaders(
187
+ seed.users.op.did,
188
+ ids.AppBskyUnspeccedGetPostThreadV2,
189
+ ),
190
+ },
191
+ )
192
+ const { thread: t, hasHiddenReplies } = data
193
+
194
+ assertPosts(t)
195
+ expect(hasHiddenReplies).toBe(false)
196
+ expect(t).toEqual([
197
+ expect.objectContaining({ depth: -1, uri: seed.root.ref.uriStr }),
198
+ expect.objectContaining({ depth: 0, uri: seed.r['2'].ref.uriStr }),
199
+ expect.objectContaining({ depth: 1, uri: seed.r['2.0'].ref.uriStr }),
200
+ ])
201
+ expect(forSnapshot(data)).toMatchSnapshot()
202
+ })
203
+
204
+ it('returns thread anchored on 2.0', async () => {
205
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
206
+ { anchor: seed.r['2.0'].ref.uriStr },
207
+ {
208
+ headers: await network.serviceHeaders(
209
+ seed.users.op.did,
210
+ ids.AppBskyUnspeccedGetPostThreadV2,
211
+ ),
212
+ },
213
+ )
214
+ const { thread: t, hasHiddenReplies } = data
215
+
216
+ assertPosts(t)
217
+ expect(hasHiddenReplies).toBe(false)
218
+ expect(t).toEqual([
219
+ expect.objectContaining({ depth: -2, uri: seed.root.ref.uriStr }),
220
+ expect.objectContaining({ depth: -1, uri: seed.r['2'].ref.uriStr }),
221
+ expect.objectContaining({ depth: 0, uri: seed.r['2.0'].ref.uriStr }),
222
+ ])
223
+ expect(forSnapshot(data)).toMatchSnapshot()
224
+ })
225
+
226
+ it('returns thread anchored on 3', async () => {
227
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
228
+ { anchor: seed.r['3'].ref.uriStr },
229
+ {
230
+ headers: await network.serviceHeaders(
231
+ seed.users.op.did,
232
+ ids.AppBskyUnspeccedGetPostThreadV2,
233
+ ),
234
+ },
235
+ )
236
+ const { thread: t, hasHiddenReplies } = data
237
+
238
+ assertPosts(t)
239
+ expect(hasHiddenReplies).toBe(false)
240
+ expect(t).toEqual([
241
+ expect.objectContaining({ depth: -1, uri: seed.root.ref.uriStr }),
242
+ expect.objectContaining({ depth: 0, uri: seed.r['3'].ref.uriStr }),
243
+ ])
244
+ expect(forSnapshot(data)).toMatchSnapshot()
245
+ })
246
+ })
247
+
248
+ describe('long thread', () => {
249
+ let seed: Awaited<ReturnType<typeof seeds.long>>
250
+
251
+ beforeAll(async () => {
252
+ seed = await seeds.long(sc)
253
+ await network.processAll()
254
+ })
255
+
256
+ describe('calculating depth', () => {
257
+ type Case = {
258
+ postKey: string
259
+ }
260
+
261
+ const cases: Case[] = [
262
+ { postKey: 'root' },
263
+ { postKey: '0' },
264
+ { postKey: '0.0' },
265
+ { postKey: '0.0.0' },
266
+ { postKey: '0.0.0.0' },
267
+ { postKey: '0.0.0.0.0' },
268
+ { postKey: '0.0.1' },
269
+ { postKey: '1' },
270
+ { postKey: '2' },
271
+ { postKey: '3' },
272
+ { postKey: '4' },
273
+ { postKey: '4.0' },
274
+ { postKey: '4.0.0' },
275
+ { postKey: '4.0.0.0' },
276
+ { postKey: '4.0.0.0.0' },
277
+ { postKey: '5' },
278
+ { postKey: '6' },
279
+ { postKey: '7' },
280
+ ]
281
+
282
+ it.each(cases)(
283
+ 'calculates the depths anchored at $postKey',
284
+ async ({ postKey }) => {
285
+ const post = postKey === 'root' ? seed.root : seed.r[postKey]
286
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
287
+ { anchor: post.ref.uriStr },
288
+ {
289
+ headers: await network.serviceHeaders(
290
+ seed.users.op.did,
291
+ ids.AppBskyUnspeccedGetPostThreadV2,
292
+ ),
293
+ },
294
+ )
295
+ const { thread: t, hasHiddenReplies } = data
296
+
297
+ assertPosts(t)
298
+ expect(hasHiddenReplies).toBe(false)
299
+ const anchorIndex = t.findIndex((i) => i.uri === post.ref.uriStr)
300
+ const anchorPost = t[anchorIndex]
301
+
302
+ const parents = t.slice(0, anchorIndex)
303
+ const children = t.slice(anchorIndex + 1, t.length)
304
+
305
+ parents.forEach((parent) => {
306
+ expect(parent.depth).toBeLessThan(0)
307
+ })
308
+ expect(anchorPost.depth).toEqual(0)
309
+ children.forEach((child) => {
310
+ expect(child.depth).toBeGreaterThan(0)
311
+ })
312
+ },
313
+ )
314
+ })
315
+ })
316
+
317
+ describe('deep thread', () => {
318
+ let seed: Awaited<ReturnType<typeof seeds.deep>>
319
+
320
+ beforeAll(async () => {
321
+ seed = await seeds.deep(sc)
322
+ await network.processAll()
323
+ })
324
+
325
+ describe('above', () => {
326
+ it('returns the ancestors above if true (default)', async () => {
327
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
328
+ {
329
+ anchor: seed.r['0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'].ref.uriStr,
330
+ },
331
+ {
332
+ headers: await network.serviceHeaders(
333
+ seed.users.op.did,
334
+ ids.AppBskyUnspeccedGetPostThreadV2,
335
+ ),
336
+ },
337
+ )
338
+ const { thread: t, hasHiddenReplies } = data
339
+
340
+ assertPosts(t)
341
+ expect(hasHiddenReplies).toBe(false)
342
+ expect(t).toHaveLength(16) // anchor + 15 ancestors, as limited by `maxThreadParents`.
343
+
344
+ const first = t.at(0)
345
+ expect(first!.uri).toBe(seed.r['0.0.0'].ref.uriStr)
346
+ expect(first!.value.moreParents).toBe(true)
347
+
348
+ const second = t.at(1)
349
+ expect(second!.uri).toBe(seed.r['0.0.0.0'].ref.uriStr)
350
+ expect(second!.value.moreParents).toBe(false)
351
+
352
+ const last = t.at(-1)
353
+ expect(last!.uri).toBe(
354
+ seed.r['0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'].ref.uriStr,
355
+ )
356
+ expect(last!.value.moreParents).toBe(false)
357
+ })
358
+
359
+ it(`does not return ancestors if false`, async () => {
360
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
361
+ {
362
+ anchor: seed.r['0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'].ref.uriStr,
363
+ above: false,
364
+ },
365
+ {
366
+ headers: await network.serviceHeaders(
367
+ seed.users.op.did,
368
+ ids.AppBskyUnspeccedGetPostThreadV2,
369
+ ),
370
+ },
371
+ )
372
+ const { thread: t, hasHiddenReplies } = data
373
+
374
+ assertPosts(t)
375
+ expect(hasHiddenReplies).toBe(false)
376
+ expect(t).toHaveLength(1)
377
+
378
+ const first = t.at(0)
379
+ expect(first!.uri).toBe(
380
+ seed.r['0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'].ref.uriStr,
381
+ )
382
+ })
383
+ })
384
+
385
+ describe('below', () => {
386
+ it('limits to the below count', async () => {
387
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
388
+ {
389
+ anchor: seed.root.ref.uriStr,
390
+ below: 10,
391
+ },
392
+ {
393
+ headers: await network.serviceHeaders(
394
+ seed.users.op.did,
395
+ ids.AppBskyUnspeccedGetPostThreadV2,
396
+ ),
397
+ },
398
+ )
399
+ const { thread: t, hasHiddenReplies } = data
400
+
401
+ assertPosts(t)
402
+ expect(hasHiddenReplies).toBe(false)
403
+ expect(t).toHaveLength(11)
404
+ const first = t.at(0)
405
+ expect(first!.uri).toBe(seed.root.ref.uriStr)
406
+ })
407
+
408
+ it(`does not fulfill the below count if there are not enough items in the thread`, async () => {
409
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
410
+ {
411
+ anchor: seed.r['0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'].ref.uriStr,
412
+ above: false,
413
+ below: 10,
414
+ },
415
+ {
416
+ headers: await network.serviceHeaders(
417
+ seed.users.op.did,
418
+ ids.AppBskyUnspeccedGetPostThreadV2,
419
+ ),
420
+ },
421
+ )
422
+ const { thread: t, hasHiddenReplies } = data
423
+
424
+ assertPosts(t)
425
+ expect(hasHiddenReplies).toBe(false)
426
+ expect(t).toHaveLength(4)
427
+
428
+ const first = t.at(0)
429
+ expect(first!.uri).toBe(
430
+ seed.r['0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'].ref.uriStr,
431
+ )
432
+ })
433
+ })
434
+ })
435
+
436
+ describe('branching factor', () => {
437
+ let seed: Awaited<ReturnType<typeof seeds.branchingFactor>>
438
+
439
+ beforeAll(async () => {
440
+ seed = await seeds.branchingFactor(sc)
441
+ await network.processAll()
442
+ })
443
+
444
+ type Case =
445
+ | {
446
+ branchingFactor: number
447
+ sort: QueryParamsThread['sort']
448
+ postKeys: string[]
449
+ }
450
+ | {
451
+ branchingFactor: number
452
+ sort: QueryParamsThread['sort']
453
+ // For higher branching factors it gets too verbose to write all posts.
454
+ length: number
455
+ }
456
+ const cases: Case[] = [
457
+ {
458
+ branchingFactor: 1,
459
+ sort: 'oldest',
460
+ postKeys: [
461
+ 'root',
462
+ '0',
463
+ '0.0',
464
+ '0.0.0',
465
+ '1',
466
+ '1.0',
467
+ '1.0.0',
468
+ '2',
469
+ '2.0',
470
+ '2.0.0',
471
+ '3',
472
+ '3.0',
473
+ '3.0.0',
474
+ ],
475
+ },
476
+ {
477
+ branchingFactor: 1,
478
+ sort: 'newest',
479
+ postKeys: [
480
+ 'root',
481
+ '3',
482
+ '3.3',
483
+ '3.3.3',
484
+ '2',
485
+ '2.3',
486
+ '2.3.3',
487
+ '1',
488
+ '1.3',
489
+ '1.3.3',
490
+ '0',
491
+ '0.3',
492
+ '0.3.3',
493
+ ],
494
+ },
495
+ {
496
+ branchingFactor: 2,
497
+ sort: 'oldest',
498
+ postKeys: [
499
+ 'root',
500
+ '0',
501
+ '0.0',
502
+ '0.0.0',
503
+ '0.0.1',
504
+ '0.1',
505
+ '0.1.0',
506
+ '0.1.1',
507
+ '1',
508
+ '1.0',
509
+ '1.0.0',
510
+ '1.1',
511
+ '1.1.0',
512
+ '1.1.1',
513
+ '2',
514
+ '2.0',
515
+ '2.0.0',
516
+ '2.0.1',
517
+ '2.1',
518
+ '2.1.0',
519
+ '2.1.1',
520
+ '3',
521
+ '3.0',
522
+ '3.0.0',
523
+ '3.0.1',
524
+ '3.1',
525
+ '3.1.0',
526
+ '3.1.1',
527
+ ],
528
+ },
529
+ {
530
+ branchingFactor: 2,
531
+ sort: 'newest',
532
+ postKeys: [
533
+ 'root',
534
+ '3',
535
+ '3.3',
536
+ '3.3.3',
537
+ '3.3.2',
538
+ '3.2',
539
+ '3.2.3',
540
+ '3.2.2',
541
+ '2',
542
+ '2.3',
543
+ '2.3.3',
544
+ '2.3.2',
545
+ '2.2',
546
+ '2.2.3',
547
+ '2.2.2',
548
+ '1',
549
+ '1.3',
550
+ '1.3.3',
551
+ '1.3.2',
552
+ '1.2',
553
+ '1.2.3',
554
+ '1.2.2',
555
+ '0',
556
+ '0.3',
557
+ '0.3.3',
558
+ '0.3.2',
559
+ '0.2',
560
+ '0.2.3',
561
+ '0.2.2',
562
+ ],
563
+ },
564
+ {
565
+ branchingFactor: 3,
566
+ sort: 'newest',
567
+ length: 53,
568
+ },
569
+ {
570
+ branchingFactor: 4,
571
+ sort: 'newest',
572
+ length: 82,
573
+ },
574
+ {
575
+ branchingFactor: 5,
576
+ sort: 'newest',
577
+ // The seeds have 1 post with 5 replies, so it is +1 compared to branchingFactor 4.
578
+ length: 83,
579
+ },
580
+ ]
581
+
582
+ it.each(cases)(
583
+ 'returns all top-level replies and limits nested to branching factor of $branchingFactor when sorting by $sort',
584
+ async (args) => {
585
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
586
+ {
587
+ anchor: seed.root.ref.uriStr,
588
+ sort: 'sort' in args ? args.sort : undefined,
589
+ branchingFactor: args.branchingFactor,
590
+ },
591
+ {
592
+ headers: await network.serviceHeaders(
593
+ seed.users.op.did,
594
+ ids.AppBskyUnspeccedGetPostThreadV2,
595
+ ),
596
+ },
597
+ )
598
+ const { thread: t, hasHiddenReplies } = data
599
+
600
+ assertPosts(t)
601
+ expect(hasHiddenReplies).toBe(false)
602
+ if ('length' in args) {
603
+ expect(data.thread).toHaveLength(args.length)
604
+ } else {
605
+ const tUris = t.map((i) => i.uri)
606
+ const postUris = args.postKeys.map((k) =>
607
+ k === 'root' ? seed.root.ref.uriStr : seed.r[k].ref.uriStr,
608
+ )
609
+ expect(tUris).toEqual(postUris)
610
+ }
611
+ },
612
+ )
613
+ })
614
+
615
+ describe('annotate more replies', () => {
616
+ let seed: Awaited<ReturnType<typeof seeds.annotateMoreReplies>>
617
+
618
+ beforeAll(async () => {
619
+ seed = await seeds.annotateMoreReplies(sc)
620
+ await network.processAll()
621
+ })
622
+
623
+ it('annotates correctly both in cases of trimmed replies by depth and by branching factor reached', async () => {
624
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
625
+ {
626
+ anchor: seed.root.ref.uriStr,
627
+ below: 4,
628
+ branchingFactor: 2,
629
+ },
630
+ {
631
+ headers: await network.serviceHeaders(
632
+ seed.users.op.did,
633
+ ids.AppBskyUnspeccedGetPostThreadV2,
634
+ ),
635
+ },
636
+ )
637
+ const { thread: t, hasHiddenReplies } = data
638
+
639
+ assertPosts(t)
640
+ expect(hasHiddenReplies).toBe(false)
641
+ expect(t).toEqual([
642
+ expect.objectContaining({
643
+ uri: seed.root.ref.uriStr,
644
+ value: expect.objectContaining(props({ opThread: true })),
645
+ }),
646
+ expect.objectContaining({
647
+ uri: seed.r['0'].ref.uriStr,
648
+ value: expect.objectContaining(props()),
649
+ }),
650
+ expect.objectContaining({
651
+ uri: seed.r['0.0'].ref.uriStr,
652
+ value: expect.objectContaining(props()),
653
+ }),
654
+ expect.objectContaining({
655
+ uri: seed.r['0.0.0'].ref.uriStr,
656
+ value: expect.objectContaining(props()),
657
+ }),
658
+ expect.objectContaining({
659
+ uri: seed.r['0.0.0.0'].ref.uriStr,
660
+ value: expect.objectContaining(props({ moreReplies: 5 })),
661
+ }),
662
+ expect.objectContaining({
663
+ uri: seed.r['0.1'].ref.uriStr,
664
+ value: expect.objectContaining(props()),
665
+ }),
666
+ expect.objectContaining({
667
+ uri: seed.r['0.1.0'].ref.uriStr,
668
+ value: expect.objectContaining(props()),
669
+ }),
670
+ expect.objectContaining({
671
+ uri: seed.r['0.1.0.0'].ref.uriStr,
672
+ value: expect.objectContaining(props()),
673
+ }),
674
+ expect.objectContaining({
675
+ uri: seed.r['1'].ref.uriStr,
676
+ value: expect.objectContaining(props({ moreReplies: 1 })),
677
+ }),
678
+ expect.objectContaining({
679
+ uri: seed.r['1.0'].ref.uriStr,
680
+ value: expect.objectContaining(props({ moreReplies: 3 })),
681
+ }),
682
+ expect.objectContaining({
683
+ uri: seed.r['1.0.0'].ref.uriStr,
684
+ value: expect.objectContaining(props()),
685
+ }),
686
+ expect.objectContaining({
687
+ uri: seed.r['1.0.1'].ref.uriStr,
688
+ value: expect.objectContaining(props()),
689
+ }),
690
+ expect.objectContaining({
691
+ uri: seed.r['1.1'].ref.uriStr,
692
+ value: expect.objectContaining(props()),
693
+ }),
694
+ expect.objectContaining({
695
+ uri: seed.r['1.1.0'].ref.uriStr,
696
+ value: expect.objectContaining(props()),
697
+ }),
698
+ expect.objectContaining({
699
+ uri: seed.r['1.1.1'].ref.uriStr,
700
+ value: expect.objectContaining(props()),
701
+ }),
702
+ expect.objectContaining({
703
+ uri: seed.r['2'].ref.uriStr,
704
+ value: expect.objectContaining(props()),
705
+ }),
706
+ ])
707
+ })
708
+ })
709
+
710
+ describe(`annotate OP thread`, () => {
711
+ let seed: Awaited<ReturnType<typeof seeds.annotateOP>>
712
+
713
+ beforeAll(async () => {
714
+ seed = await seeds.annotateOP(sc)
715
+ await network.processAll()
716
+ })
717
+
718
+ type Case = {
719
+ postKey: string
720
+ length: number
721
+ opThreadPostKeys: string[]
722
+ }
723
+
724
+ const cases: Case[] = [
725
+ {
726
+ postKey: 'root',
727
+ length: 9,
728
+ opThreadPostKeys: ['root', '0', '0.0', '0.0.0', '2'],
729
+ },
730
+ {
731
+ postKey: '0',
732
+ length: 4,
733
+ opThreadPostKeys: ['root', '0', '0.0', '0.0.0'],
734
+ },
735
+ {
736
+ postKey: '0.0',
737
+ length: 4,
738
+ opThreadPostKeys: ['root', '0', '0.0', '0.0.0'],
739
+ },
740
+ {
741
+ postKey: '0.0.0',
742
+ length: 4,
743
+ opThreadPostKeys: ['root', '0', '0.0', '0.0.0'],
744
+ },
745
+ {
746
+ postKey: '1',
747
+ length: 3,
748
+ opThreadPostKeys: ['root'],
749
+ },
750
+ {
751
+ postKey: '1.0',
752
+ length: 3,
753
+ opThreadPostKeys: ['root'],
754
+ },
755
+ {
756
+ postKey: '2',
757
+ length: 4,
758
+ opThreadPostKeys: ['root', '2'],
759
+ },
760
+ {
761
+ postKey: '2.0',
762
+ length: 4,
763
+ opThreadPostKeys: ['root', '2'],
764
+ },
765
+ {
766
+ postKey: '2.0.0',
767
+ length: 4,
768
+ opThreadPostKeys: ['root', '2'],
769
+ },
770
+ ]
771
+
772
+ it.each(cases)(
773
+ `annotates OP threads correctly anchored at $postKey`,
774
+ async ({ postKey, length, opThreadPostKeys: opThreadPosts }) => {
775
+ const post = postKey === 'root' ? seed.root : seed.r[postKey]
776
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
777
+ { anchor: post.ref.uriStr },
778
+ {
779
+ headers: await network.serviceHeaders(
780
+ seed.users.op.did,
781
+ ids.AppBskyUnspeccedGetPostThreadV2,
782
+ ),
783
+ },
784
+ )
785
+ const { thread: t, hasHiddenReplies } = data
786
+
787
+ assertPosts(t)
788
+ expect(hasHiddenReplies).toBe(false)
789
+ const opThreadPostsUris = new Set(
790
+ opThreadPosts.map((k) =>
791
+ k === 'root' ? seed.root.ref.uriStr : seed.r[k].ref.uriStr,
792
+ ),
793
+ )
794
+
795
+ expect(t).toHaveLength(length)
796
+ t.forEach((i) => {
797
+ expect(i.value.opThread).toBe(opThreadPostsUris.has(i.uri))
798
+ })
799
+ },
800
+ )
801
+ })
802
+
803
+ describe('bumping and sorting', () => {
804
+ describe('sorting', () => {
805
+ let seed: Awaited<ReturnType<typeof seeds.sort>>
806
+
807
+ beforeAll(async () => {
808
+ seed = await seeds.sort(sc)
809
+ await network.processAll()
810
+ })
811
+
812
+ type Case = {
813
+ sort: QueryParamsThread['sort']
814
+ postKeys: string[]
815
+ }
816
+
817
+ const cases: Case[] = [
818
+ {
819
+ sort: 'newest',
820
+ postKeys: [
821
+ 'root',
822
+ '2',
823
+ '2.2',
824
+ '2.1',
825
+ '2.0',
826
+ '1',
827
+ '1.2',
828
+ '1.1',
829
+ '1.0',
830
+ '0',
831
+ '0.2',
832
+ '0.1',
833
+ '0.0',
834
+ ],
835
+ },
836
+ {
837
+ sort: 'oldest',
838
+ postKeys: [
839
+ 'root',
840
+ '0',
841
+ '0.0',
842
+ '0.1',
843
+ '0.2',
844
+ '1',
845
+ '1.0',
846
+ '1.1',
847
+ '1.2',
848
+ '2',
849
+ '2.0',
850
+ '2.1',
851
+ '2.2',
852
+ ],
853
+ },
854
+ {
855
+ sort: 'top',
856
+ postKeys: [
857
+ 'root',
858
+ '1',
859
+ '1.1',
860
+ '1.0',
861
+ '1.2',
862
+ '2',
863
+ '2.0',
864
+ '2.1',
865
+ '2.2',
866
+ '0',
867
+ '0.2',
868
+ '0.1',
869
+ '0.0',
870
+ ],
871
+ },
872
+ ]
873
+
874
+ it.each(cases)(
875
+ 'sorts by $sort in all levels',
876
+ async ({ sort: sort, postKeys }) => {
877
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
878
+ {
879
+ anchor: seed.root.ref.uriStr,
880
+ sort,
881
+ },
882
+ {
883
+ headers: await network.serviceHeaders(
884
+ seed.users.op.did,
885
+ ids.AppBskyUnspeccedGetPostThreadV2,
886
+ ),
887
+ },
888
+ )
889
+ const { thread: t, hasHiddenReplies } = data
890
+
891
+ assertPosts(t)
892
+ expect(hasHiddenReplies).toBe(false)
893
+ const tUris = t.map((i) => i.uri)
894
+ const postUris = postKeys.map((k) =>
895
+ k === 'root' ? seed.root.ref.uriStr : seed.r[k].ref.uriStr,
896
+ )
897
+ expect(tUris).toEqual(postUris)
898
+ },
899
+ )
900
+ })
901
+
902
+ describe('bumping', () => {
903
+ describe('sorting within bumped post groups', () => {
904
+ let seed: Awaited<ReturnType<typeof seeds.bumpGroupSorting>>
905
+
906
+ beforeAll(async () => {
907
+ seed = await seeds.bumpGroupSorting(sc)
908
+ await network.processAll()
909
+ })
910
+
911
+ type Case = {
912
+ sort: QueryParamsThread['sort']
913
+ postKeys: string[]
914
+ }
915
+
916
+ const cases: Case[] = [
917
+ {
918
+ sort: 'newest',
919
+ postKeys: ['root', '5', '3', '1', '7', '4', '0', '6', '2'],
920
+ },
921
+ {
922
+ sort: 'oldest',
923
+ postKeys: ['root', '1', '3', '5', '0', '4', '7', '2', '6'],
924
+ },
925
+ ]
926
+
927
+ it.each(cases)(
928
+ 'sorts by $sort inside each bumped group',
929
+ async ({ sort: sort, postKeys }) => {
930
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
931
+ {
932
+ anchor: seed.root.ref.uriStr,
933
+ sort,
934
+ },
935
+ {
936
+ headers: await network.serviceHeaders(
937
+ seed.users.viewer.did,
938
+ ids.AppBskyUnspeccedGetPostThreadV2,
939
+ ),
940
+ },
941
+ )
942
+ const { thread: t, hasHiddenReplies } = data
943
+
944
+ assertPosts(t)
945
+ expect(hasHiddenReplies).toBe(false)
946
+ const tUris = t.map((i) => i.uri)
947
+ const postUris = postKeys.map((k) =>
948
+ k === 'root' ? seed.root.ref.uriStr : seed.r[k].ref.uriStr,
949
+ )
950
+ expect(tUris).toEqual(postUris)
951
+ },
952
+ )
953
+ })
954
+
955
+ describe('OP and viewer', () => {
956
+ let seed: Awaited<ReturnType<typeof seeds.bumpOpAndViewer>>
957
+
958
+ beforeAll(async () => {
959
+ seed = await seeds.bumpOpAndViewer(sc)
960
+ await network.processAll()
961
+ })
962
+
963
+ type Case = {
964
+ sort: QueryParamsThread['sort']
965
+ postKeys: string[]
966
+ }
967
+
968
+ const cases: Case[] = [
969
+ {
970
+ sort: 'newest',
971
+ postKeys: [
972
+ 'root',
973
+ '3', // op
974
+ '3.2', // op
975
+ '3.0', // viewer
976
+ '3.4',
977
+ '3.3',
978
+ '3.1',
979
+ '4', // viewer
980
+ '4.2', // op
981
+ '4.3', // viewer
982
+ '4.4',
983
+ '4.1',
984
+ '4.0',
985
+ '2',
986
+ '2.2', // op
987
+ '2.0', // viewer
988
+ '2.4',
989
+ '2.3',
990
+ '2.1',
991
+ '1',
992
+ '1.2', // op
993
+ '1.3', // viewer
994
+ '1.4',
995
+ '1.1',
996
+ '1.0',
997
+ '0',
998
+ '0.4', // op
999
+ '0.3', // viewer
1000
+ '0.2',
1001
+ '0.1',
1002
+ '0.0',
1003
+ ],
1004
+ },
1005
+ {
1006
+ sort: 'oldest',
1007
+ postKeys: [
1008
+ 'root',
1009
+ '3', // op
1010
+ '3.2', // op
1011
+ '3.0', // viewer
1012
+ '3.1',
1013
+ '3.3',
1014
+ '3.4',
1015
+ '4', // viewer
1016
+ '4.2', // op
1017
+ '4.3', // viewer
1018
+ '4.0',
1019
+ '4.1',
1020
+ '4.4',
1021
+ '0',
1022
+ '0.4', // op
1023
+ '0.3', // viewer
1024
+ '0.0',
1025
+ '0.1',
1026
+ '0.2',
1027
+ '1',
1028
+ '1.2', // op
1029
+ '1.3', // viewer
1030
+ '1.0',
1031
+ '1.1',
1032
+ '1.4',
1033
+ '2',
1034
+ '2.2', // op
1035
+ '2.0', // viewer
1036
+ '2.1',
1037
+ '2.3',
1038
+ '2.4',
1039
+ ],
1040
+ },
1041
+ {
1042
+ sort: 'top',
1043
+ postKeys: [
1044
+ 'root',
1045
+ '3', // op
1046
+ '3.2', // op
1047
+ '3.0', // viewer
1048
+ '3.4',
1049
+ '3.3',
1050
+ '3.1',
1051
+ '4', // viewer
1052
+ '4.2', // op
1053
+ '4.3', // viewer
1054
+ '4.1',
1055
+ '4.0',
1056
+ '4.4',
1057
+ '1',
1058
+ '1.2', // op
1059
+ '1.3', // viewer
1060
+ '1.1',
1061
+ '1.0',
1062
+ '1.4',
1063
+ '2',
1064
+ '2.2', // op
1065
+ '2.0', // viewer
1066
+ '2.1',
1067
+ '2.4',
1068
+ '2.3',
1069
+ '0',
1070
+ '0.4', // op
1071
+ '0.3', // viewer
1072
+ '0.2',
1073
+ '0.1',
1074
+ '0.0',
1075
+ ],
1076
+ },
1077
+ ]
1078
+
1079
+ it.each(cases)(
1080
+ 'bumps up OP and viewer and sorts by $sort in all levels',
1081
+ async ({ sort: sort, postKeys }) => {
1082
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1083
+ {
1084
+ anchor: seed.root.ref.uriStr,
1085
+ sort,
1086
+ },
1087
+ {
1088
+ headers: await network.serviceHeaders(
1089
+ seed.users.viewer.did,
1090
+ ids.AppBskyUnspeccedGetPostThreadV2,
1091
+ ),
1092
+ },
1093
+ )
1094
+ const { thread: t, hasHiddenReplies } = data
1095
+
1096
+ assertPosts(t)
1097
+ expect(hasHiddenReplies).toBe(false)
1098
+ const tUris = t.map((i) => i.uri)
1099
+ const postUris = postKeys.map((k) =>
1100
+ k === 'root' ? seed.root.ref.uriStr : seed.r[k].ref.uriStr,
1101
+ )
1102
+ expect(tUris).toEqual(postUris)
1103
+ },
1104
+ )
1105
+ })
1106
+
1107
+ describe('followers', () => {
1108
+ let seed: Awaited<ReturnType<typeof seeds.bumpFollows>>
1109
+
1110
+ beforeAll(async () => {
1111
+ seed = await seeds.bumpFollows(sc)
1112
+ await network.processAll()
1113
+ })
1114
+
1115
+ const threadForPostAndViewer = async (
1116
+ post: string,
1117
+ viewer: string,
1118
+ prioritizeFollowedUsers: boolean = false,
1119
+ ) => {
1120
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1121
+ {
1122
+ anchor: post,
1123
+ sort: 'newest',
1124
+ prioritizeFollowedUsers,
1125
+ },
1126
+ {
1127
+ headers: await network.serviceHeaders(
1128
+ viewer,
1129
+ ids.AppBskyUnspeccedGetPostThreadV2,
1130
+ ),
1131
+ },
1132
+ )
1133
+ const { thread: t, hasHiddenReplies } = data
1134
+
1135
+ assertPosts(t)
1136
+ expect(hasHiddenReplies).toBe(false)
1137
+ return t
1138
+ }
1139
+
1140
+ it('bumps up followed users if option is set', async () => {
1141
+ const prioritizeFollowedUsers = true
1142
+
1143
+ const t1 = await threadForPostAndViewer(
1144
+ seed.root.ref.uriStr,
1145
+ seed.users.viewerF.did,
1146
+ prioritizeFollowedUsers,
1147
+ )
1148
+ expect(t1).toEqual([
1149
+ expect.objectContaining({ uri: seed.root.ref.uriStr }), // root
1150
+ expect.objectContaining({ uri: seed.r['3'].ref.uriStr }), // op reply
1151
+ expect.objectContaining({ uri: seed.r['4'].ref.uriStr }), // viewer reply
1152
+ expect.objectContaining({ uri: seed.r['1'].ref.uriStr }), // newest followed reply
1153
+ expect.objectContaining({ uri: seed.r['0'].ref.uriStr }), // oldest followed reply
1154
+ expect.objectContaining({ uri: seed.r['5'].ref.uriStr }), // newest non-followed reply
1155
+ expect.objectContaining({ uri: seed.r['2'].ref.uriStr }), // oldest non-followed reply
1156
+ ])
1157
+
1158
+ const t2 = await threadForPostAndViewer(
1159
+ seed.root.ref.uriStr,
1160
+ seed.users.viewerNoF.did,
1161
+ prioritizeFollowedUsers,
1162
+ )
1163
+ expect(t2).toEqual([
1164
+ expect.objectContaining({ uri: seed.root.ref.uriStr }), // root
1165
+ expect.objectContaining({ uri: seed.r['3'].ref.uriStr }), // op reply
1166
+ expect.objectContaining({ uri: seed.r['5'].ref.uriStr }), // viewer reply
1167
+ // newest to oldest
1168
+ expect.objectContaining({ uri: seed.r['4'].ref.uriStr }),
1169
+ expect.objectContaining({ uri: seed.r['2'].ref.uriStr }),
1170
+ expect.objectContaining({ uri: seed.r['1'].ref.uriStr }),
1171
+ expect.objectContaining({ uri: seed.r['0'].ref.uriStr }),
1172
+ ])
1173
+ })
1174
+
1175
+ it('does not prioritize followed users if option is not set', async () => {
1176
+ const t1 = await threadForPostAndViewer(
1177
+ seed.root.ref.uriStr,
1178
+ seed.users.viewerF.did,
1179
+ )
1180
+ expect(t1).toHaveLength(7)
1181
+ expect(t1[0].uri).toBe(seed.root.ref.uriStr) // root
1182
+ expect(t1[1].uri).toBe(seed.r['3'].ref.uriStr) // op reply
1183
+ expect(t1[2].uri).toBe(seed.r['4'].ref.uriStr) // viewer reply
1184
+ // newest to oldest
1185
+ expect(t1[3].uri).toBe(seed.r['5'].ref.uriStr)
1186
+ expect(t1[4].uri).toBe(seed.r['2'].ref.uriStr)
1187
+ expect(t1[5].uri).toBe(seed.r['1'].ref.uriStr)
1188
+ expect(t1[6].uri).toBe(seed.r['0'].ref.uriStr)
1189
+
1190
+ const t2 = await threadForPostAndViewer(
1191
+ seed.root.ref.uriStr,
1192
+ seed.users.viewerNoF.did,
1193
+ )
1194
+ expect(t2).toHaveLength(7)
1195
+ expect(t2[0].uri).toBe(seed.root.ref.uriStr) // root
1196
+ expect(t2[1].uri).toBe(seed.r['3'].ref.uriStr) // op reply
1197
+ expect(t2[2].uri).toBe(seed.r['5'].ref.uriStr) // viewer reply
1198
+ // newest to oldest
1199
+ expect(t2[3].uri).toBe(seed.r['4'].ref.uriStr)
1200
+ expect(t2[4].uri).toBe(seed.r['2'].ref.uriStr)
1201
+ expect(t2[5].uri).toBe(seed.r['1'].ref.uriStr)
1202
+ expect(t2[6].uri).toBe(seed.r['0'].ref.uriStr)
1203
+ })
1204
+ })
1205
+ })
1206
+ })
1207
+
1208
+ describe(`blocks, deletions, no-unauthenticated`, () => {
1209
+ let seed: Awaited<ReturnType<typeof seeds.blockDeletionAuth>>
1210
+
1211
+ beforeAll(async () => {
1212
+ seed = await seeds.blockDeletionAuth(sc)
1213
+ await createLabel({
1214
+ src: labelerDid,
1215
+ uri: seed.users.auth.did,
1216
+ cid: '',
1217
+ val: '!no-unauthenticated',
1218
+ })
1219
+ await network.processAll()
1220
+ })
1221
+
1222
+ describe(`1p blocks`, () => {
1223
+ it(`blocked reply is omitted from replies`, async () => {
1224
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1225
+ { anchor: seed.root.ref.uriStr },
1226
+ {
1227
+ headers: await network.serviceHeaders(
1228
+ // Use `blocked`, who was blocked by `blocker`, author of '0'.
1229
+ seed.users.blocked.did,
1230
+ ids.AppBskyUnspeccedGetPostThreadV2,
1231
+ ),
1232
+ },
1233
+ )
1234
+ const { thread: t, hasHiddenReplies } = data
1235
+
1236
+ assertPosts(t)
1237
+ expect(hasHiddenReplies).toBe(false)
1238
+ expect(t).toEqual([
1239
+ expect.objectContaining({ uri: seed.root.ref.uriStr }),
1240
+ expect.objectContaining({ uri: seed.r['3'].ref.uriStr }),
1241
+ expect.objectContaining({ uri: seed.r['3.0'].ref.uriStr }),
1242
+ expect.objectContaining({ uri: seed.r['3.0.0'].ref.uriStr }),
1243
+ ])
1244
+ })
1245
+
1246
+ it(`blocked anchor returns lone blocked view`, async () => {
1247
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1248
+ { anchor: seed.r['0'].ref.uriStr },
1249
+ {
1250
+ headers: await network.serviceHeaders(
1251
+ // Use `blocked`, who was blocked by `blocker`, author of '0'.
1252
+ seed.users.blocked.did,
1253
+ ids.AppBskyUnspeccedGetPostThreadV2,
1254
+ ),
1255
+ },
1256
+ )
1257
+ const { thread: t, hasHiddenReplies } = data
1258
+
1259
+ expect(hasHiddenReplies).toBe(false)
1260
+ expect(t).toEqual([
1261
+ expect.objectContaining({
1262
+ uri: seed.r['0'].ref.uriStr,
1263
+ depth: 0,
1264
+ value: expect.objectContaining({
1265
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemBlocked',
1266
+ }),
1267
+ }),
1268
+ ])
1269
+ })
1270
+
1271
+ it(`blocked parent is replaced by blocked view`, async () => {
1272
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1273
+ { anchor: seed.r['0.0'].ref.uriStr },
1274
+ {
1275
+ headers: await network.serviceHeaders(
1276
+ // Use `blocked`, who was blocked by `blocker`, author of '0'.
1277
+ seed.users.blocked.did,
1278
+ ids.AppBskyUnspeccedGetPostThreadV2,
1279
+ ),
1280
+ },
1281
+ )
1282
+ const { thread: t, hasHiddenReplies } = data
1283
+
1284
+ expect(hasHiddenReplies).toBe(false)
1285
+ expect(t).toEqual([
1286
+ expect.objectContaining({
1287
+ uri: seed.r['0'].ref.uriStr,
1288
+ depth: -1,
1289
+ value: expect.objectContaining({
1290
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemBlocked',
1291
+ }),
1292
+ }),
1293
+ expect.objectContaining({
1294
+ uri: seed.r['0.0'].ref.uriStr,
1295
+ depth: 0,
1296
+ value: expect.objectContaining({
1297
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1298
+ }),
1299
+ }),
1300
+ ])
1301
+ })
1302
+ })
1303
+
1304
+ describe(`3p blocks`, () => {
1305
+ it(`blocked reply is omitted from replies`, async () => {
1306
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1307
+ { anchor: seed.root.ref.uriStr },
1308
+ {
1309
+ headers: await network.serviceHeaders(
1310
+ // Use `alice` who is a 3rd party between `op` and `opBlocked`.
1311
+ seed.users.alice.did,
1312
+ ids.AppBskyUnspeccedGetPostThreadV2,
1313
+ ),
1314
+ },
1315
+ )
1316
+ const { thread: t, hasHiddenReplies } = data
1317
+
1318
+ expect(hasHiddenReplies).toBe(false)
1319
+ assertPosts(t)
1320
+ expect(t).toEqual([
1321
+ expect.objectContaining({ uri: seed.root.ref.uriStr }),
1322
+ expect.objectContaining({ uri: seed.r['0'].ref.uriStr }),
1323
+ expect.objectContaining({ uri: seed.r['0.0'].ref.uriStr }),
1324
+ expect.objectContaining({ uri: seed.r['3'].ref.uriStr }),
1325
+ expect.objectContaining({ uri: seed.r['3.0'].ref.uriStr }),
1326
+ expect.objectContaining({ uri: seed.r['3.0.0'].ref.uriStr }),
1327
+ ])
1328
+ })
1329
+
1330
+ it(`blocked anchor returns post with blocked parent and non-blocked descendants`, async () => {
1331
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1332
+ { anchor: seed.r['1'].ref.uriStr },
1333
+ {
1334
+ headers: await network.serviceHeaders(
1335
+ // Use `alice` who is a 3rd party between `op` and `opBlocked`.
1336
+ seed.users.alice.did,
1337
+ ids.AppBskyUnspeccedGetPostThreadV2,
1338
+ ),
1339
+ },
1340
+ )
1341
+ const { thread: t, hasHiddenReplies } = data
1342
+
1343
+ expect(hasHiddenReplies).toBe(false)
1344
+ expect(t).toEqual([
1345
+ expect.objectContaining({
1346
+ uri: seed.root.ref.uriStr,
1347
+ depth: -1,
1348
+ value: expect.objectContaining({
1349
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemBlocked',
1350
+ }),
1351
+ }),
1352
+ expect.objectContaining({
1353
+ uri: seed.r['1'].ref.uriStr,
1354
+ depth: 0,
1355
+ value: expect.objectContaining({
1356
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1357
+ }),
1358
+ }),
1359
+ // 1.0 is blocked, but 1.1 is not
1360
+ expect.objectContaining({
1361
+ uri: seed.r['1.1'].ref.uriStr,
1362
+ depth: 1,
1363
+ value: expect.objectContaining({
1364
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1365
+ }),
1366
+ }),
1367
+ ])
1368
+ })
1369
+
1370
+ it(`blocked parent is replaced by blocked view`, async () => {
1371
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1372
+ { anchor: seed.r['1.0'].ref.uriStr },
1373
+ {
1374
+ headers: await network.serviceHeaders(
1375
+ // Use `alice` who is a 3rd party between `op` and `opBlocked`.
1376
+ seed.users.alice.did,
1377
+ ids.AppBskyUnspeccedGetPostThreadV2,
1378
+ ),
1379
+ },
1380
+ )
1381
+ const { thread: t, hasHiddenReplies } = data
1382
+
1383
+ expect(hasHiddenReplies).toBe(false)
1384
+ expect(t).toEqual([
1385
+ expect.objectContaining({
1386
+ uri: seed.r['1'].ref.uriStr,
1387
+ depth: -1,
1388
+ value: expect.objectContaining({
1389
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemBlocked',
1390
+ }),
1391
+ }),
1392
+ expect.objectContaining({
1393
+ uri: seed.r['1.0'].ref.uriStr,
1394
+ depth: 0,
1395
+ value: expect.objectContaining({
1396
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1397
+ }),
1398
+ }),
1399
+ ])
1400
+ })
1401
+
1402
+ it(`blocked root is replaced by blocked view`, async () => {
1403
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1404
+ { anchor: seed.r['1.1'].ref.uriStr },
1405
+ {
1406
+ headers: await network.serviceHeaders(
1407
+ // Use `alice` who is a 3rd party between `op` and `opBlocked`.
1408
+ seed.users.alice.did,
1409
+ ids.AppBskyUnspeccedGetPostThreadV2,
1410
+ ),
1411
+ },
1412
+ )
1413
+ const { thread: t, hasHiddenReplies } = data
1414
+
1415
+ expect(hasHiddenReplies).toBe(false)
1416
+ expect(t).toEqual([
1417
+ expect.objectContaining({
1418
+ uri: seed.root.ref.uriStr,
1419
+ depth: -2,
1420
+ value: expect.objectContaining({
1421
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemBlocked',
1422
+ }),
1423
+ }),
1424
+ expect.objectContaining({
1425
+ uri: seed.r['1'].ref.uriStr,
1426
+ depth: -1,
1427
+ value: expect.objectContaining({
1428
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1429
+ }),
1430
+ }),
1431
+ expect.objectContaining({
1432
+ uri: seed.r['1.1'].ref.uriStr,
1433
+ depth: 0,
1434
+ value: expect.objectContaining({
1435
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1436
+ }),
1437
+ }),
1438
+ ])
1439
+ })
1440
+ })
1441
+
1442
+ describe(`deleted posts`, () => {
1443
+ it(`deleted reply is omitted from replies`, async () => {
1444
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1445
+ { anchor: seed.root.ref.uriStr },
1446
+ {
1447
+ headers: await network.serviceHeaders(
1448
+ seed.users.op.did,
1449
+ ids.AppBskyUnspeccedGetPostThreadV2,
1450
+ ),
1451
+ },
1452
+ )
1453
+ const { thread: t, hasHiddenReplies } = data
1454
+
1455
+ expect(hasHiddenReplies).toBe(false)
1456
+ assertPosts(t)
1457
+ expect(t).toEqual([
1458
+ expect.objectContaining({ uri: seed.root.ref.uriStr }),
1459
+ expect.objectContaining({ uri: seed.r['0'].ref.uriStr }),
1460
+ expect.objectContaining({ uri: seed.r['0.0'].ref.uriStr }),
1461
+ expect.objectContaining({ uri: seed.r['3'].ref.uriStr }),
1462
+ expect.objectContaining({ uri: seed.r['3.0'].ref.uriStr }),
1463
+ expect.objectContaining({ uri: seed.r['3.0.0'].ref.uriStr }),
1464
+ ])
1465
+ })
1466
+
1467
+ it(`deleted parent is replaced by not found view`, async () => {
1468
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1469
+ { anchor: seed.r['2.0'].ref.uriStr },
1470
+ {
1471
+ headers: await network.serviceHeaders(
1472
+ seed.users.op.did,
1473
+ ids.AppBskyUnspeccedGetPostThreadV2,
1474
+ ),
1475
+ },
1476
+ )
1477
+ const { thread: t, hasHiddenReplies } = data
1478
+
1479
+ expect(hasHiddenReplies).toBe(false)
1480
+ expect(t).toEqual([
1481
+ expect.objectContaining({
1482
+ uri: seed.r['2'].ref.uriStr,
1483
+ depth: -1,
1484
+ value: expect.objectContaining({
1485
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemNotFound',
1486
+ }),
1487
+ }),
1488
+ expect.objectContaining({
1489
+ uri: seed.r['2.0'].ref.uriStr,
1490
+ depth: 0,
1491
+ value: expect.objectContaining({
1492
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1493
+ }),
1494
+ }),
1495
+ ])
1496
+ })
1497
+ })
1498
+
1499
+ describe('no-unauthenticated', () => {
1500
+ it(`no-unauthenticated reply is omitted from replies`, async () => {
1501
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1502
+ { anchor: seed.root.ref.uriStr },
1503
+ {
1504
+ headers: {
1505
+ 'atproto-accept-labelers': `${labelerDid}`,
1506
+ },
1507
+ },
1508
+ )
1509
+ const { thread: t, hasHiddenReplies } = data
1510
+
1511
+ expect(hasHiddenReplies).toBe(false)
1512
+ expect(t).toEqual([
1513
+ expect.objectContaining({
1514
+ uri: seed.root.ref.uriStr,
1515
+ depth: 0,
1516
+ value: expect.objectContaining({
1517
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1518
+ }),
1519
+ }),
1520
+ expect.objectContaining({
1521
+ uri: seed.r['0'].ref.uriStr,
1522
+ depth: 1,
1523
+ value: expect.objectContaining({
1524
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1525
+ }),
1526
+ }),
1527
+ expect.objectContaining({
1528
+ uri: seed.r['0.0'].ref.uriStr,
1529
+ depth: 2,
1530
+ value: expect.objectContaining({
1531
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1532
+ }),
1533
+ }),
1534
+ ])
1535
+ })
1536
+
1537
+ it(`no-unauthenticated anchor returns no-unauthenticated view without breaking the parent chain`, async () => {
1538
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1539
+ { anchor: seed.r['3'].ref.uriStr },
1540
+ {
1541
+ headers: {
1542
+ 'atproto-accept-labelers': `${labelerDid}`,
1543
+ },
1544
+ },
1545
+ )
1546
+ const { thread: t, hasHiddenReplies } = data
1547
+
1548
+ expect(hasHiddenReplies).toBe(false)
1549
+ expect(t).toEqual([
1550
+ expect.objectContaining({
1551
+ uri: seed.root.ref.uriStr,
1552
+ depth: -1,
1553
+ value: expect.objectContaining({
1554
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1555
+ }),
1556
+ }),
1557
+ expect.objectContaining({
1558
+ uri: seed.r['3'].ref.uriStr,
1559
+ depth: 0,
1560
+ value: expect.objectContaining({
1561
+ $type:
1562
+ 'app.bsky.unspecced.getPostThreadV2#threadItemNoUnauthenticated',
1563
+ }),
1564
+ }),
1565
+ ])
1566
+ })
1567
+
1568
+ it(`no-unauthenticated parent is replaced by no-unauthenticated view without breaking the parent chain`, async () => {
1569
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1570
+ { anchor: seed.r['3.0.0'].ref.uriStr },
1571
+ {
1572
+ headers: {
1573
+ 'atproto-accept-labelers': `${labelerDid}`,
1574
+ },
1575
+ },
1576
+ )
1577
+ const { thread: t, hasHiddenReplies } = data
1578
+
1579
+ expect(hasHiddenReplies).toBe(false)
1580
+ expect(t).toEqual([
1581
+ expect.objectContaining({
1582
+ uri: seed.root.ref.uriStr,
1583
+ depth: -3,
1584
+ value: expect.objectContaining({
1585
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1586
+ }),
1587
+ }),
1588
+ expect.objectContaining({
1589
+ uri: seed.r['3'].ref.uriStr,
1590
+ depth: -2,
1591
+ value: expect.objectContaining({
1592
+ $type:
1593
+ 'app.bsky.unspecced.getPostThreadV2#threadItemNoUnauthenticated',
1594
+ }),
1595
+ }),
1596
+ expect.objectContaining({
1597
+ uri: seed.r['3.0'].ref.uriStr,
1598
+ depth: -1,
1599
+ value: expect.objectContaining({
1600
+ $type:
1601
+ 'app.bsky.unspecced.getPostThreadV2#threadItemNoUnauthenticated',
1602
+ }),
1603
+ }),
1604
+ expect.objectContaining({
1605
+ uri: seed.r['3.0.0'].ref.uriStr,
1606
+ depth: 0,
1607
+ value: expect.objectContaining({
1608
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1609
+ }),
1610
+ }),
1611
+ ])
1612
+ })
1613
+ })
1614
+ })
1615
+
1616
+ describe(`mutes`, () => {
1617
+ let seed: Awaited<ReturnType<typeof seeds.mutes>>
1618
+
1619
+ beforeAll(async () => {
1620
+ seed = await seeds.mutes(sc)
1621
+ await network.processAll()
1622
+ })
1623
+
1624
+ describe('omitting muted replies', () => {
1625
+ it(`muted reply is omitted in top-level replies and in nested replies`, async () => {
1626
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1627
+ { anchor: seed.root.ref.uriStr },
1628
+ {
1629
+ headers: await network.serviceHeaders(
1630
+ // Fetching as `op` mutes `opMuted`.
1631
+ seed.users.op.did,
1632
+ ids.AppBskyUnspeccedGetPostThreadV2,
1633
+ ),
1634
+ },
1635
+ )
1636
+ const { thread: t, hasHiddenReplies } = data
1637
+
1638
+ expect(hasHiddenReplies).toBe(true)
1639
+ assertPosts(t)
1640
+ expect(t).toEqual([
1641
+ expect.objectContaining({
1642
+ uri: seed.root.ref.uriStr,
1643
+ value: expect.objectContaining(props({ opThread: true })),
1644
+ }),
1645
+ expect.objectContaining({
1646
+ uri: seed.r['1'].ref.uriStr,
1647
+ value: expect.objectContaining(props()),
1648
+ }),
1649
+ // 1.0 is a nested muted reply, so it is omitted.
1650
+ expect.objectContaining({
1651
+ uri: seed.r['1.1'].ref.uriStr,
1652
+ value: expect.objectContaining(props()),
1653
+ }),
1654
+ ])
1655
+ })
1656
+
1657
+ it(`top-level muted replies are returned when fetching hidden, sorted by newest`, async () => {
1658
+ const { data } = await agent.app.bsky.unspecced.getPostThreadHiddenV2(
1659
+ { anchor: seed.root.ref.uriStr },
1660
+ {
1661
+ headers: await network.serviceHeaders(
1662
+ // Fetching as `op` mutes `opMuted`.
1663
+ seed.users.op.did,
1664
+ ids.AppBskyUnspeccedGetPostThreadHiddenV2,
1665
+ ),
1666
+ },
1667
+ )
1668
+ const { thread: t } = data
1669
+
1670
+ assertHiddenPosts(t)
1671
+ expect(t).toEqual([
1672
+ expect.objectContaining({
1673
+ uri: seed.r['0'].ref.uriStr,
1674
+ value: expect.objectContaining(
1675
+ propsHidden({ mutedByViewer: true }),
1676
+ ),
1677
+ }),
1678
+ // No nested replies for hidden.
1679
+ ])
1680
+ })
1681
+ })
1682
+
1683
+ describe('OP mutes', () => {
1684
+ it(`mutes by OP don't mute for 3p`, async () => {
1685
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1686
+ { anchor: seed.root.ref.uriStr },
1687
+ {
1688
+ headers: await network.serviceHeaders(
1689
+ // Fetching as `muter` mutes `muted`.
1690
+ seed.users.muter.did,
1691
+ ids.AppBskyUnspeccedGetPostThreadV2,
1692
+ ),
1693
+ },
1694
+ )
1695
+ const { thread: t, hasHiddenReplies } = data
1696
+
1697
+ expect(hasHiddenReplies).toBe(true)
1698
+ assertPosts(t)
1699
+ expect(t).toEqual([
1700
+ expect.objectContaining({
1701
+ uri: seed.root.ref.uriStr,
1702
+ value: expect.objectContaining(props({ opThread: true })),
1703
+ }),
1704
+ expect.objectContaining({
1705
+ uri: seed.r['0'].ref.uriStr,
1706
+ value: expect.objectContaining(props()),
1707
+ }),
1708
+ expect.objectContaining({
1709
+ uri: seed.r['0.0'].ref.uriStr,
1710
+ value: expect.objectContaining(props()),
1711
+ }),
1712
+ // 0.1 is a nested muted reply, so it is omitted.
1713
+ ])
1714
+ })
1715
+
1716
+ it(`fetches hidden replies includes own mutes, not OP mutes, sorted by newest`, async () => {
1717
+ const { data } = await agent.app.bsky.unspecced.getPostThreadHiddenV2(
1718
+ { anchor: seed.root.ref.uriStr },
1719
+ {
1720
+ headers: await network.serviceHeaders(
1721
+ // Fetching as `muter` mutes `muted`.
1722
+ seed.users.muter.did,
1723
+ ids.AppBskyUnspeccedGetPostThreadHiddenV2,
1724
+ ),
1725
+ },
1726
+ )
1727
+ const { thread: t } = data
1728
+
1729
+ assertHiddenPosts(t)
1730
+ expect(t).toEqual([
1731
+ expect.objectContaining({
1732
+ uri: seed.r['1'].ref.uriStr,
1733
+ value: expect.objectContaining(
1734
+ propsHidden({ mutedByViewer: true }),
1735
+ ),
1736
+ }),
1737
+ // No nested replies for hidden.
1738
+ ])
1739
+ })
1740
+
1741
+ it(`mutes by OP don't affect the muted user`, async () => {
1742
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1743
+ { anchor: seed.root.ref.uriStr },
1744
+ {
1745
+ headers: await network.serviceHeaders(
1746
+ seed.users.opMuted.did,
1747
+ ids.AppBskyUnspeccedGetPostThreadV2,
1748
+ ),
1749
+ },
1750
+ )
1751
+ const { thread: t, hasHiddenReplies } = data
1752
+
1753
+ expect(hasHiddenReplies).toBe(false)
1754
+ assertPosts(t)
1755
+ // No muted posts by `opMuted`, gets the full thread.
1756
+ expect(t.length).toBe(1 + Object.keys(seed.r).length) // root + replies
1757
+ })
1758
+ })
1759
+ })
1760
+
1761
+ describe(`threadgated`, () => {
1762
+ let seed: Awaited<ReturnType<typeof seeds.threadgated>>
1763
+
1764
+ beforeAll(async () => {
1765
+ seed = await seeds.threadgated(sc)
1766
+ await network.processAll()
1767
+ })
1768
+
1769
+ it(`threadgated reply is omitted in top-level replies and in nested replies`, async () => {
1770
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1771
+ { anchor: seed.root.ref.uriStr },
1772
+ {
1773
+ headers: await network.serviceHeaders(
1774
+ seed.users.op.did,
1775
+ ids.AppBskyUnspeccedGetPostThreadV2,
1776
+ ),
1777
+ },
1778
+ )
1779
+ const { thread: t, hasHiddenReplies } = data
1780
+
1781
+ expect(hasHiddenReplies).toBe(true)
1782
+ assertPosts(t)
1783
+ expect(t).toEqual([
1784
+ expect.objectContaining({
1785
+ uri: seed.root.ref.uriStr,
1786
+ value: expect.objectContaining(props({ opThread: true })),
1787
+ }),
1788
+ expect.objectContaining({
1789
+ uri: seed.r['2'].ref.uriStr,
1790
+ value: expect.objectContaining(props()),
1791
+ }),
1792
+ // OP reply bumped up.
1793
+ expect.objectContaining({
1794
+ uri: seed.r['2.2'].ref.uriStr,
1795
+ value: expect.objectContaining(props()),
1796
+ }),
1797
+ expect.objectContaining({
1798
+ uri: seed.r['2.0'].ref.uriStr,
1799
+ value: expect.objectContaining(props()),
1800
+ }),
1801
+ // 2.1 is a nested hidden reply, so it is omitted.
1802
+ ])
1803
+ })
1804
+
1805
+ it(`top-level threadgated replies are returned to OP when fetching hidden, sorted by newest`, async () => {
1806
+ const { data } = await agent.app.bsky.unspecced.getPostThreadHiddenV2(
1807
+ { anchor: seed.root.ref.uriStr },
1808
+ {
1809
+ headers: await network.serviceHeaders(
1810
+ seed.users.op.did,
1811
+ ids.AppBskyUnspeccedGetPostThreadHiddenV2,
1812
+ ),
1813
+ },
1814
+ )
1815
+ const { thread: t } = data
1816
+
1817
+ assertHiddenPosts(t)
1818
+ expect(t).toEqual([
1819
+ expect.objectContaining({
1820
+ uri: seed.r['1'].ref.uriStr,
1821
+ value: expect.objectContaining(
1822
+ propsHidden({ hiddenByThreadgate: true }),
1823
+ ),
1824
+ }),
1825
+ // No nested replies for hidden.
1826
+
1827
+ // Mutes come after hidden.
1828
+ expect.objectContaining({
1829
+ uri: seed.r['0'].ref.uriStr,
1830
+ value: expect.objectContaining(propsHidden({ mutedByViewer: true })),
1831
+ }),
1832
+ ])
1833
+ })
1834
+
1835
+ it(`author of hidden reply does not see it as hidden`, async () => {
1836
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1837
+ { anchor: seed.root.ref.uriStr },
1838
+ {
1839
+ headers: await network.serviceHeaders(
1840
+ // `alice` does not get its own reply as hidden.
1841
+ seed.users.alice.did,
1842
+ ids.AppBskyUnspeccedGetPostThreadV2,
1843
+ ),
1844
+ },
1845
+ )
1846
+ const { thread: t, hasHiddenReplies } = data
1847
+
1848
+ expect(hasHiddenReplies).toBe(false)
1849
+ assertPosts(t)
1850
+ expect(t).toEqual([
1851
+ expect.objectContaining({
1852
+ uri: seed.root.ref.uriStr,
1853
+ value: expect.objectContaining(props({ opThread: true })),
1854
+ }),
1855
+
1856
+ // alice does not see its own reply as hidden.
1857
+ expect.objectContaining({
1858
+ uri: seed.r['1'].ref.uriStr,
1859
+ value: expect.objectContaining(props()),
1860
+ }),
1861
+ // OP reply bumped up.
1862
+ expect.objectContaining({
1863
+ uri: seed.r['1.2'].ref.uriStr,
1864
+ value: expect.objectContaining(props()),
1865
+ }),
1866
+ expect.objectContaining({
1867
+ uri: seed.r['1.0'].ref.uriStr,
1868
+ value: expect.objectContaining(props()),
1869
+ }),
1870
+ expect.objectContaining({
1871
+ uri: seed.r['1.1'].ref.uriStr,
1872
+ value: expect.objectContaining(props()),
1873
+ }),
1874
+
1875
+ // `opMuted` is not muted by `alice`.
1876
+ expect.objectContaining({
1877
+ uri: seed.r['0'].ref.uriStr,
1878
+ value: expect.objectContaining(props()),
1879
+ }),
1880
+
1881
+ expect.objectContaining({
1882
+ uri: seed.r['2'].ref.uriStr,
1883
+ value: expect.objectContaining(props()),
1884
+ }),
1885
+ // OP reply bumped up.
1886
+ expect.objectContaining({
1887
+ uri: seed.r['2.2'].ref.uriStr,
1888
+ value: expect.objectContaining(props()),
1889
+ }),
1890
+ expect.objectContaining({
1891
+ uri: seed.r['2.0'].ref.uriStr,
1892
+ value: expect.objectContaining(props()),
1893
+ }),
1894
+ // 2.1 is a nested hidden reply, so it is omitted.
1895
+ ])
1896
+ })
1897
+
1898
+ it(`other viewers are affected by threadgate-hidden replies by OP`, async () => {
1899
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1900
+ { anchor: seed.root.ref.uriStr },
1901
+ {
1902
+ headers: await network.serviceHeaders(
1903
+ // `viewer` also gets the replies as hidden.
1904
+ seed.users.viewer.did,
1905
+ ids.AppBskyUnspeccedGetPostThreadV2,
1906
+ ),
1907
+ },
1908
+ )
1909
+ const { thread: t, hasHiddenReplies } = data
1910
+
1911
+ expect(hasHiddenReplies).toBe(true)
1912
+ assertPosts(t)
1913
+ expect(t).toEqual([
1914
+ expect.objectContaining({
1915
+ uri: seed.root.ref.uriStr,
1916
+ value: expect.objectContaining(props({ opThread: true })),
1917
+ }),
1918
+ // `opMuted` doesn't see itself as muted, just `op` does.
1919
+ expect.objectContaining({
1920
+ uri: seed.r['0'].ref.uriStr,
1921
+ value: expect.objectContaining(props()),
1922
+ }),
1923
+
1924
+ expect.objectContaining({
1925
+ uri: seed.r['2'].ref.uriStr,
1926
+ value: expect.objectContaining(props()),
1927
+ }),
1928
+ // OP reply bumped up.
1929
+ expect.objectContaining({
1930
+ uri: seed.r['2.2'].ref.uriStr,
1931
+ value: expect.objectContaining(props()),
1932
+ }),
1933
+ expect.objectContaining({
1934
+ uri: seed.r['2.0'].ref.uriStr,
1935
+ value: expect.objectContaining(props()),
1936
+ }),
1937
+ // 2.1 is a nested hidden reply, so it is omitted.
1938
+ ])
1939
+ })
1940
+
1941
+ it(`top-level threadgated replies are returned to other viewers when fetching hidden, sorted by newest`, async () => {
1942
+ const { data } = await agent.app.bsky.unspecced.getPostThreadHiddenV2(
1943
+ { anchor: seed.root.ref.uriStr },
1944
+ {
1945
+ headers: await network.serviceHeaders(
1946
+ // `viewer` also gets the replies as hidden.
1947
+ seed.users.viewer.did,
1948
+ ids.AppBskyUnspeccedGetPostThreadHiddenV2,
1949
+ ),
1950
+ },
1951
+ )
1952
+ const { thread: t } = data
1953
+
1954
+ assertHiddenPosts(t)
1955
+ expect(t).toEqual([
1956
+ expect.objectContaining({
1957
+ uri: seed.r['1'].ref.uriStr,
1958
+ value: expect.objectContaining(
1959
+ propsHidden({ hiddenByThreadgate: true }),
1960
+ ),
1961
+ }),
1962
+ // No nested replies for hidden.
1963
+ ])
1964
+ })
1965
+ })
1966
+
1967
+ const createLabel = async (opts: {
1968
+ src?: string
1969
+ uri: string
1970
+ cid: string
1971
+ val: string
1972
+ exp?: string
1973
+ }) => {
1974
+ await network.bsky.db.db
1975
+ .insertInto('label')
1976
+ .values({
1977
+ uri: opts.uri,
1978
+ cid: opts.cid,
1979
+ val: opts.val,
1980
+ cts: new Date().toISOString(),
1981
+ exp: opts.exp ?? null,
1982
+ neg: false,
1983
+ src: opts.src ?? labelerDid,
1984
+ })
1985
+ .execute()
1986
+ }
1987
+ })
1988
+
1989
+ function assertPosts(
1990
+ t: OutputSchemaThread['thread'],
1991
+ ): asserts t is ThreadItemValuePost[] {
1992
+ t.forEach((i) => {
1993
+ assert(
1994
+ AppBskyUnspeccedGetPostThreadV2.isThreadItemPost(i.value),
1995
+ `Expected thread item to have a post as value`,
1996
+ )
1997
+ })
1998
+ }
1999
+
2000
+ function assertHiddenPosts(
2001
+ t: OutputSchemaHiddenThread['thread'],
2002
+ ): asserts t is ThreadHiddenItem[] {
2003
+ t.forEach((i) => {
2004
+ assert(
2005
+ AppBskyUnspeccedGetPostThreadHiddenV2.isThreadHiddenItemPost(i.value),
2006
+ `Expected thread item to have a hidden post as value`,
2007
+ )
2008
+ })
2009
+ }