Repository navigation
fix(e2e): harden server lifecycle and environment isolation - #189
Conversation
- Spawn the built server directly with a sanitized, allowlisted environment - Require all credentials in .env.e2e and validate APP_URL as loopback-only - Add bounded, ordered graceful shutdown with repeated-signal handling - Stub signed-out session as 401 to match the real server response - Bind test services to loopback and remove containers on teardown
There was a problem hiding this comment.
Codra Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d81de6913b
ℹ️ About Codra in GitHub
Your team has set up Codra to review pull requests in this repo. Reviews are triggered when you:
- Open a pull request for review
- Mark a draft as ready
If Codra has suggestions, it will comment; otherwise it will react with 👍.
| isShuttingDown = true; | ||
| shutdownStartTime = now; | ||
|
|
||
| const globalShutdownTimeout = setTimeout(() => { |
There was a problem hiding this comment.
Global shutdown timeout is shorter than cumulative sequential timeouts
The global shutdown timeout is hardcoded to 10,000ms (10 seconds), but the sequential resource cleanup steps have individual maximum timeouts that sum up to 15 seconds (HTTP server up to 5s, BullMQ worker up to 4s, reviewQueue up to 2s, Redis up to 2s, and Postgres up to 2s). If multiple cleanup tasks time out or experience delays, the global shutdown timer will force-exit the process prematurely at 10 seconds before the remaining cleanup steps can execute.
| const globalShutdownTimeout = setTimeout(() => { | |
| const globalShutdownTimeout = setTimeout(() => { | |
| logger.error("Global shutdown timed out after 18000ms. Forcing immediate exit."); | |
| process.exit(1); | |
| }, 18000); |
Description
Hardens the Playwright E2E setup across server lifecycle, environment isolation, and documentation. The previous setup could orphan server process trees, relied on ambient developer environment variables, ran the server through a hard-to-tear-down tsup watch process, and stubbed a session response that no longer matched the server's real signed-out behavior.
Changes:
apps/node/src/index.ts: add bounded, sequential graceful shutdown (HTTP listener, BullMQ worker and queue, Redis, Postgres) with per-resource timeouts, repeated-signal handling, and a global forced-exit fallback soSIGTERM/SIGINTcannot hang or leak resources.scripts/start-e2e-server.mjs: resolve the repo root from the launcher location, require all mandatory keys inside.env.e2e, allowlist environment and system variables passed to the child, spawn the builtapps/node/dist/index.jsdirectly instead ofnpm run dev:node, and make process-tree cleanup idempotent with aSIGKILLfallback.playwright.config.ts: parse.env.e2e, validateAPP_URLas loopback-only HTTP without credentials, paths, or query/hash fragments, and pipe web server stdout/stderr for diagnosability.playwright/smoke.spec.ts: stubGET /api/auth/sessionwith the real signed-out401response instead of a synthetic200.CONTRIBUTING.md: bind disposable Postgres/Redis to127.0.0.1, usedocker rm -ffor teardown, and remove stray blank lines.Dependencies: no new runtime dependencies.
@playwright/testremains a dev dependency (reordered alphabetically inpackage.json); the E2E run still requires Node 24+, Docker, and disposable local Postgres/Redis services as documented.Fixes # (issue)
Type of change
How Has This Been Tested?
Ran the local verification suite:
npm run lint— passed with 0 errors/warnings.npm run typecheck— passed with 0 errors.npm test— 511/511 tests across 69 files passed.npx playwright test --list— configuration parsed successfully and the Chromium smoke test was discovered.npm run build:node— dashboard and Node server bundles built successfully..env.e2eis absent, preventing accidental use of ambient credentials.The full Playwright browser run requires the disposable Docker Postgres/Redis services described in
CONTRIBUTING.md; only configuration discovery and launcher pre-flight validation were executed here.Checklist: