#!/usr/bin/env bash
# Differential check: the Rust FIFA 17 Blaze adapter vs the Python responder.
#
#   1. assert the committed fixtures still match what the Python oracle emits
#   2. replay every recorded transaction through the Rust adapter, byte-for-byte
#
# Read-only with respect to the running backend: the oracle is imported as a
# library, no responder is started, no port is bound, no live service is
# touched. Safe to run while the Python backend is serving a live FIFA client.
#
# Use --regen to rewrite the fixtures after an intentional oracle change.
set -euo pipefail

cd "$(dirname "$(readlink -f "$0")")"

if [[ "${1:-}" == "--regen" ]]; then
  echo "==> regenerating fixtures from the Python oracle"
  python3 fixtures/generate.py
else
  echo "==> checking committed fixtures against the Python oracle"
  python3 fixtures/generate.py --check
fi

echo "==> replaying transactions through the Rust adapter"
cargo test -p openfut-adapter-fifa17

echo
echo "PARITY OK — the adapter reproduces the Python dispatcher byte-for-byte."
