mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
The E2E backend inherited the caller's environment and Bun auto-loaded .env files from the repo root, so local credentials and host variables could leak into the run. server.sh now launches the backend with env -i, passing PATH and only the keys from createServerEnv (E2E_SERVER_ENV_KEYS), runs bun with --no-env-file, and starts it from a scratch directory with a frontend symlink so no .env file is in reach.
27 lines
715 B
Bash
27 lines
715 B
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
TMP="$ROOT/e2e/.tmp"
|
|
|
|
rm -rf "$TMP"
|
|
mkdir -p "$TMP/home" "$TMP/data" "$TMP/workspace" "$TMP/tmp" "$TMP/run" "$TMP/app"
|
|
ln -s "$ROOT/frontend" "$TMP/app/frontend"
|
|
trap 'rm -rf "$TMP"' EXIT
|
|
|
|
if [[ -z "${E2E_SERVER_ENV_KEYS:-}" ]]; then
|
|
echo "E2E_SERVER_ENV_KEYS is empty; refusing to start the E2E backend" >&2
|
|
exit 1
|
|
fi
|
|
|
|
args=()
|
|
for key in $E2E_SERVER_ENV_KEYS; do
|
|
args+=("$key=${!key}")
|
|
done
|
|
|
|
cd "$TMP/app"
|
|
env -i PATH="$PATH" "${args[@]}" bun --no-env-file run "$ROOT/backend/dist/index.js" &
|
|
BACKEND_PID=$!
|
|
trap 'kill -TERM "$BACKEND_PID" 2>/dev/null || true' TERM INT
|
|
wait "$BACKEND_PID" || wait "$BACKEND_PID"
|