[object Object]

← back to Sister Parish Onboarding

sp: preflight.sh — single-shot health read for YOLO ticks

b825dc72f88a9827d63cc977ce43d8a416da2f0c · 2026-05-12 00:30:17 -0700 · SteveStudio2

Replaces the curl+grep+dry-run dance future ticks were doing each time
with one O(1) call. Reports: live SP count (status=any), plist installed
& loaded, dry-run would-create count. Exit code: 0 GREEN, 1 mixed, 2 env fail.

Uses the same node-path fallback chain as scheduled_push.sh (homebrew →
/usr/local → which node) so it works on both Mac1 (homebrew) and Mac2
(/usr/local/bin/node).

Files touched

Diff

commit b825dc72f88a9827d63cc977ce43d8a416da2f0c
Author: SteveStudio2 <stevestudio2@SteveStacStudio.lan>
Date:   Tue May 12 00:30:17 2026 -0700

    sp: preflight.sh — single-shot health read for YOLO ticks
    
    Replaces the curl+grep+dry-run dance future ticks were doing each time
    with one O(1) call. Reports: live SP count (status=any), plist installed
    & loaded, dry-run would-create count. Exit code: 0 GREEN, 1 mixed, 2 env fail.
    
    Uses the same node-path fallback chain as scheduled_push.sh (homebrew →
    /usr/local → which node) so it works on both Mac1 (homebrew) and Mac2
    (/usr/local/bin/node).
---
 scripts/preflight.sh | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/scripts/preflight.sh b/scripts/preflight.sh
new file mode 100755
index 0000000..dbf51ec
--- /dev/null
+++ b/scripts/preflight.sh
@@ -0,0 +1,66 @@
+#!/bin/zsh
+# One-shot pre-flight read of SP push state.
+# Prints:
+#   - DW Shopify store + SP vendor count (current ground truth)
+#   - launchd plist install status + next-fire estimate
+#   - Dry-run "would create" count (should be 73)
+# Exit code: 0 if push is healthy + scheduled, non-zero if something's off.
+#
+# Designed to be called by YOLO-loop ticks for an O(1) SP status read instead
+# of re-deriving it each time from raw curl + grep.
+
+set -uo pipefail
+
+ROOT="$(cd "$(dirname "$0")/.." && pwd)"
+PLIST="$HOME/Library/LaunchAgents/com.steve.sister-parish-push.plist"
+ENV_FILE="$HOME/Projects/dw-collections-viewer/.env"
+
+ok()   { print -P "%F{green}✓%f $1"; }
+warn() { print -P "%F{yellow}⚠%f $1"; }
+fail() { print -P "%F{red}✗%f $1"; }
+
+[[ -f "$ENV_FILE" ]] || { fail "missing $ENV_FILE"; exit 2; }
+set -a; source "$ENV_FILE"; set +a
+
+if [[ -z "${SHOPIFY_STORE:-}" || -z "${SHOPIFY_ADMIN_TOKEN:-}" ]]; then
+  fail "SHOPIFY_STORE / SHOPIFY_ADMIN_TOKEN not set in $ENV_FILE"; exit 2
+fi
+
+print -P "%F{cyan}=== SP push pre-flight · $(date '+%F %T %Z') ===%f"
+print "store: $SHOPIFY_STORE"
+
+# 1) Live SP count
+COUNT_JSON=$(curl -s "https://${SHOPIFY_STORE}/admin/api/2026-01/products/count.json?vendor=Sister+Parish&status=any" \
+  -H "X-Shopify-Access-Token: $SHOPIFY_ADMIN_TOKEN")
+COUNT=$(print "$COUNT_JSON" | /usr/bin/python3 -c "import json,sys; print(json.load(sys.stdin).get('count','?'))" 2>/dev/null)
+print "live SP count (vendor=Sister Parish, status=any): $COUNT"
+
+# 2) launchd plist
+if [[ -f "$PLIST" ]]; then
+  ok "launchd plist installed: $PLIST"
+  /bin/launchctl list 2>/dev/null | grep -q "com.steve.sister-parish-push" && ok "loaded in launchctl" || warn "plist exists but NOT loaded — run: launchctl load $PLIST"
+else
+  warn "plist absent (already self-unloaded? expected after a successful 73-product push)"
+fi
+
+# 3) Dry-run count
+NODE_BIN="/opt/homebrew/bin/node"
+[[ -x "$NODE_BIN" ]] || NODE_BIN="/usr/local/bin/node"
+[[ -x "$NODE_BIN" ]] || NODE_BIN="$(/usr/bin/which node 2>/dev/null)"
+[[ -x "$NODE_BIN" ]] || { fail "no node binary found"; exit 2; }
+print "running dry-run via $NODE_BIN…"
+DRY=$(cd "$ROOT" && SHOPIFY_STORE="$SHOPIFY_STORE" SHOPIFY_ADMIN_TOKEN="$SHOPIFY_ADMIN_TOKEN" \
+  "$NODE_BIN" scripts/push_shopify.js --dry-run 2>&1 | grep -c "would create" || true)
+print "dry-run would-create: $DRY"
+
+# 4) Verdict
+if [[ "$COUNT" == "0" && "$DRY" == "73" && -f "$PLIST" ]]; then
+  ok "GREEN: push is armed for next Wednesday 02:00 PT"
+  exit 0
+elif [[ "$COUNT" -ge 73 ]]; then
+  ok "DONE: $COUNT/73 already in Shopify — plist should self-unload on next run"
+  exit 0
+else
+  warn "MIXED: count=$COUNT  dry=$DRY  plist=$([[ -f "$PLIST" ]] && echo present || echo absent)"
+  exit 1
+fi

← 52bd57d Shopify: bump to API 2026-01  ·  back to Sister Parish Onboarding  ·  fix: bump SP metafield namespace dw→dwc (Shopify requires ≥3 b6c1a27 →