Skip to content

Commit 8692af2

Browse files
committed
separate: setup from call
1 parent f610d13 commit 8692af2

5 files changed

Lines changed: 138 additions & 65 deletions

File tree

scenarios/run.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -132,24 +132,6 @@ def devnet_info():
132132
return json.load(f)
133133

134134

135-
def ensure_foundry():
136-
"""Install Foundry if cast is not on PATH."""
137-
if (
138-
subprocess.call(
139-
"command -v cast",
140-
shell=True,
141-
stdout=subprocess.DEVNULL,
142-
stderr=subprocess.DEVNULL,
143-
)
144-
!= 0
145-
):
146-
info("Installing Foundry...")
147-
os.system("curl -sSL https://foundry.paradigm.xyz | bash")
148-
os.environ["PATH"] = os.path.expanduser("~/.foundry/bin:") + os.environ["PATH"]
149-
os.system(os.path.expanduser("~/.foundry/bin/foundryup"))
150-
assert_ok("command -v cast", "cast is installed")
151-
152-
153135
# ── Version info ──────────────────────────────────────────────
154136

155137

scenarios/test_basic_balances.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
def run():
15-
ensure_foundry()
15+
assert_ok("command -v cast", "cast is installed")
1616
d = devnet_info()["info"]
1717
lotus_rpc = d["lotus"]["host_rpc_url"]
1818
usdfc_addr = d["contracts"]["mockusdfc_addr"]

scenarios/test_caching_subsystem.py

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
SYNAPSE_SDK_REPO = "https://github.com/FilOzone/synapse-sdk/"
2828
CASSANDRA_VERSION = "5.0.6"
2929
PYTHON_VERSION = "3.10" # max supported python version for CASSANDRA_VERSION
30-
CASSANDRA_URL = f"https://dlcdn.apache.org/cassandra/{CASSANDRA_VERSION}/apache-cassandra-{CASSANDRA_VERSION}-bin.tar.gz"
3130
CASSANDRA_DIR = Path.home() / ".foc-devnet" / "artifacts" / "cassandra"
3231
CASSANDRA_HOME = CASSANDRA_DIR / f"apache-cassandra-{CASSANDRA_VERSION}"
3332
SMALL_FILE_SIZE = 20 * 1024 * 1024 # 20MB — below 32MB threshold
@@ -78,63 +77,40 @@ def _write_random_file(path: Path, size: int, seed: int) -> None:
7877
remaining -= chunk
7978

8079

81-
def _ensure_custom_python():
82-
"""Ensure python is available on the system, installing it via apt if needed.
83-
This is because cassandra 5.0.6 requires Python 3.6-3.11
80+
def _find_custom_python():
81+
"""Locate portable Python installed by scripts/setup-scenarios-prerequisites.sh.
8482
85-
Returns the path to the python3.11 interpreter.
83+
Returns the path to the python interpreter.
84+
Raises RuntimeError if not found.
8685
"""
87-
from pathlib import Path
88-
8986
npm_root = sh("npm root -g").strip()
9087
pkg_dir = Path(npm_root) / "@bjia56" / f"portable-python-{PYTHON_VERSION}"
91-
py = ""
92-
if pkg_dir.exists():
93-
# look for any python binary under the package (handles headless builds)
94-
for p in pkg_dir.rglob("bin/python*"):
95-
py = str(p)
96-
break
97-
98-
if not py or py == "":
99-
info(f"Installing custom python version {PYTHON_VERSION}")
100-
info(sh(f"npm i --global --silent @bjia56/portable-python-{PYTHON_VERSION}"))
101-
10288
if pkg_dir.exists():
103-
# look for any python binary under the package (handles headless builds)
10489
for p in pkg_dir.rglob("bin/python*"):
105-
py = str(p)
106-
break
90+
info(f"Found custom python @ {p}")
91+
return str(p)
10792

108-
if not py or py == "":
109-
raise RuntimeError(
110-
f"python {PYTHON_VERSION} not found after installation attempt"
111-
)
112-
else:
113-
info(f"Found custom python @ {py}")
114-
115-
return py
93+
raise RuntimeError(
94+
f"Portable Python {PYTHON_VERSION} not found. "
95+
f"Run scripts/setup-scenarios-prerequisites.sh first."
96+
)
11697

11798

118-
def _install_cqlsh():
119-
"""Download Apache Cassandra tarball and return (cqlsh_path, python3.11_path).
99+
def _find_cqlsh():
100+
"""Locate cqlsh and custom Python installed by scripts/setup-scenarios-prerequisites.sh.
120101
121-
The tarball is extracted once to ~/.foc-devnet/artifacts/cassandra/ and reused
122-
on subsequent runs. Custom Python is ensured before returning.
102+
Returns (cqlsh_path, custom_python_path).
103+
Raises RuntimeError if not found.
123104
"""
124-
custom_python = _ensure_custom_python()
105+
custom_python = _find_custom_python()
125106
cqlsh = CASSANDRA_HOME / "bin" / "cqlsh"
126-
if cqlsh.exists():
127-
cqlsh_version = sh(f"CQLSH_PYTHON={custom_python} {cqlsh} --version")
128-
info(f"cqlsh version chk: {cqlsh_version}")
129-
info(f"cqlsh already installed at {cqlsh}")
130-
return str(cqlsh), custom_python
131-
info("--- Installing cqlsh from Apache Cassandra tarball ---")
132-
CASSANDRA_DIR.mkdir(parents=True, exist_ok=True)
133-
tarball = CASSANDRA_DIR / f"apache-cassandra-{CASSANDRA_VERSION}-bin.tar.gz"
134-
sh(f"curl -fL -o {tarball} {CASSANDRA_URL}")
135-
sh(f"tar -xzf {tarball} -C {CASSANDRA_DIR}")
107+
if not cqlsh.exists():
108+
raise RuntimeError(
109+
f"cqlsh not found at {cqlsh}. "
110+
f"Run scripts/setup-scenarios-prerequisites.sh first."
111+
)
136112
cqlsh_version = sh(f"CQLSH_PYTHON={custom_python} {cqlsh} --version")
137-
info(f"cqlsh version chk: {cqlsh_version}")
113+
info(f"cqlsh version: {cqlsh_version}")
138114
return str(cqlsh), custom_python
139115

140116

@@ -175,7 +151,7 @@ def run():
175151
info(f"Run index: {run_index} (persisted to {RUN_COUNTER_FILE})")
176152
info(f"Effective seeds — small file: {seed_small}, large file: {seed_large}")
177153

178-
cqlsh, python = _install_cqlsh()
154+
cqlsh, python = _find_cqlsh()
179155

180156
d = devnet_info()["info"]
181157
sp = d["pdp_sps"][0]

scenarios/test_storage_e2e.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ def run():
5252
):
5353
return
5454

55+
sdk_commit = sh(f"git -C {sdk_dir} rev-parse HEAD")
56+
info(f"synapse-sdk commit: {sdk_commit}")
57+
5558
info("--- Installing synapse-sdk dependencies with pnpm ---")
5659
if not run_cmd(
5760
["pnpm", "install"], cwd=str(sdk_dir), label="pnpm install completed"
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env bash
2+
# ─────────────────────────────────────────────────────────────
3+
# setup-scenarios-prerequisites.sh — Install all scenario test
4+
# dependencies so that scenario scripts only run tests, not setup.
5+
#
6+
# Installs (if not already present):
7+
# 1. Foundry (cast, forge)
8+
# 2. Portable Python 3.10 (for cqlsh / Cassandra compatibility)
9+
# 3. cqlsh via Apache Cassandra tarball
10+
#
11+
# Also verifies that git, node, and pnpm are available.
12+
#
13+
# Usage:
14+
# ./scripts/setup-scenarios-prerequisites.sh
15+
# ─────────────────────────────────────────────────────────────
16+
set -euo pipefail
17+
18+
RED='\033[0;31m'
19+
GREEN='\033[0;32m'
20+
BLUE='\033[0;34m'
21+
NC='\033[0m'
22+
23+
pass() { printf "${GREEN}${NC} %s\n" "$1"; }
24+
fail() { printf "${RED}${NC} %s\n" "$1"; exit 1; }
25+
info() { printf "${BLUE}${NC} %s\n" "$1"; }
26+
27+
# ── Constants ────────────────────────────────────────────────
28+
CASSANDRA_VERSION="5.0.6"
29+
PYTHON_VERSION="3.10"
30+
CASSANDRA_URL="https://dlcdn.apache.org/cassandra/${CASSANDRA_VERSION}/apache-cassandra-${CASSANDRA_VERSION}-bin.tar.gz"
31+
CASSANDRA_DIR="$HOME/.foc-devnet/artifacts/cassandra"
32+
CASSANDRA_HOME="${CASSANDRA_DIR}/apache-cassandra-${CASSANDRA_VERSION}"
33+
34+
# ── 0. Verify basic system tools ────────────────────────────
35+
info "Checking basic system tools..."
36+
37+
for tool in git node pnpm npm; do
38+
if command -v "$tool" &>/dev/null; then
39+
pass "$tool is installed ($(command -v "$tool"))"
40+
else
41+
fail "$tool is required but not found. Please install it first."
42+
fi
43+
done
44+
45+
# ── 1. Foundry (cast / forge) ───────────────────────────────
46+
info "Checking Foundry..."
47+
48+
if command -v cast &>/dev/null; then
49+
pass "Foundry already installed (cast @ $(command -v cast))"
50+
else
51+
info "Installing Foundry..."
52+
curl -sSL https://foundry.paradigm.xyz | bash
53+
export PATH="$HOME/.foundry/bin:$PATH"
54+
"$HOME/.foundry/bin/foundryup"
55+
if command -v cast &>/dev/null; then
56+
pass "Foundry installed successfully"
57+
else
58+
fail "Foundry installation failed — cast not found on PATH"
59+
fi
60+
fi
61+
62+
# ── 2. Portable Python (for cqlsh) ──────────────────────────
63+
info "Checking portable Python ${PYTHON_VERSION}..."
64+
65+
NPM_ROOT="$(npm root -g)"
66+
PKG_DIR="${NPM_ROOT}/@bjia56/portable-python-${PYTHON_VERSION}"
67+
CUSTOM_PYTHON=""
68+
69+
if [[ -d "$PKG_DIR" ]]; then
70+
CUSTOM_PYTHON="$(find "$PKG_DIR" -path '*/bin/python*' -type f | head -n1)"
71+
fi
72+
73+
if [[ -n "$CUSTOM_PYTHON" ]]; then
74+
pass "Portable Python ${PYTHON_VERSION} already installed (${CUSTOM_PYTHON})"
75+
else
76+
info "Installing portable Python ${PYTHON_VERSION} via npm..."
77+
npm i --global --silent "@bjia56/portable-python-${PYTHON_VERSION}"
78+
CUSTOM_PYTHON="$(find "$PKG_DIR" -path '*/bin/python*' -type f | head -n1)"
79+
if [[ -n "$CUSTOM_PYTHON" ]]; then
80+
pass "Portable Python ${PYTHON_VERSION} installed (${CUSTOM_PYTHON})"
81+
else
82+
fail "Portable Python ${PYTHON_VERSION} installation failed — binary not found under ${PKG_DIR}"
83+
fi
84+
fi
85+
86+
# ── 3. cqlsh (Apache Cassandra tarball) ──────────────────────
87+
info "Checking cqlsh..."
88+
89+
CQLSH="${CASSANDRA_HOME}/bin/cqlsh"
90+
91+
if [[ -x "$CQLSH" ]]; then
92+
CQLSH_VERSION="$(CQLSH_PYTHON="$CUSTOM_PYTHON" "$CQLSH" --version 2>&1 || true)"
93+
pass "cqlsh already installed (${CQLSH_VERSION})"
94+
else
95+
info "Downloading Apache Cassandra ${CASSANDRA_VERSION} for cqlsh..."
96+
mkdir -p "$CASSANDRA_DIR"
97+
TARBALL="${CASSANDRA_DIR}/apache-cassandra-${CASSANDRA_VERSION}-bin.tar.gz"
98+
curl -fL -o "$TARBALL" "$CASSANDRA_URL"
99+
tar -xzf "$TARBALL" -C "$CASSANDRA_DIR"
100+
if [[ -x "$CQLSH" ]]; then
101+
CQLSH_VERSION="$(CQLSH_PYTHON="$CUSTOM_PYTHON" "$CQLSH" --version 2>&1 || true)"
102+
pass "cqlsh installed (${CQLSH_VERSION})"
103+
else
104+
fail "cqlsh installation failed — ${CQLSH} not found after extraction"
105+
fi
106+
fi
107+
108+
# ── Done ─────────────────────────────────────────────────────
109+
echo ""
110+
echo "════════════════════════════════════════════════════════"
111+
printf "${GREEN}✓ All scenario prerequisites are installed.${NC}\n"
112+
echo "════════════════════════════════════════════════════════"

0 commit comments

Comments
 (0)