From e4ccc450679776c2b48e7358637bb0e9c79404c9 Mon Sep 17 00:00:00 2001 From: Karl Power Date: Wed, 30 Sep 2026 12:20:16 +0200 Subject: [PATCH 1/2] refactor(scripts): compute worktree slots and ports in one place The slot formula (cksum of the folder name, mod 100) was copied into dev-env.sh, test-e2e.sh, the Makefile and seed-alerts.ts. The dev portal used a different formula, so it picked the wrong slot. Add scripts/slots.sh (hdx_dev_ports, hdx_ci_ports, hdx_e2e_ports) as the only place slots and ports are computed. It has no side effects. Add scripts/with-slots.sh for tools that need the dev ports. Every caller now uses them. Default ports are unchanged. Add HDX_SLOT_FROM=path, which hashes the worktree's full path instead of its folder name, for worktrees that share a name (a/hyperdx, b/hyperdx) --- .github/actions/e2e-setup/action.yml | 2 +- Makefile | 39 +++-- agent_docs/development.md | 113 +++++++++----- knip.json | 3 + packages/api/package.json | 2 +- packages/api/scripts/seed-alerts.ts | 33 ++-- packages/hdx-eval/scripts/env.sh | 9 +- scripts/__tests__/slots.test.mjs | 218 +++++++++++++++++++++++++++ scripts/dev-env.sh | 68 ++------- scripts/dev-portal/server.js | 18 ++- scripts/slots.sh | 102 +++++++++++++ scripts/test-e2e.sh | 34 +---- scripts/with-slots.sh | 12 ++ 13 files changed, 471 insertions(+), 182 deletions(-) create mode 100644 scripts/__tests__/slots.test.mjs create mode 100755 scripts/slots.sh create mode 100755 scripts/with-slots.sh diff --git a/.github/actions/e2e-setup/action.yml b/.github/actions/e2e-setup/action.yml index ba54200ccb..f4eaaf1ac9 100644 --- a/.github/actions/e2e-setup/action.yml +++ b/.github/actions/e2e-setup/action.yml @@ -9,7 +9,7 @@ description: | runs: using: composite steps: - # E2E port configuration (slot 0 defaults — must match scripts/test-e2e.sh) + # E2E port configuration (slot 0 defaults — must match scripts/slots.sh) - name: Set E2E environment variables shell: bash run: | diff --git a/Makefile b/Makefile index 03af32b42f..13d2e087d2 100644 --- a/Makefile +++ b/Makefile @@ -6,22 +6,19 @@ include .env # --------------------------------------------------------------------------- # Multi-agent / worktree isolation # --------------------------------------------------------------------------- -# Compute a deterministic port offset (0-99) from the working directory name -# so that multiple worktrees can run integration tests in parallel without -# port conflicts. Override HDX_CI_SLOT manually if you need a specific slot. -# -# Port mapping (base + slot): -# ClickHouse HTTP : 18123 + slot -# MongoDB : 39999 + slot -# API test server : 19000 + slot -# OpAMP : 14320 + slot +# Integration tests get a slot and ports per worktree so they can run in +# parallel. scripts/slots.sh computes them; override the slot with +# `make dev-int HDX_CI_SLOT=5`. # --------------------------------------------------------------------------- -HDX_CI_SLOT ?= $(shell printf '%s' "$(notdir $(CURDIR))" | cksum | awk '{print $$1 % 100}') -HDX_CI_PROJECT := int-$(HDX_CI_SLOT) -HDX_CI_CH_PORT := $(shell echo $$((18123 + $(HDX_CI_SLOT)))) -HDX_CI_MONGO_PORT:= $(shell echo $$((39999 + $(HDX_CI_SLOT)))) -HDX_CI_API_PORT := $(shell echo $$((19000 + $(HDX_CI_SLOT)))) -HDX_CI_OPAMP_PORT:= $(shell echo $$((14320 + $(HDX_CI_SLOT)))) +# Value of one variable exported by hdx_ci_ports in scripts/slots.sh. +ci_slots = $(shell HDX_CI_SLOT='$(HDX_CI_SLOT)' sh -c '. ./scripts/slots.sh && hdx_ci_ports && printf %s "$$$(1)"') + +HDX_CI_SLOT := $(call ci_slots,HDX_CI_SLOT) +HDX_CI_PROJECT := $(call ci_slots,HDX_CI_PROJECT) +HDX_CI_CH_PORT := $(call ci_slots,HDX_CI_CH_PORT) +HDX_CI_MONGO_PORT:= $(call ci_slots,HDX_CI_MONGO_PORT) +HDX_CI_API_PORT := $(call ci_slots,HDX_CI_API_PORT) +HDX_CI_OPAMP_PORT:= $(call ci_slots,HDX_CI_OPAMP_PORT) export HDX_CI_CH_PORT HDX_CI_MONGO_PORT HDX_CI_API_PORT HDX_CI_OPAMP_PORT @@ -135,9 +132,9 @@ dev-int-down: .PHONY: dev-e2e-down dev-e2e-down: - $(eval HDX_E2E_SLOT := $(shell printf '%s' "$(notdir $(CURDIR))" | cksum | awk '{print $$1 % 100}')) - docker compose -p e2e-$(HDX_E2E_SLOT) -f packages/app/tests/e2e/docker-compose.yml down -v - @for port in $$((21000 + $(HDX_E2E_SLOT))) $$((20320 + $(HDX_E2E_SLOT))) $$((21300 + $(HDX_E2E_SLOT))) $$((21200 + $(HDX_E2E_SLOT))); do \ + @. ./scripts/slots.sh && hdx_e2e_ports && \ + docker compose -p "$$E2E_PROJECT" -f packages/app/tests/e2e/docker-compose.yml down -v && \ + for port in $$HDX_E2E_API_PORT $$HDX_E2E_OPAMP_PORT $$HDX_E2E_APP_PORT $$HDX_E2E_APP_LOCAL_PORT; do \ pids=$$(lsof -ti :$$port 2>/dev/null); \ for pid in $$pids; do \ echo "Killing process $$pid on port $$port"; \ @@ -196,6 +193,7 @@ ci-unit: node --test .github/scripts/__tests__/release-notes.test.mjs node --test .github/scripts/__tests__/changeset-hash.test.mjs node --test .github/scripts/code-review/__tests__/review-comments.test.mjs + node --test scripts/__tests__/slots.test.mjs .PHONY: ci-triage ci-triage: @@ -205,9 +203,6 @@ ci-triage: # --------------------------------------------------------------------------- # E2E tests — port isolation is handled by scripts/test-e2e.sh # --------------------------------------------------------------------------- -# Slot for the Playwright report server (only used by the Makefile REPORT flag) -HDX_E2E_SLOT ?= $(shell printf '%s' "$(notdir $(CURDIR))" | cksum | awk '{print $$1 % 100}') - .PHONY: e2e e2e: ./scripts/test-e2e.sh @@ -227,7 +222,7 @@ dev-e2e-clean: dev-e2e: ./scripts/test-e2e.sh --dev $(if $(FILE),$(FILE)) $(if $(GREP),--grep "$(GREP)") $(ARGS); \ ret=$$?; \ - $(if $(REPORT),cd packages/app && npx playwright show-report --port $$((9323 + $(HDX_E2E_SLOT)));) \ + $(if $(REPORT),. ./scripts/slots.sh && hdx_e2e_ports && cd packages/app && npx playwright show-report --port $$HDX_E2E_REPORT_PORT;) \ exit $$ret diff --git a/agent_docs/development.md b/agent_docs/development.md index 0ec88a7c4f..8b53d3154a 100644 --- a/agent_docs/development.md +++ b/agent_docs/development.md @@ -41,8 +41,10 @@ multiple agents or developers working in parallel), use `make dev` instead of ### How It Works -1. A deterministic slot (0-99) is computed from the worktree directory name (via - `cksum`) +1. `scripts/slots.sh` computes a deterministic slot (0-99) from the worktree + directory name (via `cksum`), or from its full path with `HDX_SLOT_FROM=path` + (see below). It is the only place slots and ports are computed: `yarn dev`, + `make dev-int`, `make dev-e2e`, and tools all use it. 2. Each service gets a unique port: `base + slot` (see table below) 3. Docker Compose runs with a unique project name (`hdx-dev-`) 4. Volume paths include the slot to prevent data corruption between worktrees @@ -92,6 +94,36 @@ The portal auto-refreshes every 3 seconds and shows each worktree's: HDX_DEV_SLOT=5 make dev ``` +### Worktrees With the Same Folder Name + +If your worktrees share a folder name (`a/hyperdx`, `b/hyperdx`), they get the +same slot and clash. Set `HDX_SLOT_FROM=path` in your shell profile to hash each +worktree's full path instead. It applies to the dev stack, integration tests, +E2E tests, and the dev portal. + +```bash +export HDX_SLOT_FROM=path +``` + +Your existing stacks move to new slots once, so their dev data (in +`.volumes/*_`) starts empty. The default, `HDX_SLOT_FROM=name`, keeps +today's slots. + +### Tools That Talk to the Dev Stack + +Run them through `scripts/with-slots.sh`. It sets this worktree's dev ports +(`HDX_DEV_CH_HTTP_PORT`, `HYPERDX_API_PORT`, ...) and nothing else. Don't source +`scripts/dev-env.sh` for this: it also clears `packages/app/.next` and registers +the stack with the dev portal, which disrupts a running `yarn dev`. + +```bash +# From a package script, e.g. packages/api's "seed:alerts" +../../scripts/with-slots.sh ts-node scripts/seed-alerts.ts + +# Against another slot +HDX_DEV_SLOT=5 scripts/with-slots.sh +``` + ## Testing Strategy ### Testing Tools @@ -254,65 +286,64 @@ yarn run lint - **Controllers**: `packages/api/src/controllers/` - **Pages**: `packages/app/pages/` - **Components**: `packages/app/src/` -- **Shared Utils**: `packages/common-utils/src/` — no root barrel, so imports are - deep `@hyperdx/common-utils/dist/...` paths. See - [`code_style.md`](code_style.md#where-shared-code-already-lives) for the module - map and the grep-first rule before you add a helper. +- **Shared Utils**: `packages/common-utils/src/` — no root barrel, so imports + are deep `@hyperdx/common-utils/dist/...` paths. See + [`code_style.md`](code_style.md#where-shared-code-already-lives) for the + module map and the grep-first rule before you add a helper. ## Vercel Preview Deployments (Inline API) -The `hyperdx-private` Vercel project deploys the `@hyperdx/app` Next.js app -for preview environments. Normally `/api/*` requests proxy to a separately -deployed API service (`SERVER_URL`). For PR previews we instead **inline the -entire Express API** into the Next.js serverless function so a single Vercel -deployment serves both the app and the API. +The `hyperdx-private` Vercel project deploys the `@hyperdx/app` Next.js app for +preview environments. Normally `/api/*` requests proxy to a separately deployed +API service (`SERVER_URL`). For PR previews we instead **inline the entire +Express API** into the Next.js serverless function so a single Vercel deployment +serves both the app and the API. ### How it works -1. `packages/api/src/serverless.ts` exposes the Express app from - `api-app.ts` as a stateless `(req, res) => Promise` handler. It - lazily connects to MongoDB on the first invocation and caches the - connection across warm invocations. -2. `packages/app/pages/api/[...all].ts` branches on the - `HDX_PREVIEW_INLINE_API` env var. When `true`, it `require()`s the - compiled serverless handler and dispatches directly. Otherwise it falls - back to the existing http-proxy-middleware path used by Docker/standalone - builds. +1. `packages/api/src/serverless.ts` exposes the Express app from `api-app.ts` as + a stateless `(req, res) => Promise` handler. It lazily connects to + MongoDB on the first invocation and caches the connection across warm + invocations. +2. `packages/app/pages/api/[...all].ts` branches on the `HDX_PREVIEW_INLINE_API` + env var. When `true`, it `require()`s the compiled serverless handler and + dispatches directly. Otherwise it falls back to the existing + http-proxy-middleware path used by Docker/standalone builds. 3. `packages/app/next.config.mjs` adds a webpack `externals` rule that marks - `@hyperdx/api` as a CommonJS external **unless** `HDX_PREVIEW_INLINE_API` - is `true`. This keeps production app builds (Docker fullstack image, - standalone Next output) byte-for-byte equivalent to before — they never - bundle passport-saml, mongoose, AWS SDK, etc. + `@hyperdx/api` as a CommonJS external **unless** `HDX_PREVIEW_INLINE_API` is + `true`. This keeps production app builds (Docker fullstack image, standalone + Next output) byte-for-byte equivalent to before — they never bundle + passport-saml, mongoose, AWS SDK, etc. 4. `vercel.json` declares the repo-root build commands so Vercel builds `common-utils` → `api` → `app` in order. ### Required Vercel project env vars (Preview scope only) -| Key | Notes | -|---|---| -| `HDX_PREVIEW_INLINE_API` | `true` — turns on the inline path | -| `MONGO_URI` | Preview MongoDB connection string | -| `EXPRESS_SESSION_SECRET` | Random 32+ char string | -| `DISABLED_AUTH_METHODS` | `google,saml` (avoids per-preview OAuth callback URL config) | -| `AI_PROVIDER`, `AI_API_KEY`, `AI_MODEL_NAME` | Optional, only if AI features should work | -| `FRONTEND_URL` | Optional. Leave unset to use host-only cookies on the preview URL | +| Key | Notes | +| -------------------------------------------- | ----------------------------------------------------------------- | +| `HDX_PREVIEW_INLINE_API` | `true` — turns on the inline path | +| `MONGO_URI` | Preview MongoDB connection string | +| `EXPRESS_SESSION_SECRET` | Random 32+ char string | +| `DISABLED_AUTH_METHODS` | `google,saml` (avoids per-preview OAuth callback URL config) | +| `AI_PROVIDER`, `AI_API_KEY`, `AI_MODEL_NAME` | Optional, only if AI features should work | +| `FRONTEND_URL` | Optional. Leave unset to use host-only cookies on the preview URL | Production env vars on the same project must leave `HDX_PREVIEW_INLINE_API` unset (or `false`) so production deployments keep using the proxy path. ### Limitations -- **No background tasks.** Scheduled jobs (`packages/api/src/tasks/`, - including `CheckAlertTask`) are not run in preview deployments. +- **No background tasks.** Scheduled jobs (`packages/api/src/tasks/`, including + `CheckAlertTask`) are not run in preview deployments. - **No alerts.** Alert evaluation depends on the cron task runner. -- **No OPAMP server.** The OPAMP control-plane server (`APP_TYPE=opamp`) is - not started in preview. The serverless entrypoint asserts - `APP_TYPE=api` and refuses to boot otherwise. +- **No OPAMP server.** The OPAMP control-plane server (`APP_TYPE=opamp`) is not + started in preview. The serverless entrypoint asserts `APP_TYPE=api` and + refuses to boot otherwise. - **Function size.** The bundled function should stay under Vercel's 50 MB unzipped limit. If it grows, mark heavy deps (`@aws-sdk/*`, `@node-saml/passport-saml`, AI SDKs) as `serverExternalPackages` in `next.config.mjs`. -- **Cold-start latency.** First request after idle pays ~500–1500 ms for - the initial Mongo connection. -- **Shared preview MongoDB.** Unless you partition by database name, all - preview deployments share the same Mongo state. +- **Cold-start latency.** First request after idle pays ~500–1500 ms for the + initial Mongo connection. +- **Shared preview MongoDB.** Unless you partition by database name, all preview + deployments share the same Mongo state. diff --git a/knip.json b/knip.json index 09cb2158e4..7d88c3d288 100644 --- a/knip.json +++ b/knip.json @@ -1,6 +1,9 @@ { "$schema": "https://unpkg.com/knip@6/schema.json", "workspaces": { + ".": { + "entry": ["scripts/__tests__/*.test.mjs"] + }, "packages/app": { "entry": ["pages/**/*.{ts,tsx}", "scripts/*.js", "tests/e2e/**/*.ts"], "project": ["src/**/*.{ts,tsx}", "pages/**/*.{ts,tsx}"], diff --git a/packages/api/package.json b/packages/api/package.json index a6a178de40..08915188b3 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -113,7 +113,7 @@ "dev:migrate-ch-create": "migrate create -ext sql -dir ./migrations/ch -seq", "dev:migrate-ch": "migrate -database 'clickhouse://localhost:9000?database=default&x-multi-statement=true' -path ./migrations/ch up", "docgen": "ts-node scripts/generate-api-docs.ts", - "seed:alerts": "ts-node --transpile-only -r tsconfig-paths/register scripts/seed-alerts.ts", + "seed:alerts": "../../scripts/with-slots.sh ts-node --transpile-only -r tsconfig-paths/register scripts/seed-alerts.ts", "lint:openapi": "yarn docgen && spectral lint openapi.json" } } diff --git a/packages/api/scripts/seed-alerts.ts b/packages/api/scripts/seed-alerts.ts index 2f257f061b..28220ab4ea 100644 --- a/packages/api/scripts/seed-alerts.ts +++ b/packages/api/scripts/seed-alerts.ts @@ -10,16 +10,14 @@ * yarn seed:alerts --count 2000 * yarn seed:alerts --purge * - * The Mongo URI defaults to the dev slot of the current git worktree, derived - * the same way scripts/dev-env.sh derives it. Override with --mongo-uri or - * MONGO_URI. The dev stack must be up (`yarn dev`) and registered once, since + * The Mongo URI defaults to the dev slot of the current git worktree, from + * scripts/slots.sh. Override with --mongo-uri, MONGO_URI, or HDX_DEV_SLOT. + * The dev stack must be up (`yarn dev`) and registered once, since * the script attaches everything to the existing team and log source. */ import { formatTileAlertDisplayName } from '@hyperdx/common-utils/dist/alerts'; import { DisplayType } from '@hyperdx/common-utils/dist/types'; -import { execFileSync } from 'child_process'; import mongoose from 'mongoose'; -import path from 'path'; import Alert, { AlertSource, AlertState } from '@/models/alert'; import Dashboard from '@/models/dashboard'; @@ -122,24 +120,17 @@ function parseArgs(argv: string[]): Args { } /** - * Mongo URI of the dev slot for the worktree this script lives in, matching - * the slot derivation in scripts/dev-env.sh (cksum of the directory name). + * Mongo URI of this worktree's dev stack. `yarn seed:alerts` runs through + * scripts/with-slots.sh, which sets HDX_DEV_MONGO_PORT. */ function devSlotMongoUri(): string { - const repoRoot = execFileSync('git', ['rev-parse', '--show-toplevel'], { - encoding: 'utf8', - }).trim(); - const slot = - process.env.HDX_DEV_SLOT ?? - execFileSync( - 'sh', - ['-c', `printf '%s' "$DIR" | cksum | awk '{print $1 % 100}'`], - { - encoding: 'utf8', - env: { ...process.env, DIR: path.basename(repoRoot) }, - }, - ).trim(); - return `mongodb://localhost:${30400 + Number(slot)}/hyperdx`; + const port = process.env.HDX_DEV_MONGO_PORT; + if (!port) { + throw new Error( + 'HDX_DEV_MONGO_PORT is not set. Run this with `yarn seed:alerts`, or pass --mongo-uri.', + ); + } + return `mongodb://localhost:${port}/hyperdx`; } function randomInt(minInclusive: number, maxInclusive: number): number { diff --git a/packages/hdx-eval/scripts/env.sh b/packages/hdx-eval/scripts/env.sh index a30d58c915..76ae970141 100755 --- a/packages/hdx-eval/scripts/env.sh +++ b/packages/hdx-eval/scripts/env.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Set up the full environment for hdx-eval, then exec the remaining args. # -# 1. Source dev-env.sh from the monorepo root for slot-based port vars +# 1. Set the dev stack's slot-based port vars from scripts/slots.sh # 2. Wrap the command with dotenvx to load .env / .env.local # # Usage: @@ -9,10 +9,9 @@ REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)" # Slot-based port env vars (HYPERDX_API_PORT, HDX_DEV_CH_HTTP_PORT, etc.) -_HDX_EVAL_CWD="$PWD" -cd "$REPO_ROOT" && source ./scripts/dev-env.sh > /dev/null 2>&1 -cd "$_HDX_EVAL_CWD" -unset _HDX_EVAL_CWD +# shellcheck source=../../../scripts/slots.sh +. "$REPO_ROOT/scripts/slots.sh" +hdx_dev_ports "$REPO_ROOT" # Load .env.local from the monorepo root (existing vars take precedence) exec "$REPO_ROOT/node_modules/.bin/dotenvx" run \ diff --git a/scripts/__tests__/slots.test.mjs b/scripts/__tests__/slots.test.mjs new file mode 100644 index 0000000000..91fd510b97 --- /dev/null +++ b/scripts/__tests__/slots.test.mjs @@ -0,0 +1,218 @@ +import assert from 'node:assert/strict'; +import { execFileSync, spawnSync } from 'node:child_process'; +import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; +import { after, test } from 'node:test'; + +const REPO = path.resolve(import.meta.dirname, '..', '..'); +const SLOTS = path.join(REPO, 'scripts', 'slots.sh'); +const WITH_SLOTS = path.join(REPO, 'scripts', 'with-slots.sh'); + +const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'hdx-slots-')); +after(() => fs.rmSync(tmp, { recursive: true, force: true })); + +/** A throwaway git worktree whose folder name picks the slot. */ +function worktree(name) { + const dir = path.join(tmp, name); + fs.mkdirSync(path.join(dir, 'packages', 'api'), { recursive: true }); + execFileSync('git', ['init', '-q', dir]); + return dir; +} + +// No inherited HDX_* variables, so a developer's shell can't leak into results. +const cleanEnv = (extra = {}) => ({ + PATH: process.env.PATH, + HOME: path.join(tmp, 'home'), + ...extra, +}); + +const pick = output => + Object.fromEntries( + output + .trim() + .split('\n') + .filter(line => /^(HDX_|HYPERDX_|E2E_PROJECT=)/.test(line)) + .map(line => line.split('=')), + ); + +/** Variables exported by `. slots.sh && [dir]`, run from `cwd`. */ +function ports(fn, { cwd, dir, env } = {}) { + const script = `. "$0" && ${fn} ${dir == null ? '' : '"$1"'} && env`; + return pick( + execFileSync('sh', ['-c', script, SLOTS, ...(dir == null ? [] : [dir])], { + cwd, + env: cleanEnv(env), + encoding: 'utf8', + }), + ); +} + +const hyperdxEe = worktree('hyperdx-ee'); + +test('exports the dev stack ports', () => { + assert.deepEqual(ports('hdx_dev_ports', { cwd: hyperdxEe }), { + HDX_DEV_SLOT: '44', + HYPERDX_API_PORT: '30144', + HYPERDX_APP_PORT: '30244', + HYPERDX_OPAMP_PORT: '30344', + HDX_DEV_MONGO_PORT: '30444', + HDX_DEV_CH_HTTP_PORT: '30544', + HDX_DEV_CH_NATIVE_PORT: '30644', + HDX_DEV_OTEL_HEALTH_PORT: '30744', + HDX_DEV_OTEL_GRPC_PORT: '30844', + HDX_DEV_OTEL_HTTP_PORT: '30944', + HDX_DEV_OTEL_METRICS_PORT: '31044', + HDX_DEV_OTEL_JSON_HTTP_PORT: '31144', + HDX_DEV_PROJECT: 'hdx-dev-44', + }); +}); + +test('exports the integration test ports', () => { + assert.deepEqual(ports('hdx_ci_ports', { cwd: hyperdxEe }), { + HDX_CI_SLOT: '44', + HDX_CI_CH_PORT: '18167', + HDX_CI_MONGO_PORT: '40043', + HDX_CI_API_PORT: '19044', + HDX_CI_OPAMP_PORT: '14364', + HDX_CI_PROJECT: 'int-44', + }); +}); + +test('exports the E2E test ports', () => { + assert.deepEqual(ports('hdx_e2e_ports', { cwd: hyperdxEe }), { + HDX_E2E_SLOT: '44', + HDX_E2E_OPAMP_PORT: '20364', + HDX_E2E_CH_PORT: '20544', + HDX_E2E_CH_NATIVE_PORT: '20644', + HDX_E2E_API_PORT: '21044', + HDX_E2E_MONGO_PORT: '21144', + HDX_E2E_APP_LOCAL_PORT: '21244', + HDX_E2E_APP_PORT: '21344', + HDX_E2E_REPORT_PORT: '9367', + E2E_PROJECT: 'e2e-44', + }); +}); + +test('derives the slot from the worktree folder name', () => { + const hyperdx = worktree('hyperdx'); + assert.equal(ports('hdx_dev_ports', { cwd: hyperdx }).HDX_DEV_SLOT, '96'); +}); + +test('gives the same slot from a subdirectory or a directory argument', () => { + const subdir = path.join(hyperdxEe, 'packages', 'api'); + assert.equal(ports('hdx_dev_ports', { cwd: subdir }).HDX_DEV_SLOT, '44'); + assert.equal( + ports('hdx_dev_ports', { cwd: tmp, dir: subdir }).HDX_DEV_SLOT, + '44', + ); +}); + +test('HDX_SLOT_FROM=path gives same-named worktrees their own slots', () => { + const slotOf = s => + Number( + execFileSync('cksum', { input: s, encoding: 'utf8' }).split(' ')[0], + ) % 100; + for (const name of ['a/hyperdx', 'b/hyperdx']) { + const dir = worktree(name); + const subdir = path.join(dir, 'packages', 'api'); + const env = { HDX_SLOT_FROM: 'path' }; + assert.equal(ports('hdx_dev_ports', { cwd: dir }).HDX_DEV_SLOT, '96'); + assert.equal( + ports('hdx_dev_ports', { cwd: subdir, env }).HDX_DEV_SLOT, + String(slotOf(fs.realpathSync(dir))), + ); + } +}); + +test('warns about an unknown HDX_SLOT_FROM and uses the folder name', () => { + const result = spawnSync( + 'sh', + ['-c', '. "$0" && hdx_dev_ports && printf %s "$HDX_DEV_SLOT"', SLOTS], + { + cwd: hyperdxEe, + env: cleanEnv({ HDX_SLOT_FROM: 'paths' }), + encoding: 'utf8', + }, + ); + assert.equal(result.stdout, '44'); + assert.match(result.stderr, /HDX_SLOT_FROM must be 'name' or 'path'/); +}); + +test('overrides each slot independently', () => { + const env = { HDX_DEV_SLOT: '5', HDX_E2E_SLOT: '7' }; + const dev = ports('hdx_dev_ports', { cwd: hyperdxEe, env }); + assert.equal(dev.HYPERDX_API_PORT, '30105'); + assert.equal(dev.HDX_DEV_PROJECT, 'hdx-dev-5'); + assert.equal( + ports('hdx_e2e_ports', { cwd: hyperdxEe, env }).E2E_PROJECT, + 'e2e-7', + ); + assert.equal( + ports('hdx_ci_ports', { cwd: hyperdxEe, env }).HDX_CI_SLOT, + '44', + ); +}); + +test('keeps E2E ports that are already set, as CI pins them', () => { + const e2e = ports('hdx_e2e_ports', { + cwd: hyperdxEe, + env: { HDX_E2E_API_PORT: '21000' }, + }); + assert.equal(e2e.HDX_E2E_API_PORT, '21000'); + assert.equal(e2e.HDX_E2E_APP_PORT, '21344'); +}); + +test('writes, deletes, and prints nothing', () => { + const home = path.join(tmp, 'home'); + fs.mkdirSync(home, { recursive: true }); + const snapshot = () => + [home, hyperdxEe].map(dir => fs.readdirSync(dir, { recursive: true })); + const before = snapshot(); + const output = execFileSync( + 'sh', + ['-c', '. "$0" && hdx_dev_ports && hdx_ci_ports && hdx_e2e_ports', SLOTS], + { cwd: hyperdxEe, env: cleanEnv(), encoding: 'utf8', stdio: 'pipe' }, + ); + assert.equal(output, ''); + assert.deepEqual(snapshot(), before); +}); + +test('with-slots.sh runs a command with the dev ports of its own worktree', () => { + const expected = ports('hdx_dev_ports', { cwd: REPO }); + // Run from outside the repo: the slot must come from the script's location. + const output = execFileSync(WITH_SLOTS, ['env'], { + cwd: tmp, + env: cleanEnv(), + encoding: 'utf8', + }); + const actual = pick(output); + assert.equal(actual.HDX_DEV_CH_HTTP_PORT, expected.HDX_DEV_CH_HTTP_PORT); + assert.equal(actual.HDX_DEV_SLOT, expected.HDX_DEV_SLOT); +}); + +test('no other code derives a slot', () => { + // The slot formula is `cksum` of the folder name; slots.sh must be the only + // copy so the dev stack, tests, and tools can never disagree. + const files = execFileSync( + 'git', + [ + 'grep', + '--untracked', + '-lw', + 'cksum', + '--', + '*.sh', + '*.js', + '*.mjs', + '*.ts', + 'Makefile', + '*.yml', + ':!scripts/__tests__/slots.test.mjs', + ], + { cwd: REPO, encoding: 'utf8' }, + ) + .trim() + .split('\n'); + assert.deepEqual(files, ['scripts/slots.sh']); +}); diff --git a/scripts/dev-env.sh b/scripts/dev-env.sh index 938aaeb4d7..9ef34ae14b 100755 --- a/scripts/dev-env.sh +++ b/scripts/dev-env.sh @@ -1,10 +1,13 @@ #!/usr/bin/env bash # --------------------------------------------------------------------------- -# Dev environment isolation helper +# Dev stack setup for `yarn dev` # --------------------------------------------------------------------------- -# Computes a deterministic port offset (HDX_DEV_SLOT, 0-99) from the current -# working directory name so that multiple git worktrees can run the full dev -# stack in parallel without port conflicts. +# Sets this worktree's slot and ports (see scripts/slots.sh for the scheme), +# then prepares its dev stack: clears stale Next.js output, registers the slot +# with the dev portal, and archives its logs on exit. +# +# Only source this when starting or stopping the stack. Tools that just need +# the ports should use scripts/with-slots.sh, which has no side effects. # # Usage: # source scripts/dev-env.sh # export env vars into current shell @@ -12,75 +15,24 @@ # # Override the slot manually: # HDX_DEV_SLOT=5 . scripts/dev-env.sh -# -# Port allocation scheme — each service gets a 100-wide band in the 30100-31199 -# range, well clear of: -# - CI integration test ports (14320-14419, 18123-18222, 19000-19099, 39999-40098) -# - E2E test ports (20320-21399) -# - Default dev ports (4317-4320, 8000, 8080, 8123, 8888, 9000, 13133, 14318, 27017) -# - OS ephemeral ports (32768+ Linux, 49152+ macOS) -# -# Port mapping (base + slot): -# API server : 30100 + slot (HYPERDX_API_PORT) -# App (Next.js) : 30200 + slot (HYPERDX_APP_PORT) -# OpAMP : 30300 + slot (HYPERDX_OPAMP_PORT) -# MongoDB : 30400 + slot (HDX_DEV_MONGO_PORT) -# ClickHouse HTTP : 30500 + slot (HDX_DEV_CH_HTTP_PORT) -# ClickHouse Native : 30600 + slot (HDX_DEV_CH_NATIVE_PORT) -# OTel health : 30700 + slot (HDX_DEV_OTEL_HEALTH_PORT) -# OTel gRPC : 30800 + slot (HDX_DEV_OTEL_GRPC_PORT) -# OTel HTTP : 30900 + slot (HDX_DEV_OTEL_HTTP_PORT) -# OTel metrics : 31000 + slot (HDX_DEV_OTEL_METRICS_PORT) -# OTel JSON HTTP : 31100 + slot (HDX_DEV_OTEL_JSON_HTTP_PORT) # --------------------------------------------------------------------------- -# Compute slot from directory name (same algorithm as CI slot in Makefile) -HDX_DEV_SLOT="${HDX_DEV_SLOT:-$(printf '%s' "$(basename "$PWD")" | cksum | awk '{print $1 % 100}')}" +# shellcheck source=./slots.sh +. "${BASH_SOURCE[0]%/*}/slots.sh" +hdx_dev_ports # Git metadata for portal labels HDX_DEV_BRANCH="$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo 'unknown')" HDX_DEV_WORKTREE="$(basename "$PWD")" -# --- Application ports (30100-30399) --- -HYPERDX_API_PORT=$((30100 + HDX_DEV_SLOT)) -HYPERDX_APP_PORT=$((30200 + HDX_DEV_SLOT)) -HYPERDX_OPAMP_PORT=$((30300 + HDX_DEV_SLOT)) - -# --- Docker service ports (30400-31199) --- -HDX_DEV_MONGO_PORT=$((30400 + HDX_DEV_SLOT)) -HDX_DEV_CH_HTTP_PORT=$((30500 + HDX_DEV_SLOT)) -HDX_DEV_CH_NATIVE_PORT=$((30600 + HDX_DEV_SLOT)) -HDX_DEV_OTEL_HEALTH_PORT=$((30700 + HDX_DEV_SLOT)) -HDX_DEV_OTEL_GRPC_PORT=$((30800 + HDX_DEV_SLOT)) -HDX_DEV_OTEL_HTTP_PORT=$((30900 + HDX_DEV_SLOT)) -HDX_DEV_OTEL_METRICS_PORT=$((31000 + HDX_DEV_SLOT)) -HDX_DEV_OTEL_JSON_HTTP_PORT=$((31100 + HDX_DEV_SLOT)) - -# --- Docker Compose project name (unique per slot) --- -HDX_DEV_PROJECT="hdx-dev-${HDX_DEV_SLOT}" - # --- Shared NX build cache across all worktrees --- # NX cache is content-hash based so changed files get cache misses (correct # behavior). Unchanged packages reuse cached output regardless of worktree. NX_CACHE_DIRECTORY="${HOME}/.config/hyperdx/nx-cache" mkdir -p "$NX_CACHE_DIRECTORY" -# Export everything -export HDX_DEV_SLOT export HDX_DEV_BRANCH export HDX_DEV_WORKTREE -export HYPERDX_API_PORT -export HYPERDX_APP_PORT -export HYPERDX_OPAMP_PORT -export HDX_DEV_MONGO_PORT -export HDX_DEV_CH_HTTP_PORT -export HDX_DEV_CH_NATIVE_PORT -export HDX_DEV_OTEL_HEALTH_PORT -export HDX_DEV_OTEL_GRPC_PORT -export HDX_DEV_OTEL_HTTP_PORT -export HDX_DEV_OTEL_METRICS_PORT -export HDX_DEV_OTEL_JSON_HTTP_PORT -export HDX_DEV_PROJECT export NX_CACHE_DIRECTORY # --- Clean up stale Next.js state from previous sessions --- diff --git a/scripts/dev-portal/server.js b/scripts/dev-portal/server.js index add1ea4f51..37fc6a35d5 100755 --- a/scripts/dev-portal/server.js +++ b/scripts/dev-portal/server.js @@ -18,7 +18,7 @@ // --------------------------------------------------------------------------- const http = require('node:http'); -const { execSync, spawn } = require('node:child_process'); +const { execFileSync, execSync, spawn } = require('node:child_process'); const fs = require('node:fs'); const path = require('node:path'); const net = require('node:net'); @@ -697,10 +697,18 @@ function discoverHistory() { // valid fallback (only for the slot that matches this worktree). let localSlot = null; try { - const cwd = process.cwd(); - const base = path.basename(cwd); - const cksum = [...base].reduce((s, c) => s + c.charCodeAt(0), 0); - localSlot = cksum % 100; + localSlot = Number( + execFileSync( + 'sh', + [ + '-c', + '. "$0" && hdx_dev_ports "$1" && printf %s "$HDX_DEV_SLOT"', + path.join(__dirname, '..', 'slots.sh'), + process.cwd(), + ], + { encoding: 'utf8' }, + ), + ); } catch { // ignore } diff --git a/scripts/slots.sh b/scripts/slots.sh new file mode 100755 index 0000000000..62b2ea5ab9 --- /dev/null +++ b/scripts/slots.sh @@ -0,0 +1,102 @@ +#!/bin/sh +# --------------------------------------------------------------------------- +# Slot and port allocation for worktree-isolated stacks +# --------------------------------------------------------------------------- +# The only place that turns a worktree into port numbers. dev-env.sh, +# test-e2e.sh, the Makefile, and tools run through with-slots.sh all use it, +# so they always agree. +# +# Sourcing this file only defines functions, and the functions only set and +# export variables. Nothing is written, deleted, started, or printed (apart +# from a warning on stderr for a bad HDX_SLOT_FROM), so it is safe to use while +# a dev stack is running. +# +# . scripts/slots.sh && hdx_dev_ports # dev stack (yarn dev) +# . scripts/slots.sh && hdx_ci_ports # integration tests (make dev-int) +# . scripts/slots.sh && hdx_e2e_ports # E2E tests (make e2e) +# +# Each function takes an optional directory inside the worktree (default: the +# current directory). +# +# The slot (0-99) is the cksum of the worktree's folder name, mod 100, and each +# service's port is its base plus the slot. Override the slot per stack with +# HDX_DEV_SLOT, HDX_CI_SLOT, or HDX_E2E_SLOT, e.g. `HDX_DEV_SLOT=5 yarn dev`. +# +# If your worktrees share a folder name (a/hyperdx, b/hyperdx), set +# HDX_SLOT_FROM=path, e.g. in your shell profile, to hash the worktree's full +# path instead. The default, HDX_SLOT_FROM=name, keeps existing slots and the +# .volumes/*_ data folders that go with them. +# +# The ranges stay clear of each other, of the default dev ports (4317-4320, +# 8000, 8080, 8123, 8888, 9000, 13133, 14318, 27017), and of the OS ephemeral +# range (32768+ on Linux, 49152+ on macOS). +# --------------------------------------------------------------------------- + +# Slot of the worktree containing $1 (default: the current directory). +_hdx_default_slot() { + _hdx_dir="${1:-.}" + _hdx_root="$(git -C "$_hdx_dir" rev-parse --show-toplevel 2>/dev/null || + (cd "$_hdx_dir" && pwd))" + case "${HDX_SLOT_FROM:-name}" in + path) _hdx_key="$(cd "$_hdx_root" && pwd -P)" ;; + name) _hdx_key="$(basename "$_hdx_root")" ;; + *) + echo "slots.sh: HDX_SLOT_FROM must be 'name' or 'path', got '$HDX_SLOT_FROM'; using 'name'" >&2 + _hdx_key="$(basename "$_hdx_root")" + ;; + esac + printf '%s' "$_hdx_key" | cksum | awk '{print $1 % 100}' +} + +# Dev stack (yarn dev): 30100-31199. +hdx_dev_ports() { + HDX_DEV_SLOT="${HDX_DEV_SLOT:-$(_hdx_default_slot "$1")}" + HYPERDX_API_PORT=$((30100 + HDX_DEV_SLOT)) + HYPERDX_APP_PORT=$((30200 + HDX_DEV_SLOT)) + HYPERDX_OPAMP_PORT=$((30300 + HDX_DEV_SLOT)) + HDX_DEV_MONGO_PORT=$((30400 + HDX_DEV_SLOT)) + HDX_DEV_CH_HTTP_PORT=$((30500 + HDX_DEV_SLOT)) + HDX_DEV_CH_NATIVE_PORT=$((30600 + HDX_DEV_SLOT)) + HDX_DEV_OTEL_HEALTH_PORT=$((30700 + HDX_DEV_SLOT)) + HDX_DEV_OTEL_GRPC_PORT=$((30800 + HDX_DEV_SLOT)) + HDX_DEV_OTEL_HTTP_PORT=$((30900 + HDX_DEV_SLOT)) + HDX_DEV_OTEL_METRICS_PORT=$((31000 + HDX_DEV_SLOT)) + HDX_DEV_OTEL_JSON_HTTP_PORT=$((31100 + HDX_DEV_SLOT)) + HDX_DEV_PROJECT="hdx-dev-${HDX_DEV_SLOT}" + export HDX_DEV_SLOT HYPERDX_API_PORT HYPERDX_APP_PORT HYPERDX_OPAMP_PORT \ + HDX_DEV_MONGO_PORT HDX_DEV_CH_HTTP_PORT HDX_DEV_CH_NATIVE_PORT \ + HDX_DEV_OTEL_HEALTH_PORT HDX_DEV_OTEL_GRPC_PORT HDX_DEV_OTEL_HTTP_PORT \ + HDX_DEV_OTEL_METRICS_PORT HDX_DEV_OTEL_JSON_HTTP_PORT HDX_DEV_PROJECT +} + +# Integration tests (make dev-int): ClickHouse 18123+, MongoDB 39999+, +# API 19000+, OpAMP 14320+. +hdx_ci_ports() { + HDX_CI_SLOT="${HDX_CI_SLOT:-$(_hdx_default_slot "$1")}" + HDX_CI_CH_PORT=$((18123 + HDX_CI_SLOT)) + HDX_CI_MONGO_PORT=$((39999 + HDX_CI_SLOT)) + HDX_CI_API_PORT=$((19000 + HDX_CI_SLOT)) + HDX_CI_OPAMP_PORT=$((14320 + HDX_CI_SLOT)) + HDX_CI_PROJECT="int-${HDX_CI_SLOT}" + export HDX_CI_SLOT HDX_CI_CH_PORT HDX_CI_MONGO_PORT HDX_CI_API_PORT \ + HDX_CI_OPAMP_PORT HDX_CI_PROJECT +} + +# E2E tests (make e2e): 20320-21399, plus the Playwright report server at +# 9323+. Ports that are already set are kept, because CI pins them in +# .github/actions/e2e-setup. +hdx_e2e_ports() { + HDX_E2E_SLOT="${HDX_E2E_SLOT:-$(_hdx_default_slot "$1")}" + HDX_E2E_OPAMP_PORT="${HDX_E2E_OPAMP_PORT:-$((20320 + HDX_E2E_SLOT))}" + HDX_E2E_CH_PORT="${HDX_E2E_CH_PORT:-$((20500 + HDX_E2E_SLOT))}" + HDX_E2E_CH_NATIVE_PORT="${HDX_E2E_CH_NATIVE_PORT:-$((20600 + HDX_E2E_SLOT))}" + HDX_E2E_API_PORT="${HDX_E2E_API_PORT:-$((21000 + HDX_E2E_SLOT))}" + HDX_E2E_MONGO_PORT="${HDX_E2E_MONGO_PORT:-$((21100 + HDX_E2E_SLOT))}" + HDX_E2E_APP_LOCAL_PORT="${HDX_E2E_APP_LOCAL_PORT:-$((21200 + HDX_E2E_SLOT))}" + HDX_E2E_APP_PORT="${HDX_E2E_APP_PORT:-$((21300 + HDX_E2E_SLOT))}" + HDX_E2E_REPORT_PORT=$((9323 + HDX_E2E_SLOT)) + E2E_PROJECT="e2e-${HDX_E2E_SLOT}" + export HDX_E2E_SLOT HDX_E2E_OPAMP_PORT HDX_E2E_CH_PORT \ + HDX_E2E_CH_NATIVE_PORT HDX_E2E_API_PORT HDX_E2E_MONGO_PORT \ + HDX_E2E_APP_LOCAL_PORT HDX_E2E_APP_PORT HDX_E2E_REPORT_PORT E2E_PROJECT +} diff --git a/scripts/test-e2e.sh b/scripts/test-e2e.sh index 0d30b16a23..7b6e060d66 100755 --- a/scripts/test-e2e.sh +++ b/scripts/test-e2e.sh @@ -30,35 +30,13 @@ DOCKER_COMPOSE_FILE="$REPO_ROOT/packages/app/tests/e2e/docker-compose.yml" # --------------------------------------------------------------------------- # Multi-agent / worktree isolation # --------------------------------------------------------------------------- -# Compute a deterministic port offset (0-99) from the working directory name -# so that multiple worktrees can run E2E tests in parallel without port -# conflicts. Override HDX_E2E_SLOT manually if you need a specific slot. -# -# Port allocation — E2E gets its own range (20320-21399) so it can run -# simultaneously with CI integration tests (14320-40098) and the dev -# stack (30100-31199). All ports are below the OS ephemeral range -# (32768 Linux, 49152 macOS). -# -# Port mapping (base + slot): -# OpAMP : 20320 + slot (20320-20419) -# ClickHouse HTTP : 20500 + slot (20500-20599) -# ClickHouse Native: 20600 + slot (20600-20699) -# API server : 21000 + slot (21000-21099) -# MongoDB : 21100 + slot (21100-21199) -# App (local) : 21200 + slot (21200-21299) -# App (fullstack) : 21300 + slot (21300-21399) +# E2E gets its own slot and port range so worktrees can run E2E tests in +# parallel with each other, the dev stack, and integration tests. See +# scripts/slots.sh for the ports. Override with HDX_E2E_SLOT. # --------------------------------------------------------------------------- -export HDX_E2E_SLOT="${HDX_E2E_SLOT:-$(printf '%s' "$(basename "$REPO_ROOT")" | cksum | awk '{print $1 % 100}')}" - -export HDX_E2E_OPAMP_PORT="${HDX_E2E_OPAMP_PORT:-$((20320 + HDX_E2E_SLOT))}" -export HDX_E2E_CH_PORT="${HDX_E2E_CH_PORT:-$((20500 + HDX_E2E_SLOT))}" -export HDX_E2E_CH_NATIVE_PORT="${HDX_E2E_CH_NATIVE_PORT:-$((20600 + HDX_E2E_SLOT))}" -export HDX_E2E_API_PORT="${HDX_E2E_API_PORT:-$((21000 + HDX_E2E_SLOT))}" -export HDX_E2E_MONGO_PORT="${HDX_E2E_MONGO_PORT:-$((21100 + HDX_E2E_SLOT))}" -export HDX_E2E_APP_LOCAL_PORT="${HDX_E2E_APP_LOCAL_PORT:-$((21200 + HDX_E2E_SLOT))}" -export HDX_E2E_APP_PORT="${HDX_E2E_APP_PORT:-$((21300 + HDX_E2E_SLOT))}" - -export E2E_PROJECT="e2e-${HDX_E2E_SLOT}" +# shellcheck source=./slots.sh +. "$SCRIPT_DIR/slots.sh" +hdx_e2e_ports "$REPO_ROOT" # Prevent Playwright's html reporter from spawning a blocking server on port # 9323 ("Serving HTML report... Press Ctrl+C to quit.") after a failed/flaky diff --git a/scripts/with-slots.sh b/scripts/with-slots.sh new file mode 100755 index 0000000000..7d7fa7a008 --- /dev/null +++ b/scripts/with-slots.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# Runs a command with this worktree's dev stack ports set (HDX_DEV_SLOT, +# HDX_DEV_CH_HTTP_PORT, HYPERDX_API_PORT, ...; see slots.sh), for tools that +# talk to a running `yarn dev` stack. Works from any directory. +# +# scripts/with-slots.sh ts-node scripts/seed-alerts.ts +# HDX_DEV_SLOT=5 scripts/with-slots.sh ... # target another slot +set -e +_hdx_scripts="$(dirname "$0")" +. "$_hdx_scripts/slots.sh" +hdx_dev_ports "$_hdx_scripts" +exec "$@" From 3c2f122f6597a84b023d660c6fe93b49b75d5f61 Mon Sep 17 00:00:00 2001 From: Karl Power Date: Wed, 30 Sep 2026 15:21:51 +0200 Subject: [PATCH 2/2] refactor(scripts): address review feedback on slot helpers - Makefile: compute the integration test slot and ports in one shell instead of six. The block runs on every make invocation; an empty target drops from ~190ms to ~78ms. - slots.test.mjs: scan tracked files only, so a local scratch file that mentions cksum no longer fails `make ci-unit`. --- Makefile | 19 ++++++++++--------- scripts/__tests__/slots.test.mjs | 5 +++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 13d2e087d2..91896878ea 100644 --- a/Makefile +++ b/Makefile @@ -10,15 +10,16 @@ include .env # parallel. scripts/slots.sh computes them; override the slot with # `make dev-int HDX_CI_SLOT=5`. # --------------------------------------------------------------------------- -# Value of one variable exported by hdx_ci_ports in scripts/slots.sh. -ci_slots = $(shell HDX_CI_SLOT='$(HDX_CI_SLOT)' sh -c '. ./scripts/slots.sh && hdx_ci_ports && printf %s "$$$(1)"') - -HDX_CI_SLOT := $(call ci_slots,HDX_CI_SLOT) -HDX_CI_PROJECT := $(call ci_slots,HDX_CI_PROJECT) -HDX_CI_CH_PORT := $(call ci_slots,HDX_CI_CH_PORT) -HDX_CI_MONGO_PORT:= $(call ci_slots,HDX_CI_MONGO_PORT) -HDX_CI_API_PORT := $(call ci_slots,HDX_CI_API_PORT) -HDX_CI_OPAMP_PORT:= $(call ci_slots,HDX_CI_OPAMP_PORT) +# One shell for all six values: this runs on every make invocation, and each +# shell costs ~20ms. +_hdx_ci := $(shell HDX_CI_SLOT='$(HDX_CI_SLOT)' sh -c '. ./scripts/slots.sh && hdx_ci_ports && echo "$$HDX_CI_SLOT $$HDX_CI_PROJECT $$HDX_CI_CH_PORT $$HDX_CI_MONGO_PORT $$HDX_CI_API_PORT $$HDX_CI_OPAMP_PORT"') + +HDX_CI_SLOT := $(word 1,$(_hdx_ci)) +HDX_CI_PROJECT := $(word 2,$(_hdx_ci)) +HDX_CI_CH_PORT := $(word 3,$(_hdx_ci)) +HDX_CI_MONGO_PORT:= $(word 4,$(_hdx_ci)) +HDX_CI_API_PORT := $(word 5,$(_hdx_ci)) +HDX_CI_OPAMP_PORT:= $(word 6,$(_hdx_ci)) export HDX_CI_CH_PORT HDX_CI_MONGO_PORT HDX_CI_API_PORT HDX_CI_OPAMP_PORT diff --git a/scripts/__tests__/slots.test.mjs b/scripts/__tests__/slots.test.mjs index 91fd510b97..794bc7ff10 100644 --- a/scripts/__tests__/slots.test.mjs +++ b/scripts/__tests__/slots.test.mjs @@ -193,12 +193,13 @@ test('with-slots.sh runs a command with the dev ports of its own worktree', () = test('no other code derives a slot', () => { // The slot formula is `cksum` of the folder name; slots.sh must be the only - // copy so the dev stack, tests, and tools can never disagree. + // copy so the dev stack, tests, and tools can never disagree. Any tracked use + // of the word fails this; if a file needs `cksum` for something else, + // exclude it below. const files = execFileSync( 'git', [ 'grep', - '--untracked', '-lw', 'cksum', '--',