aturi indexer with listRecords and countRecords endpoints
1#!/usr/bin/env nu
2
3let did = "did:plc:dfl62fgb7wtjj3fcbb72naae"
4let pds_host = "https://zwsp.xyz"
5
6# wait for indexing
7print "waiting for services to stabilize..."
8sleep 5sec
9
10# add dids to tap
11let dids = ["did:plc:dfl62fgb7wtjj3fcbb72naae", "did:plc:dumbmutt4po52ept2tczimje"]
12try {
13 let body = {dids: $dids} | to json
14 http post --content-type application/json "http://127.0.0.1:2480/repos/add" $body
15} catch {
16 print "tap add repos failed (maybe already running)"
17}
18
19sleep 5sec
20
21# 1. test app.bsky.actor.profile (single record)
22let collection = "app.bsky.actor.profile"
23print $"verifying ($collection) for ($did)..."
24
25let atur_url = $"http://127.0.0.1:7155/xrpc/systems.gaze.aturlist.listRecords?repo=($did)&collection=($collection)"
26print $"aturlist url: ($atur_url)"
27let atur_res = (http get $atur_url)
28let atur_uris = ($atur_res.aturis | sort)
29
30let pds_url = $"($pds_host)/xrpc/com.atproto.repo.listRecords?repo=($did)&collection=($collection)"
31print $"pds url: ($pds_url)"
32let pds_res = (http get $pds_url)
33let pds_uris = ($pds_res.records | each {|r| $r.uri } | sort)
34
35if ($atur_uris == $pds_uris) {
36 print "success: profile matches."
37} else {
38 print "failure: profile mismatch."
39 print "aturlist: " $atur_uris
40 print "pds: " $pds_uris
41 exit 1
42}
43
44# 2. test app.bsky.feed.like (multiple records)
45let collection = "app.bsky.feed.like"
46let limit = 20
47
48# ascending check (oldest)
49print $"\nverifying ($collection) ascending \(oldest\)..."
50# aturlist: reverse=true -> ascending
51let atur_url_asc = $"http://127.0.0.1:7155/xrpc/systems.gaze.aturlist.listRecords?repo=($did)&collection=($collection)&reverse=true"
52print $"aturlist asc url: ($atur_url_asc)"
53let atur_res_asc = (http get $atur_url_asc)
54let atur_uris_asc = ($atur_res_asc.aturis | first $limit)
55
56# pds: reverse=true -> ascending
57let pds_url_asc = $"($pds_host)/xrpc/com.atproto.repo.listRecords?repo=($did)&collection=($collection)&limit=($limit)&reverse=true"
58print $"pds asc url: ($pds_url_asc)"
59let pds_res_asc = (http get $pds_url_asc)
60let pds_uris_asc = ($pds_res_asc.records | each {|r| $r.uri })
61
62if ($atur_uris_asc == $pds_uris_asc) {
63 print "success: ascending (oldest) matches."
64} else {
65 print "failure: ascending mismatch."
66 print "aturlist:" $atur_uris_asc
67 print "pds:" $pds_uris_asc
68 exit 1
69}
70
71# descending check (newest)
72print $"\nverifying ($collection) descending \(newest\)..."
73# aturlist: reverse=false (default) -> descending
74let atur_url_desc = $"http://127.0.0.1:7155/xrpc/systems.gaze.aturlist.listRecords?repo=($did)&collection=($collection)&reverse=false"
75print $"aturlist desc url: ($atur_url_desc)"
76let atur_res_desc = (http get $atur_url_desc)
77let atur_uris_desc = ($atur_res_desc.aturis | first $limit)
78
79# pds: reverse=false (default) -> descending
80let pds_url_desc = $"($pds_host)/xrpc/com.atproto.repo.listRecords?repo=($did)&collection=($collection)&limit=($limit)&reverse=false"
81print $"pds desc url: ($pds_url_desc)"
82let pds_res_desc = (http get $pds_url_desc)
83let pds_uris_desc = ($pds_res_desc.records | each {|r| $r.uri })
84
85if ($atur_uris_desc == $pds_uris_desc) {
86 print "success: descending (newest) matches perfectly."
87} else {
88 # check for lag consistency
89 let head = ($atur_uris_desc | first)
90 if ($head in $pds_uris_desc) {
91 print "warning: lag detected, but consistent."
92 } else {
93 print "failure: descending mismatch (and head not found in pds top 20)."
94 exit 1
95 }
96}
97
98# 3. test countrecords
99print $"\nverifying countrecords for ($collection)..."
100let atur_count_url = $"http://127.0.0.1:7155/xrpc/systems.gaze.aturlist.countRecords?repo=($did)&collection=($collection)"
101print $"aturlist count url: ($atur_count_url)"
102let atur_count_res = (http get $atur_count_url)
103print $"aturlist count: ($atur_count_res.count)"
104
105if ($atur_count_res.count > 0) {
106 print "success: count is positive."
107} else {
108 print "warning: count is 0 (expected if db was reused without migration/reindex)."
109}
110
111print "\nverification summary: success."