#!/bin/bash

set -e

# defaults if not set
: "${SKIP_LINT:=0}"
: "${COV_REPORT:=term}"
: "${COV_PORT:=8000}"

# convert to all lowercase
COV_REPORT=$(echo $COV_REPORT | tr '[:upper:]' '[:lower:]')

# set flags for pytest-cov
COVERAGE_ARGS=""
if [ "$COV_REPORT" != "off" ]; then
    COVERAGE_ARGS="--cov-report $COV_REPORT --cov=src"
fi

# run pytest with args set
echo 'Running tests...'
uv run pytest $TEST_ARGS tests/integration/ $COVERAGE_ARGS

# serve out html coverage report
if [ "$COV_REPORT" = "html" ]; then
    echo "Serving out coverage report on port $COV_PORT..."
    uv run python -m http.server --directory htmlcov $COV_PORT
fi

echo 'Done!'
