at main 2.9 kB view raw
1#!/bin/bash 2# verify-export-debug.sh - Deep comparison of export endpoints 3 4AFTER="${1:-}" 5COUNT="${2:-1000}" 6LOCAL_URL="http://localhost:8080/api/v1/plc/export" 7REMOTE_URL="https://plc.directory/export" 8 9# Build query parameters 10PARAMS="count=$COUNT" 11if [ -n "$AFTER" ]; then 12 PARAMS="${PARAMS}&after=${AFTER}" 13fi 14 15echo "=== Fetching data ===" 16curl -s "${LOCAL_URL}?${PARAMS}" > /tmp/local_export.jsonl 17curl -s "${REMOTE_URL}?${PARAMS}" > /tmp/remote_export.jsonl 18 19echo "Local file size: $(wc -c < /tmp/local_export.jsonl) bytes" 20echo "Remote file size: $(wc -c < /tmp/remote_export.jsonl) bytes" 21echo "" 22 23echo "Local lines: $(wc -l < /tmp/local_export.jsonl)" 24echo "Remote lines: $(wc -l < /tmp/remote_export.jsonl)" 25echo "" 26 27# Check for trailing newline 28echo "Local ends with newline: $(tail -c 1 /tmp/local_export.jsonl | xxd -p)" 29echo "Remote ends with newline: $(tail -c 1 /tmp/remote_export.jsonl | xxd -p)" 30echo "(0a = newline, other = no trailing newline)" 31echo "" 32 33# Compare line by line 34echo "=== Comparing CIDs line by line ===" 35LOCAL_CIDS=$(cat /tmp/local_export.jsonl | jq -r '.cid' 2>/dev/null) 36REMOTE_CIDS=$(cat /tmp/remote_export.jsonl | jq -r '.cid' 2>/dev/null) 37 38if [ "$LOCAL_CIDS" = "$REMOTE_CIDS" ]; then 39 echo "✅ All CIDs match in order" 40else 41 echo "❌ CIDs differ" 42 echo "" 43 echo "First 5 local CIDs:" 44 echo "$LOCAL_CIDS" | head -5 45 echo "" 46 echo "First 5 remote CIDs:" 47 echo "$REMOTE_CIDS" | head -5 48fi 49echo "" 50 51# Compare exact JSON of first operation 52echo "=== First operation comparison ===" 53echo "Local:" 54head -1 /tmp/local_export.jsonl | jq . 2>/dev/null || head -1 /tmp/local_export.jsonl 55echo "" 56echo "Remote:" 57head -1 /tmp/remote_export.jsonl | jq . 2>/dev/null || head -1 /tmp/remote_export.jsonl 58echo "" 59 60# Check if it's just a trailing newline issue 61echo "=== Testing trailing newline hypothesis ===" 62LOCAL_HASH_NO_TRAIL=$(head -c -1 /tmp/local_export.jsonl | shasum -a 256 | cut -d' ' -f1) 63REMOTE_HASH_NO_TRAIL=$(head -c -1 /tmp/remote_export.jsonl | shasum -a 256 | cut -d' ' -f1) 64 65LOCAL_HASH_WITH_TRAIL=$(cat /tmp/local_export.jsonl && echo "" | shasum -a 256 | cut -d' ' -f1) 66 67echo "Local hash (as-is): $(shasum -a 256 < /tmp/local_export.jsonl | cut -d' ' -f1)" 68echo "Remote hash (as-is): $(shasum -a 256 < /tmp/remote_export.jsonl | cut -d' ' -f1)" 69echo "Local hash (no trailing \\n): $LOCAL_HASH_NO_TRAIL" 70echo "Remote hash (no trailing \\n): $REMOTE_HASH_NO_TRAIL" 71 72if [ "$LOCAL_HASH_NO_TRAIL" = "$(shasum -a 256 < /tmp/remote_export.jsonl | cut -d' ' -f1)" ]; then 73 echo "" 74 echo "🔍 Found it! Local is missing trailing newline" 75elif [ "$(shasum -a 256 < /tmp/local_export.jsonl | cut -d' ' -f1)" = "$REMOTE_HASH_NO_TRAIL" ]; then 76 echo "" 77 echo "🔍 Found it! Remote is missing trailing newline" 78fi 79 80# Clean up 81rm -f /tmp/local_export.jsonl /tmp/remote_export.jsonl 82