← back to Dw Activation Calendar

scripts/check-reintro-guard.sh

65 lines

#!/usr/bin/env bash
# Drift-guard for the "do not reintroduce old patterns as new" rule (Steve 2026-08-11, TK-10474 DTD verdict C).
# Fails LOUD (exit 1) if:
#   (a) the two rotation-order.js copies diverge, or
#   (b) any daily-activation entrypoint has lost its re-introduction guard.
# Cheap, read-only, no deps. Wire into a launchd/cron later (Steve-gated) or run before any activation change.
set -u

CAL="$HOME/Projects/dw-activation-calendar/lib/rotation-order.js"          # canonical (live calendar path)
ACT="$HOME/Projects/dw-rotation-activator/lib/rotation-order.js"           # activator copy (now a symlink → CAL)
GATED="$HOME/Projects/Designer-Wallcoverings/shopify/scripts/cadence/activate-gated.js"

fail=0
say(){ printf '%s\n' "$*"; }

# (a) the two rotation-order.js copies must be byte-identical (symlink resolves transparently)
if [ ! -f "$CAL" ]; then say "❌ MISSING canonical rotation-order.js: $CAL"; fail=1
elif [ ! -e "$ACT" ]; then say "❌ MISSING activator rotation-order.js (symlink dangling?): $ACT"; fail=1
elif ! diff -q "$CAL" "$ACT" >/dev/null 2>&1; then
  say "❌ DRIFT: rotation-order.js copies diverged — calendar vs activator:"; diff "$CAL" "$ACT" | head -20; fail=1
else
  say "✅ rotation-order.js: both copies identical"
fi

# (b) rotation-order.js must still embed the title-based re-intro guard (SQL NOT EXISTS on prior title)
if grep -q "a.title = sp.title" "$CAL" && grep -qE "status IN \('ACTIVE','ARCHIVED'" "$CAL"; then
  say "✅ rotation-order.js: re-intro guard present (SQL)"
else
  say "❌ rotation-order.js: re-introduction guard MISSING — an old pattern could be re-surfaced as new"; fail=1
fi

# (b) activate-gated.js (armed Pierre Frey + activation-schedule promoter) must carry the JS re-intro guard
if grep -q "shopify_products WHERE title=" "$GATED" && grep -qE "status IN \('ACTIVE','ARCHIVED'" "$GATED"; then
  say "✅ activate-gated.js: re-intro guard present (JS promote loop)"
else
  say "❌ activate-gated.js: re-introduction guard MISSING — the daily promoter could re-activate a retired pattern"; fail=1
fi

# (b2) mfr_sku near-dupe guard + pre-2025 age gate must stay present (Steve 2026-08-12, TK-10480)
if grep -q "upper(trim(a.mfr_sku)) = upper(trim(sp.mfr_sku))" "$CAL" && grep -q "created_at_shopify, '1970-01-01'" "$CAL"; then
  say "✅ rotation-order.js: mfr_sku near-dupe guard + pre-2025 age gate present"
else
  say "❌ rotation-order.js: mfr_sku near-dupe guard or age gate MISSING — old/dupe patterns could re-surface as new"; fail=1
fi
if grep -q "upper(trim(a.mfr_sku))=upper(trim(d.mfr_sku))" "$GATED" && grep -q "d.created_at_shopify < '2025-01-01'" "$GATED"; then
  say "✅ activate-gated.js: mfr_sku near-dupe guard + pre-2025 age gate present"
else
  say "❌ activate-gated.js: mfr_sku near-dupe guard or age gate MISSING — old/dupe patterns could re-surface as new"; fail=1
fi

# (c) NEVER-ACTIVATE vendors must stay excluded (Steve "no old dwjs, phillip jeffries", 2026-08-11)
# Grep the ASSIGNMENT line only (not comments) so a stripped value can't false-pass on a leftover comment.
for v in "jeffrey stevens" "phillip jeffries"; do
  if grep -E 'NEVER_ACTIVATE_VENDORS[[:space:]]*=' "$CAL" | grep -qi "$v"; then say "✅ rotation-order.js: never-activate vendor kept excluded — $v"
  else say "❌ rotation-order.js: NEVER_ACTIVATE_VENDORS lost '$v' — old $v patterns could re-surface"; fail=1; fi
done
if grep -E 'NEVER_ACTIVATE[[:space:]]*=' "$GATED" | grep -qiE "phillip jeffries|jeffrey stevens"; then say "✅ activate-gated.js: never-activate vendors kept excluded (dwjs/PJ)"
else say "❌ activate-gated.js: NEVER_ACTIVATE lost the dwjs/phillip-jeffries exclusion"; fail=1; fi

if [ "$fail" -ne 0 ]; then
  say ""; say "🚨 RE-INTRO GUARD DRIFT DETECTED — do not run activation until fixed. (Steve rule: no reintroducing old patterns as new; no old dwjs/phillip jeffries.)"
  exit 1
fi
say ""; say "✅ All daily-activation paths carry the re-introduction guard, copies are in sync, and dwjs/phillip-jeffries stay excluded."