# Validate a react-perf-auditor Markdown report has real evidence, not vibes.
# 1. The report must contain an actual before/after numeric comparison —
# a number with a unit (ms, KB, MB, fps, s) appearing near "before"/
# "after" language (case-insensitive). FAIL if only vague qualitative
# claims are found (no such pattern anywhere in the report).
# 2. If the report references a CI perf budget config file by path
# (budget.json, .bundlesizerc, lighthouserc, lighthouserc.json, etc.),
# verify that file actually exists on disk relative to the repo root.
# FAIL if referenced but missing.
# Usage: check_perf_report.sh REPORT.md [REPO_ROOT]
# REPO_ROOT defaults to "."
if [[ -z "$REPORT" || ! -f "$REPORT" ]]; then
echo "Usage: $0 REPORT.md [REPO_ROOT]" >&2
echo "error: report file not found: '${REPORT:-<missing arg>}'" >&2
warn() { printf '⚠️ %s\n' "$1"; }
error() { printf '❌ %s\n' "$1"; fail=1; }
ok() { printf '✅ %s\n' "$1"; }
echo "== check: before/after numeric comparison =="
# Numbers with a perf unit (ms, KB, MB, fps, s) anywhere in the doc.
metric_lines=$(grep -nEi '[0-9](\.[0-9]+)?[[:space:]]*(ms|kb|mb|fps|s)\b' "$REPORT" || true)
# Before/after language anywhere in the doc.
before_after_lines=$(grep -niE '\b(before|after)\b' "$REPORT" || true)
if [[ -n "$metric_lines" && -n "$before_after_lines" ]]; then
ok "found numeric metrics with units and before/after language"
error "no before/after numeric comparison found — report must show measured numbers (ms/KB/MB/fps/s) tied to before/after, not just qualitative claims"
echo "== check: referenced CI perf budget config files exist =="
budget_refs=$(grep -oE '[[:alnum:]_./-]*(budget\.json|\.bundlesizerc|lighthouserc(\.json|\.js|\.yml)?)' "$REPORT" 2>/dev/null | sort -u || true)
if [[ -n "$budget_refs" ]]; then
while IFS= read -r ref; do
[[ -z "$ref" ]] && continue
if [[ -f "$REPO_ROOT/$ref" || -f "$ref" ]]; then
ok "referenced budget file exists: $ref"
error "report references '$ref' but it does not exist under repo root '$REPO_ROOT'"
ok "no CI perf budget config file referenced by path — skipping"
if [[ "$fail" -eq 0 ]]; then
echo "All checks passed."
echo "One or more checks failed — see ❌ lines above."