Something went wrong. Try again.
A Transparent and Verifiable Way to Sync the AT Protocol's PLC Directory
Something went wrong. Try again.
Shell
at did-resolver
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105#!/bin/bash# test-did-resolution.sh# Compares local DID resolution with plc.directory
set -e
BUNDLE_RANGE="${1:-1}"PLC_URL="https://plc.wtf"TEMP_DIR=$(mktemp -d)trap "rm -rf $TEMP_DIR" EXIT
# ColorsRED='\033[0;31m'GREEN='\033[0;32m'YELLOW='\033[1;33m'NC='\033[0m' # No Color
echo "Testing DID resolution for bundle(s): $BUNDLE_RANGE"echo "Temp directory: $TEMP_DIR"echo ""
# Extract unique DIDs from bundle(s)echo "Extracting DIDs from bundles..."DIDS=$(plcbundle export --bundles "$BUNDLE_RANGE" | jq -r '.did' | sort -u)DID_COUNT=$(echo "$DIDS" | wc -l | tr -d ' ')
echo "Found $DID_COUNT unique DIDs"echo ""
# Test countersTOTAL=0PASSED=0FAILED=0ERRORS=0
# Test each DIDwhile IFS= read -r DID; do TOTAL=$((TOTAL + 1)) # Progress echo -ne "\r[$TOTAL/$DID_COUNT] Testing $DID..." # Resolve locally LOCAL_FILE="$TEMP_DIR/local.json" if ! plcbundle index resolve "$DID" 2>/dev/null | jq --sort-keys . > "$LOCAL_FILE" 2>/dev/null; then echo -e "\r[$TOTAL/$DID_COUNT] ${RED}ERROR${NC} $DID (local resolution failed)" ERRORS=$((ERRORS + 1)) continue fi # Resolve remotely REMOTE_FILE="$TEMP_DIR/remote.json" if ! curl -s "$PLC_URL/$DID" | jq --sort-keys . > "$REMOTE_FILE" 2>/dev/null; then echo -e "\r[$TOTAL/$DID_COUNT] ${YELLOW}SKIP${NC} $DID (remote fetch failed)" ERRORS=$((ERRORS + 1)) continue fi # Compare if diff -q "$LOCAL_FILE" "$REMOTE_FILE" > /dev/null 2>&1; then echo -e "\r[$TOTAL/$DID_COUNT] ${GREEN}✓${NC} $DID" PASSED=$((PASSED + 1)) else echo -e "\r[$TOTAL/$DID_COUNT] ${RED}✗${NC} $DID" echo "" echo "Differences found:" diff -u "$REMOTE_FILE" "$LOCAL_FILE" | head -20 echo "" FAILED=$((FAILED + 1)) # Ask to continue if [ $FAILED -ge 3 ]; then echo "" read -p "Continue testing? (y/N) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then break fi fi fi # Rate limit sleep 0.1 done <<< "$DIDS"
# Summaryecho ""echo "========================================="echo "Test Results"echo "========================================="echo -e "Total: $TOTAL"echo -e "${GREEN}Passed: $PASSED${NC}"echo -e "${RED}Failed: $FAILED${NC}"echo -e "${YELLOW}Errors: $ERRORS${NC}"echo ""
if [ $FAILED -eq 0 ] && [ $ERRORS -eq 0 ]; then echo -e "${GREEN}✓ All tests passed!${NC}" exit 0else echo -e "${RED}✗ Some tests failed${NC}" exit 1fi