#!/usr/bin/env bash # validate-submission.sh — OpenEnv submission validator # Usage: ./scripts/validate-submission.sh [repo_dir] set -euo pipefail PING_URL="${1:-}" REPO_DIR="${2:-.}" DOCKER_BUILD_TIMEOUT="${DOCKER_BUILD_TIMEOUT:-600}" if [[ -z "$PING_URL" ]]; then echo "Usage: $0 [repo_dir]" echo "Example: $0 https://my-space.hf.space ." exit 2 fi if [[ ! -d "$REPO_DIR" ]]; then echo "ERROR: repo_dir not found: $REPO_DIR" exit 2 fi cd "$REPO_DIR" echo "==> 1/4 Ping Space root" ROOT_CODE=$(curl -s -o /tmp/openenv_root.json -w '%{http_code}' "$PING_URL/") if [[ "$ROOT_CODE" != "200" ]]; then echo "FAIL: root ping returned $ROOT_CODE" exit 1 fi echo "==> 2/4 Ping reset endpoint" RESET_CODE=$(curl -s -o /tmp/openenv_reset.json -w '%{http_code}' "$PING_URL/reset") if [[ "$RESET_CODE" != "200" ]]; then echo "FAIL: reset ping returned $RESET_CODE" exit 1 fi if ! grep -q '"observation"' /tmp/openenv_reset.json; then echo "FAIL: /reset did not return observation" exit 1 fi echo "==> 3/4 openenv validate" openenv validate echo "==> 4/4 docker build" if ! command -v docker >/dev/null 2>&1; then echo "FAIL: docker command not found" exit 1 fi if command -v timeout >/dev/null 2>&1; then if ! timeout "$DOCKER_BUILD_TIMEOUT" docker build -t code-review-env-validate .; then echo "FAIL: docker build failed or timed out" exit 1 fi else echo "WARN: timeout command not found, running docker build without timeout" if ! docker build -t code-review-env-validate .; then echo "FAIL: docker build failed" exit 1 fi fi echo "PASS: submission validator checks completed"