@atproto/api 0.5.4 → 0.6.0

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.
@@ -0,0 +1,334 @@
1
+ import { moderateProfile, moderatePost } from '../src'
2
+ import { mock } from './util'
3
+ import './util/moderation-behavior'
4
+
5
+ describe('Moderation', () => {
6
+ it('Applies self-labels on profiles according to the global preferences', () => {
7
+ // porn (hide)
8
+ const res1 = moderateProfile(
9
+ mock.profileViewBasic({
10
+ handle: 'bob.test',
11
+ displayName: 'Bob',
12
+ labels: [
13
+ {
14
+ src: 'did:web:bob.test',
15
+ uri: 'at://did:web:bob.test/app.bsky.actor.profile/self',
16
+ val: 'porn',
17
+ cts: new Date().toISOString(),
18
+ },
19
+ ],
20
+ }),
21
+ {
22
+ userDid: 'did:web:alice.test',
23
+ adultContentEnabled: true,
24
+ labels: {
25
+ porn: 'hide',
26
+ },
27
+ labelers: [],
28
+ },
29
+ )
30
+ expect(res1.account).toBeModerationResult(
31
+ {},
32
+ 'post content',
33
+ JSON.stringify(res1, null, 2),
34
+ )
35
+ expect(res1.profile).toBeModerationResult(
36
+ {},
37
+ 'post content',
38
+ JSON.stringify(res1, null, 2),
39
+ )
40
+ expect(res1.avatar).toBeModerationResult(
41
+ { blur: true },
42
+ 'post avatar',
43
+ JSON.stringify(res1, null, 2),
44
+ true,
45
+ )
46
+
47
+ // porn (ignore)
48
+ const res2 = moderateProfile(
49
+ mock.profileViewBasic({
50
+ handle: 'bob.test',
51
+ displayName: 'Bob',
52
+ labels: [
53
+ {
54
+ src: 'did:web:bob.test',
55
+ uri: 'at://did:web:bob.test/app.bsky.actor.profile/self',
56
+ val: 'porn',
57
+ cts: new Date().toISOString(),
58
+ },
59
+ ],
60
+ }),
61
+ {
62
+ userDid: 'did:web:alice.test',
63
+ adultContentEnabled: true,
64
+ labels: {
65
+ porn: 'ignore',
66
+ },
67
+ labelers: [],
68
+ },
69
+ )
70
+ expect(res2.account).toBeModerationResult(
71
+ {},
72
+ 'post content',
73
+ JSON.stringify(res2, null, 2),
74
+ )
75
+ expect(res2.profile).toBeModerationResult(
76
+ {},
77
+ 'post content',
78
+ JSON.stringify(res2, null, 2),
79
+ )
80
+ expect(res2.avatar).toBeModerationResult(
81
+ {},
82
+ 'post avatar',
83
+ JSON.stringify(res2, null, 2),
84
+ true,
85
+ )
86
+ })
87
+
88
+ it('Applies self-labels on posts according to the global preferences', () => {
89
+ // porn (hide)
90
+ const res1 = moderatePost(
91
+ mock.postView({
92
+ record: {
93
+ text: 'Hello',
94
+ createdAt: new Date().toISOString(),
95
+ },
96
+ author: mock.profileViewBasic({
97
+ handle: 'bob.test',
98
+ displayName: 'Bob',
99
+ }),
100
+ labels: [
101
+ {
102
+ src: 'did:web:bob.test',
103
+ uri: 'at://did:web:bob.test/app.bsky.actor.profile/self',
104
+ val: 'porn',
105
+ cts: new Date().toISOString(),
106
+ },
107
+ ],
108
+ }),
109
+ {
110
+ userDid: 'did:web:alice.test',
111
+ adultContentEnabled: true,
112
+ labels: {
113
+ porn: 'hide',
114
+ },
115
+ labelers: [],
116
+ },
117
+ )
118
+ expect(res1.content).toBeModerationResult(
119
+ { cause: 'label:porn', filter: true },
120
+ 'post content',
121
+ JSON.stringify(res1, null, 2),
122
+ )
123
+ expect(res1.embed).toBeModerationResult(
124
+ { cause: 'label:porn', blur: true },
125
+ 'post content',
126
+ JSON.stringify(res1, null, 2),
127
+ )
128
+ expect(res1.avatar).toBeModerationResult(
129
+ {},
130
+ 'post avatar',
131
+ JSON.stringify(res1, null, 2),
132
+ true,
133
+ )
134
+
135
+ // porn (ignore)
136
+ const res2 = moderatePost(
137
+ mock.postView({
138
+ record: {
139
+ text: 'Hello',
140
+ createdAt: new Date().toISOString(),
141
+ },
142
+ author: mock.profileViewBasic({
143
+ handle: 'bob.test',
144
+ displayName: 'Bob',
145
+ }),
146
+ labels: [
147
+ {
148
+ src: 'did:web:bob.test',
149
+ uri: 'at://did:web:bob.test/app.bsky.actor.profile/self',
150
+ val: 'porn',
151
+ cts: new Date().toISOString(),
152
+ },
153
+ ],
154
+ }),
155
+ {
156
+ userDid: 'did:web:alice.test',
157
+ adultContentEnabled: true,
158
+ labels: {
159
+ porn: 'ignore',
160
+ },
161
+ labelers: [],
162
+ },
163
+ )
164
+ expect(res2.content).toBeModerationResult(
165
+ {},
166
+ 'post content',
167
+ JSON.stringify(res2, null, 2),
168
+ )
169
+ expect(res2.embed).toBeModerationResult(
170
+ {},
171
+ 'post content',
172
+ JSON.stringify(res2, null, 2),
173
+ )
174
+ expect(res2.avatar).toBeModerationResult(
175
+ {},
176
+ 'post avatar',
177
+ JSON.stringify(res2, null, 2),
178
+ true,
179
+ )
180
+ })
181
+
182
+ it('Applies labeler labels according to the per-labeler then global preferences', () => {
183
+ // porn (ignore for labeler, hide for global)
184
+ const res1 = moderateProfile(
185
+ mock.profileViewBasic({
186
+ handle: 'bob.test',
187
+ displayName: 'Bob',
188
+ labels: [
189
+ {
190
+ src: 'did:web:labeler.test',
191
+ uri: 'at://did:web:bob.test/app.bsky.actor.profile/self',
192
+ val: 'porn',
193
+ cts: new Date().toISOString(),
194
+ },
195
+ ],
196
+ }),
197
+ {
198
+ userDid: 'did:web:alice.test',
199
+ adultContentEnabled: true,
200
+ labels: {
201
+ porn: 'hide',
202
+ },
203
+ labelers: [
204
+ {
205
+ labeler: {
206
+ did: 'did:web:labeler.test',
207
+ displayName: 'Labeler',
208
+ },
209
+ labels: {
210
+ porn: 'ignore',
211
+ },
212
+ },
213
+ ],
214
+ },
215
+ )
216
+ expect(res1.avatar).toBeModerationResult(
217
+ {},
218
+ 'post avatar',
219
+ JSON.stringify(res1, null, 2),
220
+ true,
221
+ )
222
+
223
+ // porn (hide for labeler, ignore for global)
224
+ const res2 = moderateProfile(
225
+ mock.profileViewBasic({
226
+ handle: 'bob.test',
227
+ displayName: 'Bob',
228
+ labels: [
229
+ {
230
+ src: 'did:web:labeler.test',
231
+ uri: 'at://did:web:bob.test/app.bsky.actor.profile/self',
232
+ val: 'porn',
233
+ cts: new Date().toISOString(),
234
+ },
235
+ ],
236
+ }),
237
+ {
238
+ userDid: 'did:web:alice.test',
239
+ adultContentEnabled: true,
240
+ labels: {
241
+ porn: 'ignore',
242
+ },
243
+ labelers: [
244
+ {
245
+ labeler: {
246
+ did: 'did:web:labeler.test',
247
+ displayName: 'Labeler',
248
+ },
249
+ labels: {
250
+ porn: 'hide',
251
+ },
252
+ },
253
+ ],
254
+ },
255
+ )
256
+ expect(res2.avatar).toBeModerationResult(
257
+ { blur: true },
258
+ 'post avatar',
259
+ JSON.stringify(res2, null, 2),
260
+ true,
261
+ )
262
+
263
+ // porn (unspecified for labeler, hide for global)
264
+ const res3 = moderateProfile(
265
+ mock.profileViewBasic({
266
+ handle: 'bob.test',
267
+ displayName: 'Bob',
268
+ labels: [
269
+ {
270
+ src: 'did:web:labeler.test',
271
+ uri: 'at://did:web:bob.test/app.bsky.actor.profile/self',
272
+ val: 'porn',
273
+ cts: new Date().toISOString(),
274
+ },
275
+ ],
276
+ }),
277
+ {
278
+ userDid: 'did:web:alice.test',
279
+ adultContentEnabled: true,
280
+ labels: {
281
+ porn: 'hide',
282
+ },
283
+ labelers: [
284
+ {
285
+ labeler: {
286
+ did: 'did:web:labeler.test',
287
+ displayName: 'Labeler',
288
+ },
289
+ labels: {},
290
+ },
291
+ ],
292
+ },
293
+ )
294
+ expect(res3.avatar).toBeModerationResult(
295
+ { blur: true },
296
+ 'post avatar',
297
+ JSON.stringify(res3, null, 2),
298
+ true,
299
+ )
300
+ })
301
+
302
+ /*
303
+ TODO enable when 3P labeler support is addded
304
+ it('Ignores labels from unknown labelers', () => {
305
+ const res1 = moderateProfile(
306
+ mock.profileViewBasic({
307
+ handle: 'bob.test',
308
+ displayName: 'Bob',
309
+ labels: [
310
+ {
311
+ src: 'did:web:rando.test',
312
+ uri: 'at://did:web:bob.test/app.bsky.actor.profile/self',
313
+ val: 'porn',
314
+ cts: new Date().toISOString(),
315
+ },
316
+ ],
317
+ }),
318
+ {
319
+ userDid: 'did:web:alice.test',
320
+ adultContentEnabled: true,
321
+ labels: {
322
+ porn: 'hide',
323
+ },
324
+ labelers: [],
325
+ },
326
+ )
327
+ expect(res1.avatar).toBeModerationResult(
328
+ {},
329
+ 'post avatar',
330
+ JSON.stringify(res1, null, 2),
331
+ true,
332
+ )
333
+ })*/
334
+ })
@@ -166,13 +166,14 @@ export class ModerationBehaviorSuiteRunner {
166
166
  adultContentEnabled: Boolean(
167
167
  this.suite.configurations[scenario.cfg].adultContentEnabled,
168
168
  ),
169
- labelerSettings: [
169
+ labels: this.suite.configurations[scenario.cfg].settings,
170
+ labelers: [
170
171
  {
171
172
  labeler: {
172
173
  did: 'did:plc:fake-labeler',
173
174
  displayName: 'Fake Labeler',
174
175
  },
175
- settings: this.suite.configurations[scenario.cfg].settings,
176
+ labels: this.suite.configurations[scenario.cfg].settings,
176
177
  },
177
178
  ],
178
179
  }