Skip to content

Commit 57b30bc

Browse files
authored
ENG-9212: integration socket.dev in OSS integration tests (#6280)
* ENG-9212: integration socket.dev in OSS integration tests * don't pass git+https dependencies through sfw * greptile feedback * handle git+https wheels earlier in the process * simplify git+https install * Revert pyi_hashes.json change This reverts commit 88d0a0e. * Make the bun/npm sfw shim more focused * Add local `sfw-shims` for adding sfw-enabled bun/npm to PATH * consolidate sfw wrapper logic * reference upstream issue * setup bun for integration_tests the sfw shims are expecting bun to exist * install bun before setting up shims * exclude reflex-dev/reflex repo
1 parent 046e66e commit 57b30bc

File tree

4 files changed

+118
-9
lines changed

4 files changed

+118
-9
lines changed

.github/workflows/integration_tests.yml

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,52 @@ jobs:
117117
with:
118118
fetch-tags: true
119119
fetch-depth: 0
120-
- uses: ./.github/actions/setup_build_env
120+
121+
# Install sfw BEFORE any dependency installation so all packages are scanned.
122+
- name: Install Socket.dev Firewall (free)
123+
uses: SocketDev/action@2d3f25590c6ed6ba11a9a14c064d962a3a04698f # v1.3.1
124+
with:
125+
mode: firewall-free
126+
127+
- name: Install Bun
128+
uses: oven-sh/setup-bun@v2
129+
- name: Activate sfw shims for npm and bun
130+
run: |
131+
SHIM_DIR="$(cd scripts/sfw-shims && pwd)"
132+
echo "$SHIM_DIR" >> "$GITHUB_PATH"
133+
echo "REFLEX_USE_SYSTEM_BUN=1" >> "$GITHUB_ENV"
134+
135+
# Inline setup_build_env steps so all installs go through sfw.
136+
- name: Install UV
137+
uses: astral-sh/setup-uv@v6
121138
with:
122139
python-version: ${{ matrix.python-version }}
123-
run-uv-sync: true
140+
enable-cache: true
141+
prune-cache: false
142+
activate-environment: true
143+
cache-dependency-glob: "uv.lock"
144+
- name: Setup Node
145+
uses: actions/setup-node@v4
146+
with:
147+
node-version: 22
148+
149+
# Build git+https deps as wheels outside sfw (avoids sfw MITM cert issues
150+
# with git), then install everything else through sfw for scanning.
151+
# TODO: revisit when https://github.com/SocketDev/sfw-free/issues/30 is resolved.
152+
- name: Pre-install git dependencies (outside sfw)
153+
run: |
154+
# Install git+https deps directly without sfw to avoid MITM cert issues.
155+
# Their transitive registry deps will still be scanned by sfw uv sync.
156+
grep -oP 'git\+https://[^"]+' uv.lock | sort -u > "$RUNNER_TEMP/git-deps.txt" || true
157+
if [ -s "$RUNNER_TEMP/git-deps.txt" ]; then
158+
echo "Installing git dependencies:"
159+
cat "$RUNNER_TEMP/git-deps.txt"
160+
uv pip install --no-deps -r "$RUNNER_TEMP/git-deps.txt"
161+
else
162+
echo "No git dependencies found."
163+
fi
164+
- name: Install Dependencies (scanned by Socket.dev)
165+
run: sfw uv sync
124166

125167
- name: Clone Reflex Website Repo
126168
uses: actions/checkout@v4
@@ -130,25 +172,45 @@ jobs:
130172
path: reflex-web
131173
submodules: recursive
132174

133-
- name: Compile pyproject.toml into requirements.txt
175+
# TODO: revisit when https://github.com/SocketDev/sfw-free/issues/30 is resolved.
176+
- name: Pre-install reflex-web git dependencies (outside sfw)
134177
working-directory: ./reflex-web
135178
run: |
136-
uv pip compile pyproject.toml --no-annotate --no-header --no-deps --output-file requirements.txt
179+
# Install git+https deps from pyproject.toml before pip compile resolves them.
180+
# Exclude reflex itself — the PR version is already installed.
181+
grep -oP 'git\+https://[^"'"'"']+' pyproject.toml | grep -v 'reflex-dev/reflex\.git' | sort -u > git-requirements.txt || true
182+
if [ -s git-requirements.txt ]; then
183+
echo "Installing git dependencies:"
184+
cat git-requirements.txt
185+
uv pip install --no-deps -r git-requirements.txt
186+
fi
187+
- name: Compile and install reflex-web requirements (scanned by Socket.dev)
188+
working-directory: ./reflex-web
189+
run: |
190+
sfw uv pip compile pyproject.toml --no-annotate --no-header --no-deps --output-file requirements.txt
137191
uv pip list --format=json | jq -r '"^" + .[].name + "[ =]"' > installed_patterns.txt
138192
grep -ivf installed_patterns.txt requirements.txt > requirements.txt.tmp && mv requirements.txt.tmp requirements.txt
139193
rm installed_patterns.txt
140-
- name: Install Requirements for reflex-web
141-
working-directory: ./reflex-web
142-
run: uv pip install -r requirements.txt
194+
if [ -s requirements.txt ]; then
195+
sfw uv pip install -r requirements.txt
196+
fi
143197
- name: Init Website for reflex-web
144198
working-directory: ./reflex-web
145199
run: uv run --active --no-sync reflex init
146200
- name: Run Website and Check for errors
147201
run: |
148-
# Check that npm is home
149-
npm -v
202+
# Verify sfw wrappers are on PATH
203+
which npm && npm -v
150204
uv run --active --no-sync bash scripts/integration.sh ./reflex-web prod
151205
206+
- name: Upload Socket.dev Firewall report
207+
if: always()
208+
uses: actions/upload-artifact@v4
209+
with:
210+
name: sfw-report-reflex-web-py${{ matrix.python-version }}
211+
path: ${{ env.SFW_JSON_REPORT_PATH }}
212+
if-no-files-found: warn
213+
152214
rx-shout-from-template:
153215
strategy:
154216
fail-fast: false

scripts/sfw-shims/activate.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
# Source this file to route npm/bun through Socket.dev Firewall (sfw).
3+
# Usage: source scripts/sfw-shims/activate.sh
4+
SHIM_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-${(%):-%x}}")" && pwd)"
5+
export PATH="$SHIM_DIR:$PATH"
6+
export REFLEX_USE_SYSTEM_BUN=1
7+
echo "sfw shims activated (npm=$(which npm), bun=$(which bun))"

scripts/sfw-shims/bun

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
# Remove this shim's directory from PATH so we find the real bun
3+
SHIM_DIR="$(cd "$(dirname "$0")" && pwd)"
4+
export PATH="${PATH//$SHIM_DIR:/}"
5+
export PATH="${PATH//:$SHIM_DIR/}"
6+
7+
# Use sfw directly if available, otherwise fall back to npx sfw
8+
if command -v sfw >/dev/null 2>&1; then
9+
SFW=sfw
10+
else
11+
SFW="npx sfw"
12+
fi
13+
14+
# Only route registry-touching commands through sfw
15+
case "${1-}" in
16+
install|add|update|pm)
17+
exec $SFW bun "$@" ;;
18+
*)
19+
exec bun "$@" ;;
20+
esac

scripts/sfw-shims/npm

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
# Remove this shim's directory from PATH so we find the real npm
3+
SHIM_DIR="$(cd "$(dirname "$0")" && pwd)"
4+
export PATH="${PATH//$SHIM_DIR:/}"
5+
export PATH="${PATH//:$SHIM_DIR/}"
6+
7+
# Use sfw directly if available, otherwise fall back to npx sfw
8+
if command -v sfw >/dev/null 2>&1; then
9+
SFW=sfw
10+
else
11+
SFW="npx sfw"
12+
fi
13+
14+
# Only route registry-touching commands through sfw
15+
case "${1-}" in
16+
install|ci|update|audit|pack|publish|fund|outdated)
17+
exec $SFW npm "$@" ;;
18+
*)
19+
exec npm "$@" ;;
20+
esac

0 commit comments

Comments
 (0)