| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
set -e |
| 4 |
|
| 5 |
cd "$(dirname "$0")/.." |
| 6 |
|
| 7 |
RED='\033[0;31m' |
| 8 |
GREEN='\033[0;32m' |
| 9 |
YELLOW='\033[0;33m' |
| 10 |
NC='\033[0m' # No Color |
| 11 |
|
| 12 |
function steady_is_running() { |
| 13 |
curl --silent "http://127.0.0.1:4010/_x-steady/health" >/dev/null 2>&1 |
| 14 |
} |
| 15 |
|
| 16 |
kill_server_on_port() { |
| 17 |
pids=$(lsof -t -i tcp:"$1" -sTCP:LISTEN || echo "") |
| 18 |
for pid in $pids; do |
| 19 |
kill "$pid" |
| 20 |
echo "Stopped process $pid on port $1." |
| 21 |
done |
| 22 |
} |
| 23 |
|
| 24 |
function is_overriding_api_base_url() { |
| 25 |
[ -n "$TEST_API_BASE_URL" ] |
| 26 |
} |
| 27 |
|
| 28 |
if ! is_overriding_api_base_url && ! steady_is_running ; then |
| 29 |
# When we exit this script, make sure to kill the background mock server process |
| 30 |
trap 'kill_server_on_port 4010' EXIT |
| 31 |
|
| 32 |
# Start the dev server |
| 33 |
./scripts/mock --daemon |
| 34 |
fi |
| 35 |
|
| 36 |
if is_overriding_api_base_url ; then |
| 37 |
echo -e "${GREEN}✔ Running tests against ${TEST_API_BASE_URL}${NC}" |
| 38 |
echo |
| 39 |
elif ! steady_is_running ; then |
| 40 |
echo -e "${RED}ERROR:${NC} The test suite will not run without a mock Steady server" |
| 41 |
echo -e "running against your OpenAPI spec." |
| 42 |
echo |
| 43 |
echo -e "To run the server, pass in the path or url of your OpenAPI" |
| 44 |
echo -e "spec to the steady command:" |
| 45 |
echo |
| 46 |
echo -e " \$ ${YELLOW}npm exec --package=@stdy/[email protected] -- steady path/to/your.openapi.yml --host 127.0.0.1 -p 4010 --validator-query-array-format=brackets --validator-form-array-format=brackets --validator-query-object-format=brackets --validator-form-object-format=brackets${NC}" |
| 47 |
echo |
| 48 |
|
| 49 |
exit 1 |
| 50 |
else |
| 51 |
echo -e "${GREEN}✔ Mock steady server is running with your OpenAPI spec${NC}" |
| 52 |
echo |
| 53 |
fi |
| 54 |
|
| 55 |
export DEFER_PYDANTIC_BUILD=false |
| 56 |
|
| 57 |
# Note that we need to specify the patch version here so that uv |
| 58 |
# won't use unstable (alpha, beta, rc) releases for the tests |
| 59 |
PY_VERSION_MIN=">=3.10.0" |
| 60 |
PY_VERSION_MAX=">=3.14.0" |
| 61 |
|
| 62 |
function run_tests() { |
| 63 |
echo "==> Running tests with Pydantic v2" |
| 64 |
uv run --isolated --all-extras pytest "$@" |
| 65 |
|
| 66 |
# Skip Pydantic v1 tests on latest Python (not supported) |
| 67 |
if [[ "$UV_PYTHON" != "$PY_VERSION_MAX" ]]; then |
| 68 |
echo "==> Running tests with Pydantic v1" |
| 69 |
uv run --isolated --all-extras --no-extra=mcp --group=pydantic-v1 pytest "$@" |
| 70 |
fi |
| 71 |
|
| 72 |
# The lockfile pins one mcp major; also run the mcp tests against the other one |
| 73 |
# (mcp requires Python 3.10+, so skip on the minimum version) |
| 74 |
if [[ "$UV_PYTHON" != "$PY_VERSION_MIN" ]]; then |
| 75 |
echo "==> Running MCP tests with mcp v2" |
| 76 |
uv run --isolated --all-extras --with 'mcp>=2' pytest tests/lib/tools/test_mcp_tool.py |
| 77 |
fi |
| 78 |
} |
| 79 |
|
| 80 |
# If UV_PYTHON is already set in the environment, just run the command once |
| 81 |
if [[ -n "$UV_PYTHON" ]]; then |
| 82 |
run_tests "$@" |
| 83 |
else |
| 84 |
# If UV_PYTHON is not set, run the command for min and max versions |
| 85 |
|
| 86 |
echo "==> Running tests for Python $PY_VERSION_MIN" |
| 87 |
UV_PYTHON="$PY_VERSION_MIN" run_tests "$@" |
| 88 |
|
| 89 |
echo "==> Running tests for Python $PY_VERSION_MAX" |
| 90 |
UV_PYTHON="$PY_VERSION_MAX" run_tests "$@" |
| 91 |
fi |