mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
test(e2e): start the E2E backend with only the variables the suite defines
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.
This commit is contained in:
1 parent
2e31cb45ba
commit
b431c121a2
2 files changed
+17
-4
No files matched your search
@@ -1,6 +1,8 @@
|
||||
import { defineConfig, devices } from '@playwright/test'
|
||||
import { BASE_URL, E2E_ROOT, REPORT_DIR, REPO_ROOT, STORAGE_STATE, TEST_RESULTS_DIR, createServerEnv } from './env'
|
||||
|
||||
const serverEnv = createServerEnv()
|
||||
|
||||
export default defineConfig({
|
||||
testDir: E2E_ROOT,
|
||||
outputDir: TEST_RESULTS_DIR,
|
||||
@@ -43,6 +45,6 @@ export default defineConfig({
|
||||
timeout: 180_000,
|
||||
reuseExistingServer: false,
|
||||
gracefulShutdown: { signal: 'SIGTERM', timeout: 15_000 },
|
||||
env: createServerEnv(),
|
||||
env: { ...serverEnv, E2E_SERVER_ENV_KEYS: Object.keys(serverEnv).join(' ') },
|
||||
},
|
||||
})
|
||||
+14
-3
@@ -5,11 +5,22 @@ 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"
|
||||
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
|
||||
|
||||
cd "$ROOT"
|
||||
bun run backend/dist/index.js &
|
||||
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"
|
||||
Reference in new issue
Block a user