Skip to content

fix(e2e): harden server lifecycle and environment isolation - #189

Merged
devarshishimpi merged 1 commit into
mainfrom
fix/e2e-playwright-hardening
Nov 19, 2026
Merged

devarshishimpi merged 1 commit into
mainfrom
fix/e2e-playwright-hardening

Conversation

@devarshishimpi

@devarshishimpi devarshishimpi commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

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 so SIGTERM/SIGINT cannot 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 built apps/node/dist/index.js directly instead of npm run dev:node, and make process-tree cleanup idempotent with a SIGKILL fallback.
  • playwright.config.ts: parse .env.e2e, validate APP_URL as loopback-only HTTP without credentials, paths, or query/hash fragments, and pipe web server stdout/stderr for diagnosability.
  • playwright/smoke.spec.ts: stub GET /api/auth/session with the real signed-out 401 response instead of a synthetic 200.
  • CONTRIBUTING.md: bind disposable Postgres/Redis to 127.0.0.1, use docker rm -f for teardown, and remove stray blank lines.

Dependencies: no new runtime dependencies. @playwright/test remains a dev dependency (reordered alphabetically in package.json); the E2E run still requires Node 24+, Docker, and disposable local Postgres/Redis services as documented.

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Documentation update

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.
  • Ran the E2E launcher pre-flight check and confirmed it fails fast with an actionable error when .env.e2e is 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.

  • Unit Tests
  • Integration Tests
  • Manual Dashboard Verification
  • Manual GitHub Webhook Verification

Checklist:

  • I have starred Codra on GitHub
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes
  • I have signed the CLA

- 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

@codra-app-personal codra-app-personal Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 👍.

Comment thread apps/node/src/index.ts
isShuttingDown = true;
shutdownStartTime = now;

const globalShutdownTimeout = setTimeout(() => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Suggested change
const globalShutdownTimeout = setTimeout(() => {
const globalShutdownTimeout = setTimeout(() => {
logger.error("Global shutdown timed out after 18000ms. Forcing immediate exit.");
process.exit(1);
}, 18000);

@devarshishimpi
devarshishimpi merged commit f3ba3bf into main Nov 19, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant