#!/bin/bash
set -e

echo "=========================================="
echo "  Luminal Python: Full Test Suite"
echo "=========================================="

NATIVE_TESTS="tests/test_hlir_ops.py tests/test_unary.py"
CUDA_TESTS="tests/test_hlir_ops.py tests/test_unary.py tests/test_llama3.py"

# ── Phase 1: Native Backend ─────────────────────────────────

echo ""
echo "=== Phase 1: Building native backend ==="
rm -rf rust/target/wheels rust/target/debug rust/target/release
uv run maturin develop --manifest-path rust/Cargo.toml

echo ""
echo "--- 1a: Native backend tests ---"
uv run pytest $NATIVE_TESTS -v

# ── Phase 2: CUDA Backend ───────────────────────────────────

echo ""
echo "=== Phase 2: Building CUDA backend ==="
rm -rf rust/target/wheels rust/target/debug rust/target/release
uv run maturin develop --manifest-path rust/Cargo.toml --features cuda -r

echo ""
echo "--- 2a: CUDA ---"
RUST_BACKTRACE=1 LUMINAL_TEST_DEVICE=cuda uv run pytest $CUDA_TESTS -m "not slow" -v

echo ""
echo "=========================================="
echo "  All tests passed!"
echo "=========================================="
