File size: 2,515 Bytes
9763ffa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/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 <ping_url> [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"