← back to Dw Kravet Hires
data/tk12097/verify-sample.sh
41 lines
#!/bin/bash
# Spot-verify a batch ledger against LIVE Shopify.
# For N random rows: confirm the product's CURRENT featured media is the ledger's
# new_media_id AND that its width exceeds the recorded old media's width.
# Read-only. Usage: verify-sample.sh <ledger> <n>
set -uo pipefail
L="$1"; N="${2:-10}"
TOKEN=$(grep -m1 '^SHOPIFY_ADMIN_TOKEN=' ~/Projects/secrets-manager/.env | cut -d= -f2- | tr -d '"'"'"' ')
API="https://designer-laboratory-sandbox.myshopify.com/admin/api/2024-10/graphql.json"
pass=0; fail=0; notmeasured=0
# de-dup by product so a double-applied product is sampled once
jq -s -c 'group_by(.shopify_id)|map(.[-1])|.[]' "$L" | sort -R | head -n "$N" | while IFS= read -r row; do
pid=$(echo "$row" | jq -r .shopify_id)
newid=$(echo "$row" | jq -r .new_media_id)
oldid=$(echo "$row" | jq -r .old_media_id)
sku=$(echo "$row" | jq -r .mfr_sku)
resp=$(curl -s --max-time 25 -X POST "$API" \
-H "X-Shopify-Access-Token: $TOKEN" -H "Content-Type: application/json" \
-d "{\"query\":\"{ product(id:\\\"$pid\\\") { media(first:25) { edges { node { id ... on MediaImage { image { width height } } } } } } }\"}")
# NOT-MEASURED guard: no data back means we did not measure, never call it a pass
if ! echo "$resp" | jq -e '.data.product.media.edges' >/dev/null 2>&1; then
echo "NOT-MEASURED $sku $pid — $(echo "$resp" | head -c 120)"; continue
fi
featured=$(echo "$resp" | jq -r '.data.product.media.edges[0].node.id')
fw=$(echo "$resp" | jq -r '.data.product.media.edges[0].node.image.width // 0')
ow=$(echo "$resp" | jq -r --arg o "$oldid" '[.data.product.media.edges[]|select(.node.id==$o)|.node.image.width][0] // 0')
if [ "$featured" = "$newid" ] && [ "$fw" -gt "$ow" ] && [ "$ow" -gt 0 ]; then
echo "PASS $sku featured=${fw}px old=${ow}px anchor-retained"
elif [ "$featured" = "$newid" ] && [ "$ow" = "0" ]; then
echo "WARN $sku featured=${fw}px but old anchor $oldid NOT present on product"
else
echo "FAIL $sku featured=$featured (expected $newid) fw=${fw} ow=${ow}"
fi
sleep 0.6
done