#!/usr/bin/env bash
set -e

cd "$(dirname "$0")"

# Reset working tree to match remote exactly
git reset --hard --quiet >&2 || true
git clean -fdx --quiet  >&2 || true

if [ -f /usr/local/Ascend/ascend-toolkit/set_env.sh ]; then
    source /usr/local/Ascend/ascend-toolkit/set_env.sh >&2 || true
fi

SUBMISSION=/coursegrader/submit/flash_attention_forward.py

if [ ! -f "$SUBMISSION" ]; then
    echo '{"verdict": "submission not found", "score": 0, "comment": "Submission file not found at /coursegrader/submit/flash_attention_forward.py. The filename is fixed — please name your submission exactly: flash_attention_forward.py"}'
    exit 1
fi

# Run the judge on the user's submission
exec python3 competition/primary/judge.py "$SUBMISSION"