at protocol indexer with flexible filtering, xrpc queries, and a cursor-backed event stream, built on fjall
at-protocol
atproto
indexer
rust
fjall
1#!/usr/bin/env nu
2use common.nu *
3
4def main [] {
5 let did = "did:web:guestbook.gaze.systems"
6 let port = 3003
7 let debug_port = $port + 1
8 let url = $"http://localhost:($port)"
9 let debug_url = $"http://localhost:($debug_port)"
10 let db_path = (mktemp -d -t hydrant_debug_test.XXXXXX)
11
12 print $"testing debug endpoints..."
13 print $"database path: ($db_path)"
14
15 let binary = build-hydrant
16 let instance = start-hydrant $binary $db_path $port
17
18 if (wait-for-api $url) {
19 # Trigger backfill to populate some data
20 print $"adding repo ($did) to tracking..."
21 http put -t application/json $"($url)/repos" [ { did: ($did) } ]
22
23 if (wait-for-backfill $url) {
24 print "backfill complete, testing debug endpoints"
25
26 # 1. Test /debug/iter to find a key
27 print "testing /debug/iter on records partition"
28 let records = http get $"($debug_url)/debug/iter?partition=records&limit=1"
29
30 if ($records.items | is-empty) {
31 print "FAILED: /debug/iter returned empty items"
32 exit 1
33 }
34
35 let first_item = ($records.items | first)
36 let key_str = $first_item.0
37 let value_cid = $first_item.1
38
39 print $"found key: ($key_str)"
40 print $"found value [cid]: ($value_cid)"
41
42 if not ($key_str | str contains "|") {
43 print "FAILED: key does not contain pipe separator"
44 exit 1
45 }
46
47 # 2. Test /debug/get with that key (sent as string)
48 print "testing /debug/get"
49 let encoded_key = ($key_str | url encode)
50 let get_res = http get $"($debug_url)/debug/get?partition=records&key=($encoded_key)"
51
52 if $get_res.value != $value_cid {
53 print $"FAILED: /debug/get returned different value. expected: ($value_cid), got: ($get_res.value)"
54 exit 1
55 }
56
57 print "PASSED: /debug/iter and /debug/get works with string keys and JSON values"
58
59 # 3. Test /debug/iter on events partition (should be JSON objects)
60 print "testing /debug/iter on events partition"
61 let events = http get $"($debug_url)/debug/iter?partition=events&limit=1"
62
63 if ($events.items | is-empty) {
64 # might be empty if no events yet (backfill only fills records?)
65 # Backfill should generate events? ops.rs makes events.
66 print "WARNING: /debug/iter returned empty items for events (expected if async?)"
67 } else {
68 let first_evt = ($events.items | first)
69 let val = $first_evt.1
70 let type = ($val | describe)
71 print $"found event value type: ($type)"
72 if not ($type | str starts-with "record") {
73 print $"FAILED: events value is not a record/object. got: ($type)"
74 exit 1
75 }
76 print "PASSED: /debug/iter on events returns JSON objects"
77 }
78
79 } else {
80 print "backfill failed"
81 exit 1
82 }
83 } else {
84 print "api failed to start"
85 exit 1
86 }
87
88 try { kill $instance.pid }
89}