mirror of
https://github.com/hyperdxio/hyperdx
synced 2026-04-21 13:37:15 +00:00
## Summary - Isolate dev, E2E, and integration test environments so multiple git worktrees can run all three simultaneously without port conflicts - Each worktree gets a deterministic slot (0-99) with unique port ranges: dev (30100-31199), E2E (20320-21399), CI integration (14320-40098) - Dev portal dashboard (http://localhost:9900) auto-discovers all running stacks, streams logs, and provides a History tab for past run logs ## Port Isolation | Environment | Port Range | Project Name | |---|---|---| | Dev stack | 30100-31199 | `hdx-dev-<slot>` | | E2E tests | 20320-21399 | `e2e-<slot>` | | CI integration | 14320-40098 | `int-<slot>` | All three can run simultaneously from the same worktree with zero port conflicts. ## Dev Portal Features **Live tab:** - Auto-discovers dev, E2E, and integration Docker containers + local services (API, App) - Groups all environments for the same worktree into a single card - SSE log streaming with ANSI color rendering, capped at 5000 lines - Auto-starts in background from `make dev`, `make dev-e2e`, `make dev-int` **History tab:** - Logs archived to `~/.config/hyperdx/dev-slots/<slot>/history/` on exit (instead of deleted) - Each archived run includes `meta.json` with worktree/branch metadata - Grouped by worktree with collapsible cards, search by worktree/branch - View any past log file in the same log panel, delete individual runs or clear all - Custom dark-themed confirm modal (no native browser dialogs) ## What Changed - **`scripts/dev-env.sh`** — Slot-based port assignments, portal auto-start, log archival on exit - **`scripts/test-e2e.sh`** — E2E port range (20320-21399), log capture via `tee`, portal auto-start, log archival - **`scripts/ensure-dev-portal.sh`** — Shared singleton portal launcher (works sourced or executed) - **`scripts/dev-portal/server.js`** — Discovery for dev/E2E/CI containers, history API (list/read/delete), local service port probing - **`scripts/dev-portal/index.html`** — Live/History tabs, worktree-grouped cards, search, collapse/expand, custom confirm modal, ANSI color log rendering - **`docker-compose.dev.yml`** — Parameterized ports/volumes/project name with `hdx.dev.*` labels - **`packages/app/tests/e2e/docker-compose.yml`** — Updated to new E2E port defaults - **`Makefile`** — `dev-int`/`dev-e2e` targets with log capture + portal auto-start; `dev-portal-stop`; `dev-clean` stops everything + wipes slot data - **`.env` files** — Ports use `${VAR:-default}` syntax across dev, E2E, and CI environments - **`agent_docs/development.md`** — Full documentation for isolation, port tables, E2E/CI port ranges ## How to Use ```bash # Start dev stack (auto-starts portal) make dev # Run E2E tests (auto-starts portal, separate ports) make dev-e2e FILE=navigation # Run integration tests (auto-starts portal, separate ports) make dev-int FILE=alerts # All three can run simultaneously from the same worktree # Portal at http://localhost:9900 shows everything # Stop portal make dev-portal-stop # Clean up everything (all stacks + portal + history) make dev-clean ``` ## Dev Portal <img width="1692" height="944" alt="image" src="https://github.com/user-attachments/assets/6ed388a3-43bc-4552-aa8d-688077b79fb7" /> <img width="1689" height="935" alt="image" src="https://github.com/user-attachments/assets/8677a138-0a40-4746-93ed-3b355c8bd45e" /> ## Test Plan - [x] Run `make dev` — verify services start with slot-assigned ports - [x] Run `make dev` in a second worktree — verify different ports, no conflicts - [x] Run `make dev-e2e` and `make dev-int` simultaneously — no port conflicts - [x] Open http://localhost:9900 — verify all stacks grouped by worktree - [x] Click a service to view logs — verify ANSI colors render correctly - [x] Stop a stack — verify logs archived to History tab with correct worktree - [x] History tab — search, collapse/expand, view archived logs, delete - [x] `make dev-clean` — stops everything, wipes slot data and history
113 lines
4.8 KiB
TypeScript
113 lines
4.8 KiB
TypeScript
import { defineConfig, devices } from '@playwright/test';
|
|
import path from 'path';
|
|
|
|
// Check if we should use full-stack mode (with backend)
|
|
const USE_FULLSTACK = process.env.E2E_FULLSTACK === 'true';
|
|
// Check if we should use next dev (hot reload) instead of build + start
|
|
const USE_DEV = process.env.E2E_USE_DEV === 'true';
|
|
const AUTH_FILE = path.join(__dirname, 'tests/e2e/.auth/user.json');
|
|
|
|
// Port configuration (set by scripts/test-e2e.sh via HDX_E2E_* env vars)
|
|
const API_PORT = process.env.HDX_E2E_API_PORT || '21000';
|
|
const APP_PORT = process.env.HDX_E2E_APP_PORT || '21300';
|
|
const APP_LOCAL_PORT = process.env.HDX_E2E_APP_LOCAL_PORT || '21200';
|
|
|
|
// Timeout configuration constants (in milliseconds)
|
|
const TEST_TIMEOUT_MS = 60 * 1000; // 60 seconds per test
|
|
const API_SERVER_STARTUP_TIMEOUT_MS = 120 * 1000; // 2 minutes for API to start
|
|
const APP_SERVER_STARTUP_TIMEOUT_MS = 180 * 1000; // 3 minutes for Next.js build + start
|
|
|
|
/**
|
|
* @see https://playwright.dev/docs/test-configuration
|
|
*/
|
|
export default defineConfig({
|
|
testDir: './tests/e2e',
|
|
/* Global setup to ensure server is ready */
|
|
globalSetup: USE_FULLSTACK
|
|
? require.resolve('./tests/e2e/global-setup-fullstack.ts')
|
|
: require.resolve('./tests/e2e/global-setup-local.ts'),
|
|
/* Run tests in files in parallel */
|
|
fullyParallel: true,
|
|
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
|
forbidOnly: !!process.env.CI,
|
|
/* Retry on CI only */
|
|
retries: process.env.CI ? 2 : 1,
|
|
/* Use multiple workers on CI for faster execution */
|
|
workers: process.env.CI ? 2 : undefined,
|
|
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
|
reporter: [
|
|
['html'],
|
|
['json', { outputFile: 'test-results/results.json' }],
|
|
...(process.env.CI
|
|
? [['github'] as const, ['list'] as const]
|
|
: [['list'] as const]),
|
|
],
|
|
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
|
use: {
|
|
/* Base URL to use in actions like `await page.goto('/')`. */
|
|
baseURL: USE_FULLSTACK
|
|
? `http://localhost:${APP_PORT}`
|
|
: process.env.PLAYWRIGHT_BASE_URL || `http://localhost:${APP_LOCAL_PORT}`,
|
|
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
|
trace: 'on-first-retry',
|
|
/* Take screenshot on failure */
|
|
screenshot: 'only-on-failure',
|
|
/* Record video on failure */
|
|
video: 'retain-on-failure',
|
|
},
|
|
|
|
/* Global test timeout - CI needs more time than local */
|
|
timeout: TEST_TIMEOUT_MS,
|
|
|
|
/* Configure projects for different test environments */
|
|
projects: [
|
|
{
|
|
name: 'chromium',
|
|
use: {
|
|
...devices['Desktop Chrome'],
|
|
// Use saved authentication state for full-stack mode
|
|
...(USE_FULLSTACK && {
|
|
storageState: AUTH_FILE,
|
|
}),
|
|
},
|
|
},
|
|
],
|
|
|
|
/* Run your local dev server before starting the tests */
|
|
// Note: webServer array syntax requires Playwright v1.32.0+ (current: v1.57.0)
|
|
webServer: USE_FULLSTACK
|
|
? [
|
|
// Full-stack mode: Start API and App servers (infrastructure started separately)
|
|
{
|
|
// Connections/sources come from env (injected by run-e2e.js from e2e-fixtures.json)
|
|
command: `cd ../api && ${process.env.MONGO_URI ? `MONGO_URI="${process.env.MONGO_URI}"` : ''} DOTENV_CONFIG_PATH=.env.e2e npx ts-node --transpile-only -r tsconfig-paths/register -r dotenv-expand/config -r @hyperdx/node-opentelemetry/build/src/tracing src/index.ts`,
|
|
port: parseInt(API_PORT, 10),
|
|
reuseExistingServer: !process.env.CI,
|
|
timeout: API_SERVER_STARTUP_TIMEOUT_MS,
|
|
stdout: 'pipe',
|
|
stderr: 'pipe',
|
|
},
|
|
{
|
|
// Full UI: Alerts + Dashboards. Not local mode; Alerts enabled;
|
|
command: USE_DEV
|
|
? `SERVER_URL=http://localhost:${API_PORT} PORT=${APP_PORT} NEXT_DIST_DIR=.next-e2e next dev --webpack`
|
|
: `SERVER_URL=http://localhost:${API_PORT} PORT=${APP_PORT} NEXT_DIST_DIR=.next-e2e yarn build && SERVER_URL=http://localhost:${API_PORT} PORT=${APP_PORT} NEXT_DIST_DIR=.next-e2e yarn start`,
|
|
port: parseInt(APP_PORT, 10),
|
|
reuseExistingServer: !process.env.CI,
|
|
timeout: APP_SERVER_STARTUP_TIMEOUT_MS,
|
|
stdout: 'pipe',
|
|
stderr: 'pipe',
|
|
},
|
|
]
|
|
: {
|
|
// Local mode: Frontend only
|
|
command: USE_DEV
|
|
? `NEXT_PUBLIC_IS_LOCAL_MODE=true PORT=${APP_LOCAL_PORT} NEXT_DIST_DIR=.next-e2e next dev --webpack`
|
|
: `NEXT_PUBLIC_IS_LOCAL_MODE=true NEXT_DIST_DIR=.next-e2e yarn build && NEXT_PUBLIC_IS_LOCAL_MODE=true PORT=${APP_LOCAL_PORT} NEXT_DIST_DIR=.next-e2e yarn start`,
|
|
port: parseInt(APP_LOCAL_PORT, 10),
|
|
reuseExistingServer: !process.env.CI,
|
|
timeout: APP_SERVER_STARTUP_TIMEOUT_MS,
|
|
stdout: 'pipe',
|
|
stderr: 'pipe',
|
|
},
|
|
});
|