Skip to content

chore(e2e): automatic per-checkout port isolation — hash the checkout path, no setup required - #712

Merged
ivogt merged 1 commit into
mainfrom
chore/e2e-port-offset-auto
Jul 6, 2026
Merged

ivogt merged 1 commit into
mainfrom
chore/e2e-port-offset-auto

Conversation

@ivogt

@ivogt ivogt commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Problem

#711 added RANGO_E2E_PORT_OFFSET, but an opt-in knob has a bootstrapping flaw: the sessions that need port isolation are precisely the ones that don't know another clone is running e2e. Requiring prior knowledge means the default is still silently wrong in the multi-clone case — the exact case that burned #705's verification.

Change

The offset is now derived automatically from a hash of the checkout's absolute path. checkoutPortOffset() lives in @shared/e2e (both suites already depend on it) and resolves the path from its own file location — the workspace symlink resolves to the real per-clone path — so every importer in the same clone derives the identical value by construction:

  • packages/rangojs-router/playwright.config.ts (dev/preview + host ports)
  • packages/rangojs-router/e2e/host-routing.test.ts (builds absolute URLs — imports the same function, replacing the old keep-in-sync comment contract)
  • tests/cloudflare-basic/playwright.config.ts

Properties:

Concern Behavior
Same clone, repeated runs Same hash → same ports → reuseExistingServer still reuses your own servers
Two clones in parallel Disjoint port blocks, zero setup (all four local sibling clones hash to distinct offsets: 18200/25200/25600/25800)
Cross-suite spacing Offset applied uniformly, so the deliberate rangojs-vs-cloudflare-basic spacing holds at any offset
CI Pins offset 0 (one checkout per runner, canonical ports in logs)
Explicit control RANGO_E2E_PORT_OFFSET still overrides; 0 forces the canonical bases
Bounds 150 buckets × 200 stride → max port ~35297, clear of the OS ephemeral range
Residual hash collision ~1–2% for a handful of clones; degrades to today's pre-#711 status quo, and the override remains the escape hatch

AGENTS.md gotcha rewritten: read actual ports from playwright's webServer output; never hardcode ports in cleanup commands. Stale :5188-style comments in helper.ts/consumer-testing-harness.test.ts updated to name the base + offset.

Test plan

  • Derivation probed via node: this clone → 25800, stable across calls; override 0/400 honored; CI=1 → 0.
  • Router e2e (content-negotiation dev, 23 passed) binds 30988/30989; cloudflare-basic (cache-signal dev) binds 30999/30998 — same offset from both configs.
  • host-routing --project=host 5 passed against derived 31096/31097 — proves config/test-file port agreement live (the one spot the old design kept in sync by comment).
  • typecheck (17/17 incl. shared-e2e), test:unit:all (0 failures), lint, format.

Notes

  • The helper anchors on its own resolved path rather than process.cwd() (invocation-dependent) or per-file __dirname math (drifts on file moves).
  • Sibling clones get the behavior when they pull main; until then they keep fixed bases while this clone has already moved off them — collision-free in the interim either way.

… path, no setup required

Follow-up to #711: the env var only helps if a session already knows about
the multi-clone failure mode — the sessions that need isolation are exactly
the ones unaware of each other, so opt-in defends nothing by default.

checkoutPortOffset() in @shared/e2e hashes the checkout's absolute path
(resolved from the helper's own location through the workspace symlink) into
a 0..29800 offset (150 buckets x 200 stride). Every importer in the same
clone derives the identical value by construction: both playwright configs
and host-routing.test.ts (absolute URLs) import the one function, replacing
the keep-in-sync constants. Same clone, same ports across runs, so
reuseExistingServer still reuses your own servers; different clones get
disjoint blocks with zero setup. RANGO_E2E_PORT_OFFSET remains as explicit
override (0 forces the canonical bases); CI pins 0.

Verified: this clone derives 25800 — router e2e binds 30988/30989 (+host
31096/31097), cloudflare-basic binds 30999/30998 (same offset, cross-suite
spacing preserved); host-routing suite green against the derived ports
(config/test agreement); override 0/400 and CI=1 probed; all four local
sibling clones hash to distinct offsets (18200/25200/25600/25800).
@pkg-pr-new

pkg-pr-new Bot commented Jul 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@rangojs/router@712

commit: 1dc8bd7

@ivogt
ivogt merged commit 1b00414 into main Jul 6, 2026
34 checks passed
@ivogt
ivogt deleted the chore/e2e-port-offset-auto branch July 6, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant