Skip to content

Commit 076900a

Browse files
helper script to make running test shards locally easy
1 parent 8a9f8f9 commit 076900a

1 file changed

Lines changed: 105 additions & 0 deletions

File tree

scripts/run-integration-v4.sh

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Run one cell of the v4 integration-test matrix, mirroring the
4+
# `integration-tests-v4-sm` job in .github/workflows/pull_request.yml.
5+
#
6+
# Required (shell env or .env at repo root):
7+
# CONDUCTOR_SERVER_URL, CONDUCTOR_AUTH_KEY, CONDUCTOR_AUTH_SECRET
8+
#
9+
# Usage:
10+
# scripts/run-integration-v4.sh [-n|--node 20|22|24] [-s|--shard 1|2|3]
11+
# [-t|--test <path|pattern>] [-c|--coverage] [-- jest args]
12+
# Examples:
13+
# scripts/run-integration-v4.sh # node 24, shard 1/3
14+
# scripts/run-integration-v4.sh --node 22 --shard 2 # node 22, shard 2/3
15+
# scripts/run-integration-v4.sh --coverage # include the coverage report (off by default)
16+
# # Run a single test file (--test disables sharding so the file isn't filtered out):
17+
# scripts/run-integration-v4.sh --test src/integration-tests/WorkflowExecutor.test.ts
18+
# scripts/run-integration-v4.sh --node 20 --test WorkflowExecutor
19+
# scripts/run-integration-v4.sh -- --testPathPatterns="WorkflowExecutor"
20+
set -euo pipefail
21+
22+
NODE_VERSION=24
23+
SHARD=1
24+
TOTAL_SHARDS=3
25+
TEST_PATTERN=""
26+
COVERAGE=0
27+
28+
# Print the leading comment block (everything after the shebang up to the first
29+
# non-comment line) as help text, so it stays in sync with the header above.
30+
usage() { awk 'NR>1 && /^#/ {sub(/^# ?/, ""); print; next} NR>1 {exit}' "$0"; }
31+
32+
extra=()
33+
while [[ $# -gt 0 ]]; do
34+
case "$1" in
35+
-n|--node) NODE_VERSION="${2:?--node needs a value}"; shift 2 ;;
36+
-s|--shard) SHARD="${2:?--shard needs a value}"; shift 2 ;;
37+
-t|--test) TEST_PATTERN="${2:?--test needs a path or pattern}"; shift 2 ;;
38+
-c|--coverage) COVERAGE=1; shift ;;
39+
-h|--help) usage; exit 0 ;;
40+
--) shift; extra=("$@"); break ;;
41+
*) echo "Unknown argument: $1" >&2; usage; exit 1 ;;
42+
esac
43+
done
44+
45+
case "$NODE_VERSION" in 20|22|24) ;; *) echo "Error: --node must be 20, 22, or 24 (got '$NODE_VERSION')" >&2; exit 1 ;; esac
46+
case "$SHARD" in 1|2|3) ;; *) echo "Error: --shard must be 1, 2, or 3 (got '$SHARD')" >&2; exit 1 ;; esac
47+
48+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
49+
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
50+
cd "${REPO_ROOT}"
51+
52+
if [[ -f .env ]]; then
53+
set -a
54+
# shellcheck disable=SC1091
55+
source .env
56+
set +a
57+
fi
58+
59+
missing=()
60+
for var in CONDUCTOR_SERVER_URL CONDUCTOR_AUTH_KEY CONDUCTOR_AUTH_SECRET; do
61+
if [[ -z "${!var:-}" ]]; then
62+
missing+=("$var")
63+
fi
64+
done
65+
if (( ${#missing[@]} > 0 )); then
66+
echo "Error: missing required environment variable(s): ${missing[*]}" >&2
67+
echo "Set them in your shell or in a .env file at the repo root (see .env.example)." >&2
68+
exit 1
69+
fi
70+
71+
export ORKES_BACKEND_VERSION=4
72+
export CONDUCTOR_REQUEST_TIMEOUT_MS="${CONDUCTOR_REQUEST_TIMEOUT_MS:-120000}"
73+
export CONDUCTOR_RETRY_SERVER_ERRORS="${CONDUCTOR_RETRY_SERVER_ERRORS:-true}"
74+
75+
test_cmd=(npm run test:integration:v4 -- --ci --runInBand --testTimeout=120000)
76+
if [[ "${COVERAGE}" == "1" ]]; then
77+
test_cmd+=(--coverage)
78+
fi
79+
if [[ -n "${TEST_PATTERN}" ]]; then
80+
# Targeting a specific test: don't shard, or the file may be filtered out.
81+
test_cmd+=("--testPathPatterns=${TEST_PATTERN}")
82+
else
83+
test_cmd+=("--shard=${SHARD}/${TOTAL_SHARDS}")
84+
fi
85+
if (( ${#extra[@]} > 0 )); then
86+
test_cmd+=("${extra[@]}")
87+
fi
88+
89+
if [[ -n "${TEST_PATTERN}" ]]; then
90+
echo "Running v4 integration tests | node ${NODE_VERSION} | test '${TEST_PATTERN}' | server ${CONDUCTOR_SERVER_URL}"
91+
else
92+
echo "Running v4 integration tests | node ${NODE_VERSION} | shard ${SHARD}/${TOTAL_SHARDS} | server ${CONDUCTOR_SERVER_URL}"
93+
fi
94+
95+
if command -v fnm >/dev/null 2>&1; then
96+
fnm exec --using="${NODE_VERSION}" -- "${test_cmd[@]}"
97+
else
98+
current_major="$(node -v 2>/dev/null | sed -E 's/^v([0-9]+).*/\1/')"
99+
if [[ "${current_major}" != "${NODE_VERSION}" ]]; then
100+
echo "Error: requested Node ${NODE_VERSION} but current Node is v${current_major:-unknown} and fnm is not installed." >&2
101+
echo "Install fnm (see SDK_DEVELOPMENT.md) or switch your Node version manually before running." >&2
102+
exit 1
103+
fi
104+
"${test_cmd[@]}"
105+
fi

0 commit comments

Comments
 (0)