#!/bin/bash
# Exit 0 when the census snapshot is intact and pagination cursors stay redacted.
set -euo pipefail
cd "$(dirname "$0")"

required=(
  all-blocks.json
  allposts.json
  posts_db.json
  harvest.json
  chain-walk.json
  followed-accounts.json
  full-chain-follows-report.json
  consensus-follows-report.json
  community-history.md
  stackchain-market-cap.json
  stackchain-market-cap-blocks.csv
  tip-state.json
  timmy-supplement-2026-11-09.json
  README.md
)

missing=0
for f in "${required[@]}"; do
  if [[ ! -f "$f" ]]; then
    echo "MISSING $f" >&2
    missing=1
  fi
done
[[ $missing -eq 0 ]]

python3 - << 'PY'
import json, re, sys
from pathlib import Path
here = Path(".")
cursor = re.compile(r"b26v89c19zqg")
for p in here.glob("*.json"):
    text = p.read_text()
    if cursor.search(text):
        print(f"CURSOR_LEAK {p.name}", file=sys.stderr)
        sys.exit(1)
    json.loads(text)
fa = json.loads((here / "followed-accounts.json").read_text())
n = len(fa["accounts"])
if n != 609:
    print(f"FOLLOW_COUNT {n} != 609", file=sys.stderr)
    sys.exit(1)
mcap = json.loads((here / "stackchain-market-cap.json").read_text())
if "totals" not in mcap or "methodology" not in mcap:
    print("MCAP_SHAPE", file=sys.stderr)
    sys.exit(1)
print("ok files=json-parsed follows=609 cursors=redacted")
PY
