atproto blogging
1#!/usr/bin/env bash
2# Test scripts for weaver-index XRPC endpoints
3
4set -euo pipefail
5
6BASE_URL="${INDEXER_URL:-http://localhost:3000}"
7DID="did:plc:yfvwmnlztr4dwkb7hwz55r2g"
8
9# Colors for output
10RED='\033[0;31m'
11GREEN='\033[0;32m'
12BLUE='\033[0;34m'
13NC='\033[0m' # No Color
14
15info() { echo -e "${BLUE}==>${NC} $1"; }
16success() { echo -e "${GREEN}✓${NC} $1"; }
17error() { echo -e "${RED}✗${NC} $1"; }
18
19# Health check
20test_health() {
21 info "Testing health endpoint..."
22 curl -s "${BASE_URL}/xrpc/_health" | jq .
23}
24
25# Get profile
26test_get_profile() {
27 info "Testing sh.weaver.actor.getProfile..."
28 curl -s "${BASE_URL}/xrpc/sh.weaver.actor.getProfile?actor=${DID}" | jq .
29}
30
31# Resolve notebook
32test_resolve_notebook() {
33 local name="${1:-weaver}"
34 info "Testing sh.weaver.notebook.resolveNotebook (name=${name})..."
35 curl -s "${BASE_URL}/xrpc/sh.weaver.notebook.resolveNotebook?actor=${DID}&name=${name}" | jq .
36}
37
38# Get entry by URI
39test_get_entry() {
40 local rkey="${1:-3m7tg3ni77tqx}"
41 local uri="at://${DID}/sh.weaver.notebook.entry/${rkey}"
42 info "Testing sh.weaver.notebook.getEntry (rkey=${rkey})..."
43 curl -s "${BASE_URL}/xrpc/sh.weaver.notebook.getEntry?uri=$(urlencode "${uri}")" | jq .
44}
45
46# Resolve entry by name
47test_resolve_entry() {
48 local notebook="${1:-weaver}"
49 local entry="${2:-drafts_privacy}"
50 info "Testing sh.weaver.notebook.resolveEntry (notebook=${notebook}, entry=${entry})..."
51 curl -s "${BASE_URL}/xrpc/sh.weaver.notebook.resolveEntry?actor=${DID}¬ebook=${notebook}&entry=${entry}" | jq .
52}
53
54# URL encode helper
55urlencode() {
56 python3 -c "import urllib.parse; print(urllib.parse.quote('$1', safe=''))"
57}
58
59# Get actor notebooks
60test_actor_notebooks() {
61 local actor="${1:-$DID}"
62 local limit="${2:-10}"
63 info "Testing sh.weaver.actor.getActorNotebooks (actor=${actor}, limit=${limit})..."
64 curl -s "${BASE_URL}/xrpc/sh.weaver.actor.getActorNotebooks?actor=${actor}&limit=${limit}" | jq .
65}
66
67# Get actor notebooks with cursor
68test_actor_notebooks_cursor() {
69 local cursor="$1"
70 local actor="${2:-$DID}"
71 local limit="${3:-10}"
72 info "Testing sh.weaver.actor.getActorNotebooks with cursor..."
73 curl -s "${BASE_URL}/xrpc/sh.weaver.actor.getActorNotebooks?actor=${actor}&limit=${limit}&cursor=${cursor}" | jq .
74}
75
76# Get actor entries
77test_actor_entries() {
78 local actor="${1:-$DID}"
79 local limit="${2:-10}"
80 info "Testing sh.weaver.actor.getActorEntries (actor=${actor}, limit=${limit})..."
81 curl -s "${BASE_URL}/xrpc/sh.weaver.actor.getActorEntries?actor=${actor}&limit=${limit}" | jq .
82}
83
84# Get notebook feed
85test_notebook_feed() {
86 local limit="${1:-10}"
87 info "Testing sh.weaver.notebook.getNotebookFeed (limit=${limit})..."
88 curl -s "${BASE_URL}/xrpc/sh.weaver.notebook.getNotebookFeed?limit=${limit}" | jq .
89}
90
91# Get entry feed
92test_entry_feed() {
93 local limit="${1:-10}"
94 info "Testing sh.weaver.notebook.getEntryFeed (limit=${limit})..."
95 curl -s "${BASE_URL}/xrpc/sh.weaver.notebook.getEntryFeed?limit=${limit}" | jq .
96}
97
98# Get book entry by index
99test_book_entry() {
100 local notebook_rkey="${1:-weaver}"
101 local index="${2:-0}"
102 local notebook_uri="at://${DID}/sh.weaver.notebook.book/${notebook_rkey}"
103 info "Testing sh.weaver.notebook.getBookEntry (notebook=${notebook_uri}, index=${index})..."
104 curl -s "${BASE_URL}/xrpc/sh.weaver.notebook.getBookEntry?notebook=$(urlencode "${notebook_uri}")&index=${index}" | jq .
105}
106
107# Test all entry rkeys
108test_all_entries() {
109 local rkeys=(
110 "3m7tg3ni77tqx"
111 "3m7gtl3v4t3kn"
112 "3m7ekja42a32v"
113 "3m746pdxlldfq"
114 "3m6wvayeoqdx4"
115 "3m6ug3zrwb22v"
116 "3m6sy3qur622v"
117 "3m6mnvrkoeq2v"
118 "3m5mepkowvy2a"
119 "3m4rbphjzt62b"
120 "3m4oy5go4742b"
121 "3m4okwb7wp42b"
122 "3m4ojkfioom2b"
123 )
124
125 for rkey in "${rkeys[@]}"; do
126 test_get_entry "$rkey"
127 echo
128 done
129}
130
131# Run all tests
132test_all() {
133 test_health
134 echo
135 test_get_profile
136 echo
137 test_resolve_notebook "weaver"
138 echo
139 test_resolve_entry "weaver" "drafts_privacy"
140 echo
141 test_get_entry "3m7tg3ni77tqx"
142 echo
143 test_actor_notebooks
144 echo
145 test_actor_entries
146 echo
147 test_notebook_feed
148 echo
149 test_entry_feed
150 echo
151 test_book_entry "3m4rbphheug2b" 0
152}
153
154# Main
155case "${1:-all}" in
156 health)
157 test_health
158 ;;
159 profile)
160 test_get_profile
161 ;;
162 notebook)
163 test_resolve_notebook "${2:-weaver}"
164 ;;
165 entry)
166 test_get_entry "${2:-3m7tg3ni77tqx}"
167 ;;
168 resolve)
169 test_resolve_entry "${2:-weaver}" "${3:-drafts_privacy}"
170 ;;
171 entries)
172 test_all_entries
173 ;;
174 actor-notebooks)
175 test_actor_notebooks "${2:-$DID}" "${3:-10}"
176 ;;
177 actor-entries)
178 test_actor_entries "${2:-$DID}" "${3:-10}"
179 ;;
180 notebook-feed)
181 test_notebook_feed "${2:-10}"
182 ;;
183 entry-feed)
184 test_entry_feed "${2:-10}"
185 ;;
186 book-entry)
187 test_book_entry "${2:-3m4rbphheug2b}" "${3:-0}"
188 ;;
189 all)
190 test_all
191 ;;
192 *)
193 echo "Usage: $0 {health|profile|notebook [name]|entry [rkey]|resolve [notebook] [entry]|entries|actor-notebooks [actor] [limit]|actor-entries [actor] [limit]|notebook-feed [limit]|entry-feed [limit]|book-entry [notebook] [index]|all}"
194 echo
195 echo "Environment:"
196 echo " INDEXER_URL Base URL (default: http://localhost:3000)"
197 exit 1
198 ;;
199esac