#!/bin/bash
# Run CLI integration tests only
#
# Usage:
#   ./scripts/test_cli.sh [options] [filter]
#
# Options:
#   -b, --binary PATH    Test specific binary instead of cargo build
#
# Examples:
#   ./scripts/test_cli.sh                              # All tests
#   ./scripts/test_cli.sh selector                     # Only selector tests
#   ./scripts/test_cli.sh -b ./target/release/wasot    # Test release binary
#   ./scripts/test_cli.sh -b ./target/release/wasot selector  # Both

set -e

# Parse arguments
while [[ $# -gt 0 ]]; do
    case $1 in
        -b|--binary)
            export WASOT_TEST_BINARY="$2"
            shift 2
            ;;
        --binary=*)
            export WASOT_TEST_BINARY="${1#*=}"
            shift
            ;;
        *)
            FILTER="$1"
            shift
            ;;
    esac
done

echo "🧪 Running CLI integration tests..."
if [ -n "$WASOT_TEST_BINARY" ]; then
    echo "   Binary: $WASOT_TEST_BINARY"
fi

if [ -n "$FILTER" ]; then
    echo "   Filter: $FILTER"
    cargo test --test cli_tests "$FILTER" -- --nocapture
else
    cargo test --test cli_tests
fi

echo "✅ CLI tests completed!"
