#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
OUTPUT_DIR="${CV_BENCHMARK_OUTPUT_DIR:-$ROOT_DIR/tmp/cv-benchmarks/latest}"
APPROVED_DIR="${CV_BENCHMARK_APPROVED_DIR:-$ROOT_DIR/tmp/cv-benchmarks/approved-fixtures}"

mkdir -p "$OUTPUT_DIR" "$APPROVED_DIR"

echo "CV benchmark output: $OUTPUT_DIR"
echo "Approved fixtures: $APPROVED_DIR"

CV_BENCHMARK_OUTPUT_DIR="$OUTPUT_DIR" \
CV_BENCHMARK_APPROVED_DIR="$APPROVED_DIR" \
  dotnet test "$ROOT_DIR/JobTrackerApi.Tests/JobTrackerApi.Tests.csproj" --filter CvCorpusHarnessTests

if [[ -f "$OUTPUT_DIR/report.md" ]]; then
  echo
  echo "Benchmark report written to: $OUTPUT_DIR/report.md"
fi
if [[ -f "$OUTPUT_DIR/index.json" ]]; then
  echo "Benchmark index written to: $OUTPUT_DIR/index.json"
fi
