Skip to content

Commit cdb6b27

Browse files
[TS-160] Add debug field to PostView and ProfileView*s (#4297)
* Add debug field to lex and proto, codegen * Include debug field for DIDs configured via env var * Gen bufs * Update types and view * Add debug field to profile views * Safely populate debug field * Format * Use util * Simplify existence check * Values may be undefined * Clarify type * Update descriptions * Include default value for dev-env * Add test harness (cherry picked from commit 7e49b4cf4cf3cbb989114540081e74f7a34acb6f) * Use unknown field type instead of serializing * KISS keep it set stupid * Fix comments * Differentiate between source of debug * Add matching profile view test * Specifying types of the merged objects isn't really helpful * Changeset * Add comment * Put includeDebugField on HydrateCtx and use in views * Mutate TestNetwork innards for tests * Format * Use separate debug schema for profile test * Little more terse * Oops, remove last usage * Remove vestigial props * Include other actor metadata * Simply views, remove debugField
1 parent d764c54 commit cdb6b27

File tree

24 files changed

+320
-2
lines changed

24 files changed

+320
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@atproto/bsky": patch
3+
---
4+
5+
Add `debug` field to `PostView` and `ProfileView*`s

lexicons/app/bsky/actor/defs.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
"status": {
3333
"type": "ref",
3434
"ref": "#statusView"
35+
},
36+
"debug": {
37+
"type": "unknown",
38+
"description": "Debug information for internal development"
3539
}
3640
}
3741
},
@@ -71,6 +75,10 @@
7175
"status": {
7276
"type": "ref",
7377
"ref": "#statusView"
78+
},
79+
"debug": {
80+
"type": "unknown",
81+
"description": "Debug information for internal development"
7482
}
7583
}
7684
},
@@ -123,6 +131,10 @@
123131
"status": {
124132
"type": "ref",
125133
"ref": "#statusView"
134+
},
135+
"debug": {
136+
"type": "unknown",
137+
"description": "Debug information for internal development"
126138
}
127139
}
128140
},

lexicons/app/bsky/feed/defs.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@
3434
"type": "array",
3535
"items": { "type": "ref", "ref": "com.atproto.label.defs#label" }
3636
},
37-
"threadgate": { "type": "ref", "ref": "#threadgateView" }
37+
"threadgate": { "type": "ref", "ref": "#threadgateView" },
38+
"debug": {
39+
"type": "unknown",
40+
"description": "Debug information for internal development"
41+
}
3842
}
3943
},
4044
"viewerState": {

packages/api/src/client/lexicons.ts

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/api/src/client/types/app/bsky/actor/defs.ts

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/api/src/client/types/app/bsky/feed/defs.ts

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/bsky/src/config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export interface ServerConfigValues {
8484
proxyMaxRetries?: number
8585
proxyPreferCompressed?: boolean
8686
kws?: KwsConfig
87+
debugFieldAllowedDids: Set<string>
8788
}
8889

8990
export class ServerConfig {
@@ -276,6 +277,10 @@ export class ServerConfig {
276277
}
277278
}
278279

280+
const debugFieldAllowedDids = new Set(
281+
envList(process.env.BSKY_DEBUG_FIELD_ALLOWED_DIDS),
282+
)
283+
279284
return new ServerConfig({
280285
version,
281286
debugMode,
@@ -334,6 +339,7 @@ export class ServerConfig {
334339
proxyMaxRetries,
335340
proxyPreferCompressed,
336341
kws,
342+
debugFieldAllowedDids,
337343
...stripUndefineds(overrides ?? {}),
338344
})
339345
}
@@ -572,6 +578,10 @@ export class ServerConfig {
572578
get kws() {
573579
return this.cfg.kws
574580
}
581+
582+
get debugFieldAllowedDids() {
583+
return this.cfg.debugFieldAllowedDids
584+
}
575585
}
576586

577587
function stripUndefineds(

packages/bsky/src/hydration/actor.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ export type Actor = {
3838
verifications: VerificationHydrationState[]
3939
status?: RecordInfo<StatusRecord>
4040
allowActivitySubscriptionsFrom: AllowActivitySubscriptions
41+
/**
42+
* Debug information for internal development
43+
*/
44+
debug?: {
45+
pagerank?: number
46+
accountTags?: string[]
47+
profileTags?: string[]
48+
[key: string]: unknown
49+
}
4150
}
4251

4352
export type VerificationHydrationState = {
@@ -213,6 +222,12 @@ export class ActorHydrator {
213222
}
214223
}
215224

225+
const debug = {
226+
pagerank: actor.pagerank,
227+
accountTags: actor.tags,
228+
profileTags: actor.profileTags,
229+
}
230+
216231
return acc.set(did, {
217232
did,
218233
handle: parseString(actor.handle),
@@ -233,6 +248,7 @@ export class ActorHydrator {
233248
allowActivitySubscriptionsFrom: allowActivitySubscriptionsFrom(
234249
actor.allowActivitySubscriptionsFrom,
235250
),
251+
debug,
236252
})
237253
}, new HydrationMap<Actor>())
238254
}

packages/bsky/src/hydration/feed.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ export type Post = RecordInfo<PostRecord> & {
2626
hasThreadGate: boolean
2727
hasPostGate: boolean
2828
tags: Set<string>
29+
/**
30+
* Debug information for internal development
31+
*/
32+
debug?: {
33+
tags?: string[]
34+
[key: string]: unknown
35+
}
2936
}
3037
export type Posts = HydrationMap<Post>
3138

@@ -117,6 +124,7 @@ export class FeedHydrator {
117124
const hasThreadGate = res.meta[i].hasThreadGate
118125
const hasPostGate = res.meta[i].hasPostGate
119126
const tags = new Set<string>(res.records[i].tags ?? [])
127+
const debug = { tags: Array.from(tags) }
120128
return acc.set(
121129
uri,
122130
record
@@ -127,6 +135,7 @@ export class FeedHydrator {
127135
hasThreadGate,
128136
hasPostGate,
129137
tags,
138+
debug,
130139
}
131140
: null,
132141
)

packages/bsky/src/hydration/hydrator.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export class HydrateCtx {
8080
includeTakedowns = this.vals.includeTakedowns
8181
includeActorTakedowns = this.vals.includeActorTakedowns
8282
include3pBlocks = this.vals.include3pBlocks
83+
includeDebugField = this.vals.includeDebugField
8384
constructor(private vals: HydrateCtxVals) {}
8485
// Convenience with use with dataplane.getActors cache control
8586
get skipCacheForViewer() {
@@ -97,6 +98,7 @@ export type HydrateCtxVals = {
9798
includeTakedowns?: boolean
9899
includeActorTakedowns?: boolean
99100
include3pBlocks?: boolean
101+
includeDebugField?: boolean
100102
}
101103

102104
export type HydrationState = {
@@ -156,17 +158,28 @@ export type BidirectionalBlocks = HydrationMap<HydrationMap<boolean>>
156158
// actor DID -> stash key -> bookmark
157159
export type Bookmarks = HydrationMap<HydrationMap<Bookmark>>
158160

161+
/**
162+
* Additional config passed from `ServerConfig` to the `Hydrator` instance.
163+
* Values within this config object may be passed to other sub-hydrators.
164+
*/
165+
export type HydratorConfig = {
166+
debugFieldAllowedDids: Set<string>
167+
}
168+
159169
export class Hydrator {
160170
actor: ActorHydrator
161171
feed: FeedHydrator
162172
graph: GraphHydrator
163173
label: LabelHydrator
164174
serviceLabelers: Set<string>
175+
config: HydratorConfig
165176

166177
constructor(
167178
public dataplane: DataPlaneClient,
168179
serviceLabelers: string[] = [],
180+
config: HydratorConfig,
169181
) {
182+
this.config = config
170183
this.actor = new ActorHydrator(dataplane)
171184
this.feed = new FeedHydrator(dataplane)
172185
this.graph = new GraphHydrator(dataplane)
@@ -1283,11 +1296,14 @@ export class Hydrator {
12831296
dids: availableDids,
12841297
redact: vals.labelers.redact,
12851298
}
1299+
const includeDebugField =
1300+
!!vals.viewer && this.config.debugFieldAllowedDids.has(vals.viewer)
12861301
return new HydrateCtx({
12871302
labelers: availableLabelers,
12881303
viewer: vals.viewer,
12891304
includeTakedowns: vals.includeTakedowns,
12901305
include3pBlocks: vals.include3pBlocks,
1306+
includeDebugField,
12911307
})
12921308
}
12931309

0 commit comments

Comments
 (0)