fix(browser): fold loopback spellings into one attach admission key (#1604)

A CDP endpoint serves every loopback stack on one port, but the attach
admission key was built from the endpoint origin string, so scenarios
attaching through http://127.0.0.1:PORT and http://[::1]:PORT produced
two lease keys, passed admission in parallel and the browser rejected
the second client. Collapse literal loopback hostnames to one identity
in the lease key (port and target still partition it) without touching
endpoint validation.

Validation: npx vitest run src/browser/PlaywrightScenarioBrowser.test.ts (9 passed; the two new loopback tests failed before the fix), npx vitest run src/browser src/domain (1745 passed, 2 failed, both failing on pristine main), npm run test:fast (3896 passed, 12 failed, 7 skipped; the failure set is identical on pristine main at 3894 passed), plus typecheck, oxlint, oxfmt and resolved module-boundary verification.
This commit is contained in:
akushonkamen
2026-10-11 06:22:59 +08:00
committed by GitHub
parent 6edd5cf045
commit 3e931a7e35
2 changed files with 94 additions and 2 deletions
+9 -2
View File
@@ -11,6 +11,7 @@ import {
import type { BrowserScenario } from "../domain/browserScenario.js";
import { AnalysisError } from "../domain/analysisErrorBase.js";
import { isLiteralLoopbackHostname } from "../domain/browserObservation.js";
import { BrowserObservationError } from "../domain/browserObservationError.js";
import { withPlaywrightExecutionBoundary } from "./PlaywrightExecutionBoundary.js";
@@ -189,8 +190,14 @@ const createAttachedScenarioRelease = (
export const attachedScenarioLeaseKey = (
endpoint: string,
targetId: string,
): string =>
JSON.stringify([new URL("/json/version", endpoint).href, targetId]);
): string => {
const discovery = new URL("/json/version", endpoint);
// One CDP browser serves every loopback stack on one port, so spellings that
// reach it through 127.0.0.1 or ::1 must share a single admission.
if (isLiteralLoopbackHostname(discovery.hostname))
discovery.hostname = "127.0.0.1";
return JSON.stringify([discovery.href, targetId]);
};
const acquireAttachedScenario = (
scenario: Extract<BrowserScenario["browser"], { readonly mode: "connect" }>,