#!/usr/bin/env bash
# validate.sh — heavyweight correctness gate
# Run this AFTER measure.sh score is high. Stage 5 / Stage 6 from VALIDATION_PLAYBOOK_v2.md.
# This is NOT in the inner iteration loop — it takes hours, not seconds.

set -euo pipefail

cat <<'EOF'
This is the heavyweight validation gate (Stage 5 + Stage 6 phase 6A).
Don't run it in the iteration loop — it's hours, not seconds.

Pre-requisites:
  - measure.sh score is at least 90/115.
  - Both binaries built (patient + reference).
  - 4-validator private testnet recipe in VALIDATION_PLAYBOOK_v2.md §5.1-§5.3.
  - debug_minePinned RPC added to both binaries (see playbook §5.4).
  - Apothem snapshot tarball available for Stage 6 phase 6A.

To execute:
  1. Spin up the 4-validator private testnet on a single host.
  2. Drive past V2.SwitchBlock (block 4500 with the suggested test config).
  3. Run the deterministic mining harness (PASS=5/5 over 5 V2 rounds).
  4. Run multi-round mining for ≥1 epoch with mixed proposers.
  5. Run Apothem read-only canary for ≥24 hours (Stage 6A).

Pass criteria are documented in VALIDATION_PLAYBOOK_v2.md §5.5, §5.7, §6.1.1.

This script doesn't run those for you — they need a real test environment.
What it CAN do quickly is report which acceptance gates have been passed
based on log evidence. Drop your test outputs into:

  log/validation/<date>/
    stage5_harness_results.json
    stage5_multi_round.log
    stage6a_24h_canary.log

Then re-run validate.sh to aggregate a verdict.

EOF

# Aggregate any validation logs that have been dropped in
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VAL_DIR="$HERE/log/validation"
if [[ ! -d "$VAL_DIR" ]]; then
  echo "No validation logs yet. Run the playbook stages and drop outputs in $VAL_DIR."
  exit 0
fi

# TODO: parse stage5/6 results and emit a unified verdict.
echo "Validation log dir found: $VAL_DIR"
ls -la "$VAL_DIR"
