#!/usr/bin/env bash
# Design-partner runbook, steps 3 to 5 in one command: the packaged driver
# (tessera-milestone-partner) judges the model against the registered protocol,
# runs the lead-time backtest when the protocol declares lead-time metrics,
# archives the protocol and the reports by fingerprint and writes the
# published-results document. Set TESSERA_MODEL_ID and TESSERA_REPO_ROOT (a
# checkout of the Tessera repository).
#
# There is no flag for a threshold, a margin or a provenance class: thresholds
# come from the registered protocol, and a run against our hosted deployment
# reports at most the design-partner class.
set -euo pipefail

: "${TESSERA_API_BASE:?e.g. https://api.staging.tessera.zone/v1}"
: "${TESSERA_API_KEY:?the tsk_ key of the partner project}"
: "${TESSERA_MODEL_ID:?the trained model, mdl_...}"
: "${TESSERA_REPO_ROOT:?a checkout of the Tessera repository}"
: "${TESSERA_STATE_DIR:?set by the runner; ids are handed between steps}"
PROTOCOL_ID="$(cat "$TESSERA_STATE_DIR/protocol_id")"
REPORT_DIR="${TESSERA_PARTNER_REPORT_DIR:-$TESSERA_STATE_DIR/partner}"

uv run --project "$TESSERA_REPO_ROOT/tools/milestones" tessera-milestone-partner run \
  --target staging \
  --protocol-id "$PROTOCOL_ID" \
  --model-id "$TESSERA_MODEL_ID" \
  --report-dir "$REPORT_DIR"
