#!/usr/bin/env bash # # validate-submission.sh — OpenEnv Submission Validator (Hardened) # # Checks that your HF Space is live, Docker image builds, and OpenEnv spec compliance. # Mandatory Log Format Check included. set -e PING_URL=$1 REPO_DIR=${2:-"."} if [ -z "$PING_URL" ]; then echo "Usage: $0 [repo_dir]" echo "Example: bash scripts/validate-submission.sh https://huggingface.co/spaces/user/rust-coder" exit 1 fi echo "--- 🔍 1. Testing Connection to HF Space ---" # Check health or root RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "$PING_URL/health" || curl -s -o /dev/null -w "%{http_code}" "$PING_URL/") if [ "$RESPONSE" -ne 200 ]; then echo "❌ FAILED: Space at $PING_URL returned $RESPONSE (expected 200)" echo " Ensure your Space is 'Running' and public." exit 1 fi echo "✅ PASSED: Connection OK" echo "--- 🔍 2. Validating OpenEnv Spec ---" cd "$REPO_DIR" if command -v openenv &>/dev/null; then if ! openenv validate; then echo "❌ FAILED: openenv validate failed. Check your openenv.yaml syntax." exit 1 fi echo "✅ PASSED: openenv.yaml is valid" else echo "⚠️ WARNING: 'openenv' command not found. Skipping local spec validation." echo " (Ensure you've run 'pip install openenv-core' if you want this check)" fi echo "--- 🔍 3. Checking Mandatory Logging Format ---" # The judge requires [START], [STEP], and [END] in stdout if grep -q "\[START\]" "inference.py" && grep -q "\[STEP\]" "inference.py" && grep -q "\[END\]" "inference.py"; then echo "✅ PASSED: inference.py contains mandatory [START/STEP/END] logs." else echo "❌ FAILED: inference.py is missing mandatory structured logging." echo " See documentation for [START], [STEP], and [END] format." exit 1 fi echo "--- 🔍 4. Verifying File Structure ---" FILES=("inference.py" "problems.json" "server/Dockerfile" "openenv.yaml") for f in "${FILES[@]}"; do if [ ! -f "$f" ]; then echo "❌ FAILED: Missing required file: $f" exit 1 fi done echo "✅ PASSED: All core files exist." echo "--- 🔍 5. Checking Task Count ---" TASK_COUNT=$(grep -c "id:" "openenv.yaml" || true) if [ "$TASK_COUNT" -lt 3 ]; then echo "❌ FAILED: Found only $TASK_COUNT tasks in openenv.yaml (minimum 3 required)." exit 1 fi echo "✅ PASSED: Found $TASK_COUNT tasks." echo "" echo "🎉 SUCCESS: Your submission has passed all local checks!" echo "You are ready to submit your Space URL: $PING_URL"