From a38096e8cc7b7d0fb3e9cafa64c2918cfa327769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrew=20Beveridge=20=E2=98=84=EF=B8=8F?= Date: Mon, 2 Mar 2026 23:18:28 -0500 Subject: [PATCH] fix: prevent test hanging from emulator prompts, zombies, port conflicts (#448) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - Add `--quiet` flag to `gcloud beta emulators firestore start` to prevent interactive prompts that hang CI/agent sessions - Fix `stop-emulators.sh` to kill Java child processes (`pkill -P`) with port-based fallback for orphans on port 8080 - Generate unique Playwright dev server port per worktree (3100-3199 hash range) to prevent cross-worktree conflicts ## Test plan - [ ] `./scripts/start-emulators.sh` starts without interactive prompts - [ ] `./scripts/stop-emulators.sh` kills Java emulator child processes (no orphans on port 8080) - [ ] Playwright config generates different ports for different worktree directories - [ ] `E2E_PORT` env var still overrides the default port 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 --- frontend/playwright.config.ts | 15 ++++++++++++--- scripts/start-emulators.sh | 1 + scripts/stop-emulators.sh | 25 +++++++++++-------------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/frontend/playwright.config.ts b/frontend/playwright.config.ts index 7b6d3190..a594e32b 100644 --- a/frontend/playwright.config.ts +++ b/frontend/playwright.config.ts @@ -18,9 +18,18 @@ if (fs.existsSync(envLocalPath)) { } } -// Configurable port for dev server (default: 3000) -// Use E2E_PORT env var to change, e.g.: E2E_PORT=3001 npx playwright test -const PORT = process.env.E2E_PORT || '3000'; +// Generate a stable port per worktree directory to avoid cross-worktree conflicts. +// Each worktree gets a unique port in the 3100-3199 range based on a hash of __dirname. +// Override with E2E_PORT env var, e.g.: E2E_PORT=3001 npx playwright test +const DEFAULT_PORT = (() => { + const dir = __dirname; + let hash = 0; + for (let i = 0; i < dir.length; i++) { + hash = ((hash << 5) - hash + dir.charCodeAt(i)) | 0; + } + return 3100 + (Math.abs(hash) % 100); // 3100-3199 +})(); +const PORT = process.env.E2E_PORT || String(DEFAULT_PORT); // Use 127.0.0.1 instead of localhost to avoid IPv6 resolution issues on macOS. // localhost resolves to ::1 (IPv6) first, but Next.js dev server may not accept // IPv6 connections, causing Playwright's webServer health check to hang. diff --git a/scripts/start-emulators.sh b/scripts/start-emulators.sh index ad484d92..26f7cd32 100755 --- a/scripts/start-emulators.sh +++ b/scripts/start-emulators.sh @@ -21,6 +21,7 @@ else echo "📦 Starting Firestore emulator on port 8080..." gcloud beta emulators firestore start \ --host-port=127.0.0.1:8080 \ + --quiet \ > "$EMULATOR_LOG_DIR/firestore.log" 2>&1 & FIRESTORE_PID=$! diff --git a/scripts/stop-emulators.sh b/scripts/stop-emulators.sh index a17be689..d2e19c1d 100755 --- a/scripts/stop-emulators.sh +++ b/scripts/stop-emulators.sh @@ -16,23 +16,20 @@ if [ -f "$EMULATOR_LOG_DIR/firestore.pid" ]; then FIRESTORE_PID=$(cat "$EMULATOR_LOG_DIR/firestore.pid") if ps -p $FIRESTORE_PID > /dev/null 2>&1; then echo "📦 Stopping Firestore emulator (PID: $FIRESTORE_PID)..." + # Kill the process and its children (Java emulator subprocess) + pkill -P $FIRESTORE_PID 2>/dev/null || true kill $FIRESTORE_PID 2>/dev/null || true - rm "$EMULATOR_LOG_DIR/firestore.pid" - echo " ✅ Firestore emulator stopped" - else - echo "⚠️ Firestore emulator not running" - rm "$EMULATOR_LOG_DIR/firestore.pid" fi + rm -f "$EMULATOR_LOG_DIR/firestore.pid" +fi +# Always clean up by port as a fallback (catches orphaned Java processes) +REMAINING=$(lsof -ti:8080 2>/dev/null || true) +if [ -n "$REMAINING" ]; then + echo "📦 Cleaning up remaining processes on port 8080..." + kill $REMAINING 2>/dev/null || true + echo " ✅ Firestore emulator stopped" else - # Try to kill by port if PID file doesn't exist - FIRESTORE_PID=$(lsof -ti:8080 2>/dev/null || true) - if [ ! -z "$FIRESTORE_PID" ]; then - echo "📦 Stopping Firestore emulator on port 8080 (PID: $FIRESTORE_PID)..." - kill $FIRESTORE_PID 2>/dev/null || true - echo " ✅ Firestore emulator stopped" - else - echo "⚠️ Firestore emulator not running" - fi + echo "⚠️ Firestore emulator not running" fi # Stop GCS emulator