@atproto/bsky 0.0.243 → 0.0.244

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 (272) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/api/app/bsky/actor/searchActorsTypeahead.js +5 -3
  3. package/dist/api/app/bsky/actor/searchActorsTypeahead.js.map +1 -1
  4. package/dist/api/app/bsky/notification/putPreferencesV2.js +4 -1
  5. package/dist/api/app/bsky/notification/putPreferencesV2.js.map +1 -1
  6. package/dist/api/app/bsky/notification/util.d.ts +1 -0
  7. package/dist/api/app/bsky/notification/util.d.ts.map +1 -1
  8. package/dist/api/app/bsky/notification/util.js +7 -7
  9. package/dist/api/app/bsky/notification/util.js.map +1 -1
  10. package/dist/api/blob-dispatcher.d.ts.map +1 -1
  11. package/dist/api/blob-dispatcher.js +9 -8
  12. package/dist/api/blob-dispatcher.js.map +1 -1
  13. package/dist/api/blob-resolver.d.ts +1 -1
  14. package/dist/api/blob-resolver.d.ts.map +1 -1
  15. package/dist/api/blob-resolver.js +0 -1
  16. package/dist/api/blob-resolver.js.map +1 -1
  17. package/dist/data-plane/bsync/index.d.ts +2 -0
  18. package/dist/data-plane/bsync/index.d.ts.map +1 -1
  19. package/dist/data-plane/bsync/index.js +7 -10
  20. package/dist/data-plane/bsync/index.js.map +1 -1
  21. package/dist/data-plane/server/background.d.ts +12 -8
  22. package/dist/data-plane/server/background.d.ts.map +1 -1
  23. package/dist/data-plane/server/background.js +32 -14
  24. package/dist/data-plane/server/background.js.map +1 -1
  25. package/dist/data-plane/server/index.d.ts +2 -0
  26. package/dist/data-plane/server/index.d.ts.map +1 -1
  27. package/dist/data-plane/server/index.js +7 -10
  28. package/dist/data-plane/server/index.js.map +1 -1
  29. package/dist/data-plane/server/indexing/index.d.ts +2 -2
  30. package/dist/data-plane/server/indexing/index.d.ts.map +1 -1
  31. package/dist/data-plane/server/indexing/index.js.map +1 -1
  32. package/dist/data-plane/server/indexing/plugins/block.d.ts +1 -1
  33. package/dist/data-plane/server/indexing/plugins/block.d.ts.map +1 -1
  34. package/dist/data-plane/server/indexing/plugins/block.js.map +1 -1
  35. package/dist/data-plane/server/indexing/plugins/chat-declaration.d.ts +1 -1
  36. package/dist/data-plane/server/indexing/plugins/chat-declaration.d.ts.map +1 -1
  37. package/dist/data-plane/server/indexing/plugins/chat-declaration.js.map +1 -1
  38. package/dist/data-plane/server/indexing/plugins/feed-generator.d.ts +1 -1
  39. package/dist/data-plane/server/indexing/plugins/feed-generator.d.ts.map +1 -1
  40. package/dist/data-plane/server/indexing/plugins/feed-generator.js.map +1 -1
  41. package/dist/data-plane/server/indexing/plugins/follow.d.ts +1 -1
  42. package/dist/data-plane/server/indexing/plugins/follow.d.ts.map +1 -1
  43. package/dist/data-plane/server/indexing/plugins/follow.js.map +1 -1
  44. package/dist/data-plane/server/indexing/plugins/germ-declaration.d.ts +1 -1
  45. package/dist/data-plane/server/indexing/plugins/germ-declaration.d.ts.map +1 -1
  46. package/dist/data-plane/server/indexing/plugins/germ-declaration.js.map +1 -1
  47. package/dist/data-plane/server/indexing/plugins/labeler.d.ts +1 -1
  48. package/dist/data-plane/server/indexing/plugins/labeler.d.ts.map +1 -1
  49. package/dist/data-plane/server/indexing/plugins/labeler.js.map +1 -1
  50. package/dist/data-plane/server/indexing/plugins/like.d.ts +1 -1
  51. package/dist/data-plane/server/indexing/plugins/like.d.ts.map +1 -1
  52. package/dist/data-plane/server/indexing/plugins/like.js.map +1 -1
  53. package/dist/data-plane/server/indexing/plugins/list-block.d.ts +1 -1
  54. package/dist/data-plane/server/indexing/plugins/list-block.d.ts.map +1 -1
  55. package/dist/data-plane/server/indexing/plugins/list-block.js.map +1 -1
  56. package/dist/data-plane/server/indexing/plugins/list-item.d.ts +1 -1
  57. package/dist/data-plane/server/indexing/plugins/list-item.d.ts.map +1 -1
  58. package/dist/data-plane/server/indexing/plugins/list-item.js.map +1 -1
  59. package/dist/data-plane/server/indexing/plugins/list.d.ts +1 -1
  60. package/dist/data-plane/server/indexing/plugins/list.d.ts.map +1 -1
  61. package/dist/data-plane/server/indexing/plugins/list.js.map +1 -1
  62. package/dist/data-plane/server/indexing/plugins/notif-declaration.d.ts +1 -1
  63. package/dist/data-plane/server/indexing/plugins/notif-declaration.d.ts.map +1 -1
  64. package/dist/data-plane/server/indexing/plugins/notif-declaration.js.map +1 -1
  65. package/dist/data-plane/server/indexing/plugins/post-gate.d.ts +1 -1
  66. package/dist/data-plane/server/indexing/plugins/post-gate.d.ts.map +1 -1
  67. package/dist/data-plane/server/indexing/plugins/post-gate.js.map +1 -1
  68. package/dist/data-plane/server/indexing/plugins/post.d.ts +1 -1
  69. package/dist/data-plane/server/indexing/plugins/post.d.ts.map +1 -1
  70. package/dist/data-plane/server/indexing/plugins/post.js.map +1 -1
  71. package/dist/data-plane/server/indexing/plugins/profile.d.ts +1 -1
  72. package/dist/data-plane/server/indexing/plugins/profile.d.ts.map +1 -1
  73. package/dist/data-plane/server/indexing/plugins/profile.js.map +1 -1
  74. package/dist/data-plane/server/indexing/plugins/repost.d.ts +1 -1
  75. package/dist/data-plane/server/indexing/plugins/repost.d.ts.map +1 -1
  76. package/dist/data-plane/server/indexing/plugins/repost.js.map +1 -1
  77. package/dist/data-plane/server/indexing/plugins/starter-pack.d.ts +1 -1
  78. package/dist/data-plane/server/indexing/plugins/starter-pack.d.ts.map +1 -1
  79. package/dist/data-plane/server/indexing/plugins/starter-pack.js.map +1 -1
  80. package/dist/data-plane/server/indexing/plugins/status.d.ts +1 -1
  81. package/dist/data-plane/server/indexing/plugins/status.d.ts.map +1 -1
  82. package/dist/data-plane/server/indexing/plugins/status.js.map +1 -1
  83. package/dist/data-plane/server/indexing/plugins/thread-gate.d.ts +1 -1
  84. package/dist/data-plane/server/indexing/plugins/thread-gate.d.ts.map +1 -1
  85. package/dist/data-plane/server/indexing/plugins/thread-gate.js.map +1 -1
  86. package/dist/data-plane/server/indexing/plugins/verification.d.ts +1 -1
  87. package/dist/data-plane/server/indexing/plugins/verification.d.ts.map +1 -1
  88. package/dist/data-plane/server/indexing/plugins/verification.js.map +1 -1
  89. package/dist/data-plane/server/indexing/processor.d.ts +1 -1
  90. package/dist/data-plane/server/indexing/processor.d.ts.map +1 -1
  91. package/dist/data-plane/server/indexing/processor.js.map +1 -1
  92. package/dist/data-plane/server/routes/notifs.d.ts.map +1 -1
  93. package/dist/data-plane/server/routes/notifs.js +1 -8
  94. package/dist/data-plane/server/routes/notifs.js.map +1 -1
  95. package/dist/data-plane/server/routes/search.js +2 -2
  96. package/dist/data-plane/server/routes/search.js.map +1 -1
  97. package/dist/data-plane/server/subscription.d.ts +13 -12
  98. package/dist/data-plane/server/subscription.d.ts.map +1 -1
  99. package/dist/data-plane/server/subscription.js +59 -26
  100. package/dist/data-plane/server/subscription.js.map +1 -1
  101. package/dist/feature-gates/index.d.ts +2 -1
  102. package/dist/feature-gates/index.d.ts.map +1 -1
  103. package/dist/feature-gates/index.js +9 -6
  104. package/dist/feature-gates/index.js.map +1 -1
  105. package/dist/feature-gates/metrics.d.ts +3 -3
  106. package/dist/feature-gates/metrics.d.ts.map +1 -1
  107. package/dist/feature-gates/metrics.js +8 -8
  108. package/dist/feature-gates/metrics.js.map +1 -1
  109. package/dist/index.d.ts +1 -0
  110. package/dist/index.d.ts.map +1 -1
  111. package/dist/index.js +16 -7
  112. package/dist/index.js.map +1 -1
  113. package/dist/lexicons/app/bsky/notification/defs.defs.d.ts +5 -0
  114. package/dist/lexicons/app/bsky/notification/defs.defs.d.ts.map +1 -1
  115. package/dist/lexicons/app/bsky/notification/defs.defs.js +1 -0
  116. package/dist/lexicons/app/bsky/notification/defs.defs.js.map +1 -1
  117. package/dist/lexicons/chat/bsky/notification/defs.d.ts +2 -0
  118. package/dist/lexicons/chat/bsky/notification/defs.d.ts.map +1 -0
  119. package/dist/lexicons/chat/bsky/notification/defs.defs.d.ts +20 -0
  120. package/dist/lexicons/chat/bsky/notification/defs.defs.d.ts.map +1 -0
  121. package/dist/lexicons/chat/bsky/notification/defs.defs.js +19 -0
  122. package/dist/lexicons/chat/bsky/notification/defs.defs.js.map +1 -0
  123. package/dist/lexicons/chat/bsky/notification/defs.js +5 -0
  124. package/dist/lexicons/chat/bsky/notification/defs.js.map +1 -0
  125. package/dist/lexicons/chat/bsky/notification/getPreferences.d.ts +3 -0
  126. package/dist/lexicons/chat/bsky/notification/getPreferences.d.ts.map +1 -0
  127. package/dist/lexicons/chat/bsky/notification/getPreferences.defs.d.ts +18 -0
  128. package/dist/lexicons/chat/bsky/notification/getPreferences.defs.d.ts.map +1 -0
  129. package/dist/lexicons/chat/bsky/notification/getPreferences.defs.js +16 -0
  130. package/dist/lexicons/chat/bsky/notification/getPreferences.defs.js.map +1 -0
  131. package/dist/lexicons/chat/bsky/notification/getPreferences.js +6 -0
  132. package/dist/lexicons/chat/bsky/notification/getPreferences.js.map +1 -0
  133. package/dist/lexicons/chat/bsky/notification/putPreferences.d.ts +3 -0
  134. package/dist/lexicons/chat/bsky/notification/putPreferences.d.ts.map +1 -0
  135. package/dist/lexicons/chat/bsky/notification/putPreferences.defs.d.ts +27 -0
  136. package/dist/lexicons/chat/bsky/notification/putPreferences.defs.d.ts.map +1 -0
  137. package/dist/lexicons/chat/bsky/notification/putPreferences.defs.js +22 -0
  138. package/dist/lexicons/chat/bsky/notification/putPreferences.defs.js.map +1 -0
  139. package/dist/lexicons/chat/bsky/notification/putPreferences.js +6 -0
  140. package/dist/lexicons/chat/bsky/notification/putPreferences.js.map +1 -0
  141. package/dist/lexicons/chat/bsky/notification.d.ts +4 -0
  142. package/dist/lexicons/chat/bsky/notification.d.ts.map +1 -0
  143. package/dist/lexicons/chat/bsky/notification.js +7 -0
  144. package/dist/lexicons/chat/bsky/notification.js.map +1 -0
  145. package/dist/lexicons/chat/bsky.d.ts +1 -0
  146. package/dist/lexicons/chat/bsky.d.ts.map +1 -1
  147. package/dist/lexicons/chat/bsky.js +1 -0
  148. package/dist/lexicons/chat/bsky.js.map +1 -1
  149. package/dist/lexicons/tools/ozone/report/defs.defs.d.ts +4 -0
  150. package/dist/lexicons/tools/ozone/report/defs.defs.d.ts.map +1 -1
  151. package/dist/lexicons/tools/ozone/report/defs.defs.js +2 -0
  152. package/dist/lexicons/tools/ozone/report/defs.defs.js.map +1 -1
  153. package/dist/lexicons/tools/ozone/report/queryActivities.d.ts +3 -0
  154. package/dist/lexicons/tools/ozone/report/queryActivities.d.ts.map +1 -0
  155. package/dist/lexicons/tools/ozone/report/queryActivities.defs.d.ts +42 -0
  156. package/dist/lexicons/tools/ozone/report/queryActivities.defs.d.ts.map +1 -0
  157. package/dist/lexicons/tools/ozone/report/queryActivities.defs.js +31 -0
  158. package/dist/lexicons/tools/ozone/report/queryActivities.defs.js.map +1 -0
  159. package/dist/lexicons/tools/ozone/report/queryActivities.js +6 -0
  160. package/dist/lexicons/tools/ozone/report/queryActivities.js.map +1 -0
  161. package/dist/lexicons/tools/ozone/report.d.ts +1 -0
  162. package/dist/lexicons/tools/ozone/report.d.ts.map +1 -1
  163. package/dist/lexicons/tools/ozone/report.js +1 -0
  164. package/dist/lexicons/tools/ozone/report.js.map +1 -1
  165. package/dist/proto/bsky_pb.d.ts +47 -53
  166. package/dist/proto/bsky_pb.d.ts.map +1 -1
  167. package/dist/proto/bsky_pb.js +62 -71
  168. package/dist/proto/bsky_pb.js.map +1 -1
  169. package/package.json +10 -10
  170. package/proto/bsky.proto +19 -17
  171. package/src/api/app/bsky/actor/searchActorsTypeahead.ts +5 -3
  172. package/src/api/app/bsky/notification/putPreferencesV2.ts +4 -1
  173. package/src/api/app/bsky/notification/util.ts +7 -11
  174. package/src/api/blob-dispatcher.ts +12 -8
  175. package/src/api/blob-resolver.ts +0 -1
  176. package/src/data-plane/bsync/index.ts +12 -10
  177. package/src/data-plane/server/background.ts +49 -18
  178. package/src/data-plane/server/index.ts +12 -10
  179. package/src/data-plane/server/indexing/index.ts +1 -1
  180. package/src/data-plane/server/indexing/plugins/block.ts +4 -1
  181. package/src/data-plane/server/indexing/plugins/chat-declaration.ts +4 -1
  182. package/src/data-plane/server/indexing/plugins/feed-generator.ts +4 -1
  183. package/src/data-plane/server/indexing/plugins/follow.ts +4 -1
  184. package/src/data-plane/server/indexing/plugins/germ-declaration.ts +4 -1
  185. package/src/data-plane/server/indexing/plugins/labeler.ts +4 -1
  186. package/src/data-plane/server/indexing/plugins/like.ts +4 -1
  187. package/src/data-plane/server/indexing/plugins/list-block.ts +4 -1
  188. package/src/data-plane/server/indexing/plugins/list-item.ts +4 -1
  189. package/src/data-plane/server/indexing/plugins/list.ts +4 -1
  190. package/src/data-plane/server/indexing/plugins/notif-declaration.ts +4 -1
  191. package/src/data-plane/server/indexing/plugins/post-gate.ts +4 -1
  192. package/src/data-plane/server/indexing/plugins/post.ts +4 -1
  193. package/src/data-plane/server/indexing/plugins/profile.ts +4 -1
  194. package/src/data-plane/server/indexing/plugins/repost.ts +4 -1
  195. package/src/data-plane/server/indexing/plugins/starter-pack.ts +4 -1
  196. package/src/data-plane/server/indexing/plugins/status.ts +4 -1
  197. package/src/data-plane/server/indexing/plugins/thread-gate.ts +4 -1
  198. package/src/data-plane/server/indexing/plugins/verification.ts +4 -1
  199. package/src/data-plane/server/indexing/processor.ts +1 -1
  200. package/src/data-plane/server/routes/notifs.ts +0 -14
  201. package/src/data-plane/server/routes/search.ts +2 -2
  202. package/src/data-plane/server/subscription.ts +74 -31
  203. package/src/feature-gates/index.ts +10 -6
  204. package/src/feature-gates/metrics.test.ts +12 -12
  205. package/src/feature-gates/metrics.ts +8 -8
  206. package/src/index.ts +16 -9
  207. package/tests/_util.ts +8 -25
  208. package/tests/admin/admin-auth.test.ts +2 -2
  209. package/tests/admin/moderation.test.ts +1 -1
  210. package/tests/auth.test.ts +4 -6
  211. package/tests/blob-resolver.test.ts +4 -5
  212. package/tests/data-plane/db.test.ts +1 -1
  213. package/tests/data-plane/duplicate-records.test.ts +1 -1
  214. package/tests/data-plane/handle-invalidation.test.ts +2 -2
  215. package/tests/data-plane/indexing.test.ts +24 -21
  216. package/tests/data-plane/subscription.test.ts +1 -1
  217. package/tests/data-plane/thread-mutes.test.ts +2 -2
  218. package/tests/entryway-auth.test.ts +4 -5
  219. package/tests/feed-generation.test.ts +5 -5
  220. package/tests/image/server.test.ts +1 -1
  221. package/tests/label-hydration.test.ts +3 -5
  222. package/tests/postgates.test.ts +3 -6
  223. package/tests/query-labels.test.ts +3 -5
  224. package/tests/redis-cache.test.ts +1 -3
  225. package/tests/server.test.ts +11 -16
  226. package/tests/sitemap.test.ts +3 -4
  227. package/tests/stash.test.ts +12 -8
  228. package/tests/utils.test.ts +3 -13
  229. package/tests/views/account-deactivation.test.ts +3 -5
  230. package/tests/views/actor-likes.test.ts +3 -5
  231. package/tests/views/actor-search.test.ts +6 -7
  232. package/tests/views/age-assurance-v2.test.ts +9 -6
  233. package/tests/views/age-assurance.test.ts +30 -36
  234. package/tests/views/author-feed.test.ts +4 -6
  235. package/tests/views/block-lists.test.ts +3 -5
  236. package/tests/views/blocks.test.ts +3 -5
  237. package/tests/views/bookmarks.test.ts +4 -4
  238. package/tests/views/drafts.test.ts +7 -14
  239. package/tests/views/feed-hidden-replies.test.ts +3 -6
  240. package/tests/views/feed-view-post.test.ts +3 -6
  241. package/tests/views/follows.test.ts +4 -6
  242. package/tests/views/get-config.test.ts +4 -7
  243. package/tests/views/get-suggested-onboarding-users.test.ts +11 -9
  244. package/tests/views/get-suggested-starter-packs.test.ts +11 -9
  245. package/tests/views/get-trends.test.ts +15 -9
  246. package/tests/views/internal-actor.test.ts +3 -6
  247. package/tests/views/known-followers.test.ts +3 -6
  248. package/tests/views/labeler-service.test.ts +3 -5
  249. package/tests/views/labels-needs-review.test.ts +3 -6
  250. package/tests/views/labels-takedown.test.ts +3 -4
  251. package/tests/views/likes.test.ts +4 -6
  252. package/tests/views/list-feed.test.ts +3 -5
  253. package/tests/views/lists.test.ts +3 -5
  254. package/tests/views/mute-lists.test.ts +3 -5
  255. package/tests/views/mutes.test.ts +4 -5
  256. package/tests/views/notifications.test.ts +12 -11
  257. package/tests/views/post-search.test.ts +3 -24
  258. package/tests/views/posts-debug.test.ts +11 -6
  259. package/tests/views/posts.test.ts +3 -4
  260. package/tests/views/profile-debug.test.ts +11 -5
  261. package/tests/views/profile.test.ts +11 -5
  262. package/tests/views/quotes.test.ts +4 -6
  263. package/tests/views/reposts.test.ts +4 -6
  264. package/tests/views/starter-packs.test.ts +3 -6
  265. package/tests/views/suggestions.test.ts +9 -13
  266. package/tests/views/thread-v2.test.ts +3 -5
  267. package/tests/views/thread.test.ts +3 -7
  268. package/tests/views/threadgating.test.ts +3 -5
  269. package/tests/views/timeline.test.ts +4 -5
  270. package/tests/views/verification.test.ts +4 -6
  271. package/tsconfig.build.tsbuildinfo +1 -1
  272. package/vitest.config.ts +1 -0
@@ -2,7 +2,9 @@ import crypto from 'node:crypto'
2
2
  import { once } from 'node:events'
3
3
  import { Server, createServer } from 'node:http'
4
4
  import { AddressInfo } from 'node:net'
5
- import express, { Application } from 'express'
5
+ import express, { Application, RequestHandler } from 'express'
6
+ // eslint-disable-next-line import/default
7
+ import httpTerminator from 'http-terminator'
6
8
  import {
7
9
  afterAll,
8
10
  afterEach,
@@ -41,8 +43,17 @@ describe('age assurance views', () => {
41
43
  let actorDid: string
42
44
 
43
45
  let kwsServer: MockKwsServer
44
- const authMock = vi.fn<MockHandler>()
45
- const sendEmailMock = vi.fn<MockHandler>()
46
+
47
+ const authMock = vi.fn<RequestHandler>((req, res) =>
48
+ res.json({
49
+ access_token:
50
+ 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIn0.INVALID',
51
+ expires_in: 3600,
52
+ }),
53
+ )
54
+ const sendEmailMock = vi.fn<RequestHandler>((req, res) => {
55
+ res.json({})
56
+ })
46
57
 
47
58
  beforeAll(async () => {
48
59
  kwsServer = new MockKwsServer({
@@ -74,38 +85,24 @@ describe('age assurance views', () => {
74
85
  agent = network.bsky.getAgent()
75
86
  sc = network.getSeedClient()
76
87
  await basicSeed(sc)
77
- await network.processAll()
78
-
79
88
  actorDid = sc.dids.alice
80
89
  })
81
90
 
91
+ beforeEach(async () => network.processAll())
92
+
82
93
  beforeEach(async () => {
83
- // Default mocks for KWS endpoints.
84
- authMock.mockImplementation(
85
- (_req: express.Request, res: express.Response) =>
86
- res.json({
87
- access_token:
88
- 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIn0.INVALID',
89
- expires_in: 3600,
90
- }),
91
- )
92
- sendEmailMock.mockImplementation(
93
- (_req: express.Request, res: express.Response) => {
94
- res.json({})
95
- },
96
- )
94
+ // @TODO Use the clearMocks setting in the configuration instead of:
95
+ authMock.mockClear()
96
+ sendEmailMock.mockClear()
97
97
  })
98
98
 
99
99
  afterEach(async () => {
100
- vi.resetAllMocks()
101
100
  await clearPrivateData(db)
102
101
  await clearActorAgeAssurance(db)
103
102
  })
104
103
 
105
- afterAll(async () => {
106
- await network.close()
107
- await kwsServer.stop()
108
- })
104
+ afterAll(async () => network?.close())
105
+ afterAll(async () => kwsServer?.stop())
109
106
 
110
107
  const getAgeAssurance = async (did: string) => {
111
108
  const { data } = await agent.app.bsky.unspecced.getAgeAssuranceState(
@@ -372,13 +369,12 @@ const clearActorAgeAssurance = async (db: Database) => {
372
369
  .execute()
373
370
  }
374
371
 
375
- type MockHandler = (req: express.Request, res: express.Response) => void
376
-
377
372
  class MockKwsServer {
378
373
  private verificationSecret: string
379
374
  private webhookSecret: string
380
375
  private app: Application
381
376
  private server: Server
377
+ private terminator: httpTerminator.HttpTerminator
382
378
 
383
379
  constructor({
384
380
  verificationSecret,
@@ -388,21 +384,20 @@ class MockKwsServer {
388
384
  }: {
389
385
  verificationSecret: string
390
386
  webhookSecret: string
391
- authMock: ReturnType<typeof vi.fn<MockHandler>>
392
- sendEmailMock: ReturnType<typeof vi.fn<MockHandler>>
387
+ authMock: RequestHandler
388
+ sendEmailMock: RequestHandler
393
389
  }) {
394
390
  this.verificationSecret = verificationSecret
395
391
  this.webhookSecret = webhookSecret
396
392
 
397
393
  this.app = express()
398
- .post('/auth/realms/kws/protocol/openid-connect/token', (req, res) =>
399
- authMock(req, res),
400
- )
401
- .post('/v1/verifications/send-email', (req, res) =>
402
- sendEmailMock(req, res),
403
- )
394
+ .post('/auth/realms/kws/protocol/openid-connect/token', authMock)
395
+ .post('/v1/verifications/send-email', sendEmailMock)
404
396
 
405
397
  this.server = createServer(this.app)
398
+ this.terminator = httpTerminator.createHttpTerminator({
399
+ server: this.server,
400
+ })
406
401
  }
407
402
 
408
403
  async listen(port?: number) {
@@ -411,8 +406,7 @@ class MockKwsServer {
411
406
  }
412
407
 
413
408
  async stop() {
414
- this.server.close()
415
- await once(this.server, 'close')
409
+ await this.terminator.terminate()
416
410
  }
417
411
 
418
412
  callVerificationResponse(
@@ -1,5 +1,5 @@
1
1
  import assert from 'node:assert'
2
- import { afterAll, beforeAll, describe, expect, it } from 'vitest'
2
+ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
3
3
  import {
4
4
  AppBskyActorProfile,
5
5
  AppBskyEmbedGallery,
@@ -46,18 +46,16 @@ describe('pds author feed views', () => {
46
46
  pdsAgent = network.pds.getAgent()
47
47
  sc = network.getSeedClient()
48
48
  await authorFeedSeed(sc)
49
- await network.processAll()
50
49
  alice = sc.dids.alice
51
50
  bob = sc.dids.bob
52
51
  carol = sc.dids.carol
53
52
  dan = sc.dids.dan
54
53
  eve = sc.dids.eve
55
- }, 20_000) // @NOTE seeding can take a while
56
-
57
- afterAll(async () => {
58
- await network.close()
59
54
  })
60
55
 
56
+ beforeEach(async () => network.processAll())
57
+ afterAll(async () => network?.close())
58
+
61
59
  // @TODO(bsky) blocked by actor takedown via labels.
62
60
  // @TODO(bsky) blocked by record takedown via labels.
63
61
 
@@ -1,4 +1,4 @@
1
- import { afterAll, beforeAll, describe, expect, it } from 'vitest'
1
+ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
2
2
  import { AtUri, AtpAgent, ids } from '@atproto/api'
3
3
  import { RecordRef, SeedClient, TestNetwork, basicSeed } from '@atproto/dev-env'
4
4
  import { forSnapshot } from '../_util.js'
@@ -36,12 +36,10 @@ describe('pds views with blocking from block lists', () => {
36
36
  sc.posts[dan][0].ref,
37
37
  'alice replies to dan',
38
38
  )
39
- await network.processAll()
40
39
  })
41
40
 
42
- afterAll(async () => {
43
- await network.close()
44
- })
41
+ beforeEach(async () => network.processAll())
42
+ afterAll(async () => network?.close())
45
43
 
46
44
  let listUri: string
47
45
 
@@ -1,5 +1,5 @@
1
1
  import assert from 'node:assert'
2
- import { afterAll, beforeAll, describe, expect, it } from 'vitest'
2
+ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
3
3
  import {
4
4
  AppBskyEmbedRecord,
5
5
  AppBskyFeedDefs,
@@ -65,12 +65,10 @@ describe('pds views with blocking', () => {
65
65
  sc.getHeaders(dan),
66
66
  )
67
67
  danBlockUri = danBlockCarol.uri
68
- await network.processAll()
69
68
  })
70
69
 
71
- afterAll(async () => {
72
- await network.close()
73
- })
70
+ beforeEach(async () => network.processAll())
71
+ afterAll(async () => network?.close())
74
72
 
75
73
  it('blocks thread post', async () => {
76
74
  const { data: threadAlice } = await agent.api.app.bsky.feed.getPostThread(
@@ -3,6 +3,7 @@ import {
3
3
  afterAll,
4
4
  afterEach,
5
5
  beforeAll,
6
+ beforeEach,
6
7
  describe,
7
8
  expect,
8
9
  it,
@@ -43,7 +44,6 @@ describe('appview bookmarks views', () => {
43
44
  agent = network.bsky.getAgent()
44
45
  sc = network.getSeedClient()
45
46
  await basicSeed(sc)
46
- await network.processAll()
47
47
 
48
48
  alice = sc.dids.alice
49
49
  bob = sc.dids.bob
@@ -51,15 +51,15 @@ describe('appview bookmarks views', () => {
51
51
  dan = sc.dids.dan
52
52
  })
53
53
 
54
+ beforeEach(async () => network.processAll())
55
+
54
56
  afterEach(async () => {
55
57
  vi.resetAllMocks()
56
58
  await clearPrivateData(db)
57
59
  await clearBookmarks(db)
58
60
  })
59
61
 
60
- afterAll(async () => {
61
- await network.close()
62
- })
62
+ afterAll(async () => network?.close())
63
63
 
64
64
  const get = async (actor: string, limit?: number, cursor?: string) =>
65
65
  agent.app.bsky.bookmark.getBookmarks(
@@ -2,6 +2,7 @@ import {
2
2
  afterAll,
3
3
  afterEach,
4
4
  beforeAll,
5
+ beforeEach,
5
6
  describe,
6
7
  expect,
7
8
  it,
@@ -16,7 +17,7 @@ import {
16
17
  ids,
17
18
  } from '@atproto/api'
18
19
  import { TID } from '@atproto/common'
19
- import { SeedClient, TestNetwork, basicSeed } from '@atproto/dev-env'
20
+ import { TestNetwork, basicSeed } from '@atproto/dev-env'
20
21
  import { paginateAll } from '../_util.js'
21
22
 
22
23
  type Database = TestNetwork['bsky']['db']
@@ -26,8 +27,6 @@ const LIMIT = 10
26
27
  describe('appview drafts views', () => {
27
28
  let network: TestNetwork
28
29
  let agent: AtpAgent
29
- let sc: SeedClient
30
- let db: Database
31
30
 
32
31
  // account dids, for convenience
33
32
  let alice: string
@@ -40,24 +39,18 @@ describe('appview drafts views', () => {
40
39
  draftsLimit: LIMIT,
41
40
  },
42
41
  })
43
- db = network.bsky.db
44
42
  agent = network.bsky.getAgent()
45
- sc = network.getSeedClient()
43
+ const sc = network.getSeedClient()
46
44
  await basicSeed(sc)
47
- await network.processAll()
48
45
 
49
46
  alice = sc.dids.alice
50
47
  bob = sc.dids.bob
51
48
  })
52
49
 
53
- afterEach(async () => {
54
- vi.resetAllMocks()
55
- await clearDrafts(db)
56
- })
57
-
58
- afterAll(async () => {
59
- await network.close()
60
- })
50
+ beforeEach(async () => network.processAll())
51
+ afterEach(async () => vi.resetAllMocks())
52
+ afterEach(async () => clearDrafts(network.bsky.db))
53
+ afterAll(async () => network?.close())
61
54
 
62
55
  const makeDraft = (): AppBskyDraftDefs.Draft => ({
63
56
  posts: [{ text: 'Hello, world!' }],
@@ -1,4 +1,4 @@
1
- import { afterAll, beforeAll, describe, expect, it } from 'vitest'
1
+ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
2
2
  import { AtpAgent, ids } from '@atproto/api'
3
3
  import { SeedClient, TestNetwork } from '@atproto/dev-env'
4
4
  import { Users, feedHiddenRepliesSeed } from '../seed/feed-hidden-replies.js'
@@ -20,13 +20,10 @@ describe('feed hidden replies', () => {
20
20
 
21
21
  const result = await feedHiddenRepliesSeed(sc)
22
22
  users = result.users
23
-
24
- await network.processAll()
25
23
  })
26
24
 
27
- afterAll(async () => {
28
- await network.close()
29
- })
25
+ beforeEach(async () => network.processAll())
26
+ afterAll(async () => network?.close())
30
27
 
31
28
  describe(`notifications`, () => {
32
29
  it(`[A] -> [B] : B is hidden`, async () => {
@@ -1,5 +1,5 @@
1
1
  import assert from 'node:assert'
2
- import { afterAll, beforeAll, describe, expect, it } from 'vitest'
2
+ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
3
3
  import { AppBskyFeedDefs, AtUri, AtpAgent, ids } from '@atproto/api'
4
4
  import { SeedClient, TestNetwork, basicSeed } from '@atproto/dev-env'
5
5
 
@@ -47,13 +47,10 @@ describe('pds thread views', () => {
47
47
  await sc.follow(dan, alice)
48
48
  await sc.follow(dan, bob)
49
49
  await sc.follow(dan, carol)
50
-
51
- await network.processAll()
52
50
  })
53
51
 
54
- afterAll(async () => {
55
- await network.close()
56
- })
52
+ beforeEach(async () => network.processAll())
53
+ afterAll(async () => network?.close())
57
54
 
58
55
  it(`[A] -> [B], A blocks B, viewed as C`, async () => {
59
56
  const A = await sc.post(alice, `A`)
@@ -1,4 +1,4 @@
1
- import { afterAll, beforeAll, describe, expect, it } from 'vitest'
1
+ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
2
2
  import {
3
3
  AppBskyGraphGetFollowers,
4
4
  AppBskyGraphGetFollows,
@@ -23,14 +23,12 @@ describe('pds follow views', () => {
23
23
  agent = network.bsky.getAgent()
24
24
  sc = network.getSeedClient()
25
25
  await followsSeed(sc)
26
- await network.processAll()
27
26
  alice = sc.dids.alice
28
- }, 20_000) // @NOTE seeding can take a while
29
-
30
- afterAll(async () => {
31
- await network.close()
32
27
  })
33
28
 
29
+ beforeEach(async () => network.processAll())
30
+ afterAll(async () => network?.close())
31
+
34
32
  // TODO(bsky) blocks followers by actor takedown via labels
35
33
  // TODO(bsky) blocks follows by actor takedown via labels
36
34
 
@@ -1,4 +1,4 @@
1
- import { afterAll, beforeAll, describe, expect, it } from 'vitest'
1
+ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
2
2
  import AtpAgent from '@atproto/api'
3
3
  import { TestNetwork } from '@atproto/dev-env'
4
4
 
@@ -12,13 +12,10 @@ describe('get config', () => {
12
12
  dbPostgresSchema: 'bsky_tests_live_now_config_off',
13
13
  })
14
14
  agent = network.bsky.getAgent()
15
-
16
- await network.processAll()
17
15
  })
18
16
 
19
- afterAll(async () => {
20
- await network.close()
21
- })
17
+ beforeEach(async () => network.processAll())
18
+ afterAll(async () => network?.close())
22
19
 
23
20
  it('omits the live now config', async () => {
24
21
  const res = await agent.app.bsky.unspecced.getConfig()
@@ -55,7 +52,7 @@ describe('get config', () => {
55
52
  })
56
53
 
57
54
  afterAll(async () => {
58
- await network.close()
55
+ await network?.close()
59
56
  })
60
57
 
61
58
  it(`returns the config`, async () => {
@@ -2,7 +2,9 @@ import { once } from 'node:events'
2
2
  import { Server, createServer } from 'node:http'
3
3
  import { AddressInfo } from 'node:net'
4
4
  import express, { Application } from 'express'
5
- import { afterAll, beforeAll, describe, expect, it } from 'vitest'
5
+ // eslint-disable-next-line import/default
6
+ import httpTerminator from 'http-terminator'
7
+ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
6
8
  import {
7
9
  AppBskyUnspeccedGetOnboardingSuggestedUsersSkeleton,
8
10
  AtpAgent,
@@ -83,14 +85,11 @@ describe('getSuggestedOnboardingUsers', () => {
83
85
 
84
86
  const result = await seed(sc)
85
87
  seededUsers = result.users
86
-
87
- await network.processAll()
88
88
  })
89
89
 
90
- afterAll(async () => {
91
- await network.close()
92
- await mockServer.stop()
93
- })
90
+ beforeEach(async () => network.processAll())
91
+ afterAll(async () => network?.close())
92
+ afterAll(async () => mockServer?.stop())
94
93
 
95
94
  describe(`basic handling`, () => {
96
95
  beforeAll(() => {
@@ -150,12 +149,16 @@ describe('getSuggestedOnboardingUsers', () => {
150
149
  class MockServer {
151
150
  app: Application
152
151
  server: Server
152
+ terminator: httpTerminator.HttpTerminator
153
153
 
154
154
  mockedDids = new Map<string, string>()
155
155
 
156
156
  constructor() {
157
157
  this.app = this.createApp()
158
158
  this.server = createServer(this.app)
159
+ this.terminator = httpTerminator.createHttpTerminator({
160
+ server: this.server,
161
+ })
159
162
  }
160
163
 
161
164
  async listen(port?: number) {
@@ -164,8 +167,7 @@ class MockServer {
164
167
  }
165
168
 
166
169
  async stop() {
167
- this.server.close()
168
- await once(this.server, 'close')
170
+ await this.terminator.terminate()
169
171
  }
170
172
 
171
173
  get url() {
@@ -2,7 +2,9 @@ import { once } from 'node:events'
2
2
  import { Server, createServer } from 'node:http'
3
3
  import { AddressInfo } from 'node:net'
4
4
  import express, { Application } from 'express'
5
- import { afterAll, beforeAll, describe, expect, it } from 'vitest'
5
+ // eslint-disable-next-line import/default
6
+ import httpTerminator from 'http-terminator'
7
+ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
6
8
  import {
7
9
  AppBskyUnspeccedGetSuggestedStarterPacksSkeleton,
8
10
  AtpAgent,
@@ -40,14 +42,11 @@ describe('getSuggestedStarterPacks', () => {
40
42
  const result = await starterPacksSeed(sc)
41
43
  users = result.users
42
44
  starterpacks = result.starterpacks
43
-
44
- await network.processAll()
45
45
  })
46
46
 
47
- afterAll(async () => {
48
- await network.close()
49
- await mockServer.stop()
50
- })
47
+ beforeEach(async () => network.processAll())
48
+ afterAll(async () => network?.close())
49
+ afterAll(async () => mockServer?.stop())
51
50
 
52
51
  describe(`basic handling`, () => {
53
52
  beforeAll(() => {
@@ -92,6 +91,7 @@ describe('getSuggestedStarterPacks', () => {
92
91
  class MockServer {
93
92
  app: Application
94
93
  server: Server
94
+ terminator: httpTerminator.HttpTerminator
95
95
 
96
96
  mockedStarterPackUris = new Map<
97
97
  string,
@@ -101,6 +101,9 @@ class MockServer {
101
101
  constructor() {
102
102
  this.app = this.createApp()
103
103
  this.server = createServer(this.app)
104
+ this.terminator = httpTerminator.createHttpTerminator({
105
+ server: this.server,
106
+ })
104
107
  }
105
108
 
106
109
  async listen(port?: number) {
@@ -109,8 +112,7 @@ class MockServer {
109
112
  }
110
113
 
111
114
  async stop() {
112
- this.server.close()
113
- await once(this.server, 'close')
115
+ await this.terminator.terminate()
114
116
  }
115
117
 
116
118
  get url() {
@@ -3,7 +3,9 @@ import { once } from 'node:events'
3
3
  import { Server, createServer } from 'node:http'
4
4
  import { AddressInfo } from 'node:net'
5
5
  import express, { Application } from 'express'
6
- import { afterAll, beforeAll, describe, expect, it } from 'vitest'
6
+ // eslint-disable-next-line import/default
7
+ import httpTerminator from 'http-terminator'
8
+ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
7
9
  import { AppBskyUnspeccedGetTrendsSkeleton, AtpAgent, ids } from '@atproto/api'
8
10
  import { SeedClient, TestNetwork } from '@atproto/dev-env'
9
11
  import { Users, trendsSeed } from '../seed/get-trends.js'
@@ -31,14 +33,11 @@ describe('getTrends', () => {
31
33
 
32
34
  const result = await trendsSeed(sc)
33
35
  users = result.users
34
-
35
- await network.processAll()
36
36
  })
37
37
 
38
- afterAll(async () => {
39
- await network.close()
40
- await mockTrendServer.stop()
41
- })
38
+ beforeEach(async () => network.processAll())
39
+ afterAll(async () => network?.close())
40
+ afterAll(async () => mockTrendServer?.stop())
42
41
 
43
42
  describe(`basic handling`, () => {
44
43
  beforeAll(() => {
@@ -96,6 +95,7 @@ describe('getTrends', () => {
96
95
  class MockTrendsServer {
97
96
  app: Application
98
97
  server: Server
98
+ terminator: httpTerminator.HttpTerminator
99
99
 
100
100
  mockedTrendSkeletons = new Map<
101
101
  string,
@@ -105,6 +105,9 @@ class MockTrendsServer {
105
105
  constructor() {
106
106
  this.app = this.createApp()
107
107
  this.server = createServer(this.app)
108
+ this.terminator = httpTerminator.createHttpTerminator({
109
+ server: this.server,
110
+ })
108
111
  }
109
112
 
110
113
  async listen(port?: number) {
@@ -113,8 +116,11 @@ class MockTrendsServer {
113
116
  }
114
117
 
115
118
  async stop() {
116
- this.server.close()
117
- await once(this.server, 'close')
119
+ await this.terminator.terminate()
120
+ }
121
+
122
+ async [Symbol.asyncDispose]() {
123
+ await this.stop()
118
124
  }
119
125
 
120
126
  get url() {
@@ -1,4 +1,4 @@
1
- import { afterAll, beforeAll, describe, expect, it } from 'vitest'
1
+ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
2
2
  import { AppBskyActorDefs, AtpAgent } from '@atproto/api'
3
3
  import { SeedClient, TestNetwork } from '@atproto/dev-env'
4
4
  import { knownFollowersSeed } from '../seed/known-followers.js'
@@ -35,13 +35,10 @@ describe('internal actor views', () => {
35
35
  { createdAt: new Date().toISOString(), subject: dids.mix_sp_block_res },
36
36
  seedClient.getHeaders(dids.mix_sub_1),
37
37
  )
38
-
39
- await network.processAll()
40
38
  })
41
39
 
42
- afterAll(async () => {
43
- await network.close()
44
- })
40
+ beforeEach(async () => network.processAll())
41
+ afterAll(async () => network?.close())
45
42
 
46
43
  describe('getProfiles', () => {
47
44
  const getProfiles = async (
@@ -1,4 +1,4 @@
1
- import { afterAll, beforeAll, describe, expect, it } from 'vitest'
1
+ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
2
2
  import { AtpAgent, ids } from '@atproto/api'
3
3
  import { SeedClient, TestNetwork } from '@atproto/dev-env'
4
4
  import { knownFollowersSeed } from '../seed/known-followers.js'
@@ -54,13 +54,10 @@ describe('known followers (social proof)', () => {
54
54
  { createdAt: new Date().toISOString(), subject: dids.mix_sp_block_res },
55
55
  seedClient.getHeaders(dids.mix_sub_1),
56
56
  )
57
-
58
- await network.processAll()
59
57
  })
60
58
 
61
- afterAll(async () => {
62
- await network.close()
63
- })
59
+ beforeEach(async () => network.processAll())
60
+ afterAll(async () => network?.close())
64
61
 
65
62
  /*
66
63
  * Note that this test arbitrarily uses `getFollows` bc atm it returns
@@ -1,5 +1,5 @@
1
1
  import assert from 'node:assert'
2
- import { afterAll, beforeAll, describe, expect, it } from 'vitest'
2
+ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
3
3
  import {
4
4
  AppBskyEmbedRecord,
5
5
  AppBskyLabelerDefs,
@@ -67,12 +67,10 @@ describe('labeler service views', () => {
67
67
  aliceService = new RecordRef(aliceRes.data.uri, aliceRes.data.cid)
68
68
 
69
69
  await sc.like(bob, aliceService)
70
- await network.processAll()
71
70
  })
72
71
 
73
- afterAll(async () => {
74
- await network.close()
75
- })
72
+ beforeEach(async () => network.processAll())
73
+ afterAll(async () => network?.close())
76
74
 
77
75
  it('fetches labelers', async () => {
78
76
  const view = await agent.api.app.bsky.labeler.getServices(
@@ -1,5 +1,5 @@
1
1
  import assert from 'node:assert'
2
- import { afterAll, beforeAll, describe, expect, it } from 'vitest'
2
+ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
3
3
  import { AppBskyFeedDefs, AtpAgent, ids } from '@atproto/api'
4
4
  import { SeedClient, TestNetwork, basicSeed } from '@atproto/dev-env'
5
5
 
@@ -39,14 +39,11 @@ describe('bsky needs-review labels', () => {
39
39
 
40
40
  await sc.follow(sc.dids.bob, sc.dids.geoff)
41
41
 
42
- await network.processAll()
43
-
44
42
  AtpAgent.configure({ appLabelers: [network.ozone.ctx.cfg.service.did] })
45
43
  })
46
44
 
47
- afterAll(async () => {
48
- await network.close()
49
- })
45
+ beforeEach(async () => network.processAll())
46
+ afterAll(async () => network?.close())
50
47
 
51
48
  describe('account-level', () => {
52
49
  beforeAll(async () => {
@@ -1,5 +1,5 @@
1
1
  import assert from 'node:assert'
2
- import { afterAll, beforeAll, describe, expect, it } from 'vitest'
2
+ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
3
3
  import { AppBskyLabelerDefs, AtpAgent, ids } from '@atproto/api'
4
4
  import { RecordRef, SeedClient, TestNetwork, basicSeed } from '@atproto/dev-env'
5
5
 
@@ -131,9 +131,8 @@ describe('bsky takedown labels', () => {
131
131
  await network.bsky.db.db.insertInto('label').values(labels).execute()
132
132
  })
133
133
 
134
- afterAll(async () => {
135
- await network.close()
136
- })
134
+ beforeEach(async () => network.processAll())
135
+ afterAll(async () => network?.close())
137
136
 
138
137
  it('takesdown profiles', async () => {
139
138
  const attempt = agent.api.app.bsky.actor.getProfile({