Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200#!/usr/bin/env bash# Test scripts for weaver-index XRPC endpoints
set -euo pipefail
BASE_URL="${INDEXER_URL:-http://localhost:3000}"DID="did:plc:yfvwmnlztr4dwkb7hwz55r2g"
# Colors for outputRED='\033[0;31m'GREEN='\033[0;32m'BLUE='\033[0;34m'NC='\033[0m' # No Color
info() { echo -e "${BLUE}==>${NC} $1"; }success() { echo -e "${GREEN}✓${NC} $1"; }error() { echo -e "${RED}✗${NC} $1"; }
# Health checktest_health() { info "Testing health endpoint..." curl -s "${BASE_URL}/xrpc/_health" | jq .}
# Get profiletest_get_profile() { info "Testing sh.weaver.actor.getProfile..." curl -s "${BASE_URL}/xrpc/sh.weaver.actor.getProfile?actor=${DID}" | jq .}
# Resolve notebooktest_resolve_notebook() { local name="${1:-weaver}" info "Testing sh.weaver.notebook.resolveNotebook (name=${name})..." curl -s "${BASE_URL}/xrpc/sh.weaver.notebook.resolveNotebook?actor=${DID}&name=${name}" | jq .}
# Get entry by URItest_get_entry() { local rkey="${1:-3m7tg3ni77tqx}" local uri="at://${DID}/sh.weaver.notebook.entry/${rkey}" info "Testing sh.weaver.notebook.getEntry (rkey=${rkey})..." curl -s "${BASE_URL}/xrpc/sh.weaver.notebook.getEntry?uri=$(urlencode "${uri}")" | jq .}
# Resolve entry by nametest_resolve_entry() { local notebook="${1:-weaver}" local entry="${2:-drafts_privacy}" info "Testing sh.weaver.notebook.resolveEntry (notebook=${notebook}, entry=${entry})..." curl -s "${BASE_URL}/xrpc/sh.weaver.notebook.resolveEntry?actor=${DID}¬ebook=${notebook}&entry=${entry}" | jq .}
# URL encode helperurlencode() { python3 -c "import urllib.parse; print(urllib.parse.quote('$1', safe=''))"}
# Get actor notebookstest_actor_notebooks() { local actor="${1:-$DID}" local limit="${2:-10}" info "Testing sh.weaver.actor.getActorNotebooks (actor=${actor}, limit=${limit})..." curl -s "${BASE_URL}/xrpc/sh.weaver.actor.getActorNotebooks?actor=${actor}&limit=${limit}" | jq .}
# Get actor notebooks with cursortest_actor_notebooks_cursor() { local cursor="$1" local actor="${2:-$DID}" local limit="${3:-10}" info "Testing sh.weaver.actor.getActorNotebooks with cursor..." curl -s "${BASE_URL}/xrpc/sh.weaver.actor.getActorNotebooks?actor=${actor}&limit=${limit}&cursor=${cursor}" | jq .}
# Get actor entriestest_actor_entries() { local actor="${1:-$DID}" local limit="${2:-10}" info "Testing sh.weaver.actor.getActorEntries (actor=${actor}, limit=${limit})..." curl -s "${BASE_URL}/xrpc/sh.weaver.actor.getActorEntries?actor=${actor}&limit=${limit}" | jq .}
# Get notebook feedtest_notebook_feed() { local limit="${1:-10}" info "Testing sh.weaver.notebook.getNotebookFeed (limit=${limit})..." curl -s "${BASE_URL}/xrpc/sh.weaver.notebook.getNotebookFeed?limit=${limit}" | jq .}
# Get entry feedtest_entry_feed() { local limit="${1:-10}" info "Testing sh.weaver.notebook.getEntryFeed (limit=${limit})..." curl -s "${BASE_URL}/xrpc/sh.weaver.notebook.getEntryFeed?limit=${limit}" | jq .}
# Get book entry by indextest_book_entry() { local notebook_rkey="${1:-weaver}" local index="${2:-0}" local notebook_uri="at://${DID}/sh.weaver.notebook.book/${notebook_rkey}" info "Testing sh.weaver.notebook.getBookEntry (notebook=${notebook_uri}, index=${index})..." curl -s "${BASE_URL}/xrpc/sh.weaver.notebook.getBookEntry?notebook=$(urlencode "${notebook_uri}")&index=${index}" | jq .}
# Test all entry rkeystest_all_entries() { local rkeys=( "3m7tg3ni77tqx" "3m7gtl3v4t3kn" "3m7ekja42a32v" "3m746pdxlldfq" "3m6wvayeoqdx4" "3m6ug3zrwb22v" "3m6sy3qur622v" "3m6mnvrkoeq2v" "3m5mepkowvy2a" "3m4rbphjzt62b" "3m4oy5go4742b" "3m4okwb7wp42b" "3m4ojkfioom2b" )
for rkey in "${rkeys[@]}"; do test_get_entry "$rkey" echo done}
# Run all teststest_all() { test_health echo test_get_profile echo test_resolve_notebook "weaver" echo test_resolve_entry "weaver" "drafts_privacy" echo test_get_entry "3m7tg3ni77tqx" echo test_actor_notebooks echo test_actor_entries echo test_notebook_feed echo test_entry_feed echo test_book_entry "3m4rbphheug2b" 0}
# Maincase "${1:-all}" in health) test_health ;; profile) test_get_profile ;; notebook) test_resolve_notebook "${2:-weaver}" ;; entry) test_get_entry "${2:-3m7tg3ni77tqx}" ;; resolve) test_resolve_entry "${2:-weaver}" "${3:-drafts_privacy}" ;; entries) test_all_entries ;; actor-notebooks) test_actor_notebooks "${2:-$DID}" "${3:-10}" ;; actor-entries) test_actor_entries "${2:-$DID}" "${3:-10}" ;; notebook-feed) test_notebook_feed "${2:-10}" ;; entry-feed) test_entry_feed "${2:-10}" ;; book-entry) test_book_entry "${2:-3m4rbphheug2b}" "${3:-0}" ;; all) test_all ;; *) 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}" echo echo "Environment:" echo " INDEXER_URL Base URL (default: http://localhost:3000)" exit 1 ;;esac