#!/usr/bin/env bash
# Recompute this yourself: replay a published-results document's recompute
# appendix against the project its numbers were judged on.
#
# Every call in the appendix is repeated. The protocol must re-read with the
# cited fingerprint, every POST must name the cited report (report ids are
# derived from the request's content), every cited report must re-hash to the
# cited fingerprint byte for byte, every published number must be found in its
# report with exactly the published value, and the verdict must be the cited
# evaluation's, verbatim. Anything else is printed as NOT REPRODUCED with the
# JSON pointer of what failed, and the command exits 1.
set -euo pipefail

: "${TESSERA_API_BASE:?e.g. https://api.staging.tessera.zone/v1}"
: "${TESSERA_API_KEY:?the tsk_ key of the project the numbers were judged on}"
: "${TESSERA_PUBLISHED_RESULTS:?the published_results.json to check}"
: "${TESSERA_REPO_ROOT:?a checkout of the Tessera repository (for the schemas)}"

tessera-doctest recompute \
  --document "$TESSERA_PUBLISHED_RESULTS" \
  --repo-root "$TESSERA_REPO_ROOT"
