diff options
| author | Igor Soarez <igor@soarez.org> | 2026-10-15 07:07:58 +0100 |
|---|---|---|
| committer | Igor Soarez <igor@soarez.org> | 2026-10-15 07:07:58 +0100 |
| commit | 3e761274fe7b0e6be4a162e880293150ad9d9fbe (patch) | |
| tree | 89c448734eae908170d32f7f1e55e2defcb66d22 /test | |
| parent | 19c6f64c8561e286687e2b81a2e1e82fb21fd73b (diff) | |
feat(cdp): report a BU_CDP_WS pin in status, /browser-target and the prompt
Upstream 0.11.0 made BU_CDP_WS reach the daemon, and discoverEndpoint()
returns it before the fork's target is consulted. resolveCdpTarget() did
not know about it, so /browser-status and the system prompt named the
BU_CDP_HTTP/stored/default target while the daemon dialled the pinned URL,
and /browser-target claimed to switch browsers when it could not.
resolveCdpTarget() now puts BU_CDP_WS first, as a remote target with
source "ws". /browser-target warns that it takes precedence, as it already
did for BU_CDP_HTTP. Only host:port is ever shown: the path carries the
browser id and a proxied URL may carry a token. /browser-status does not
probe a pinned URL, since /json/version answering says nothing about
whether the pinned browser id is still current.
Diffstat (limited to 'test')
| -rw-r--r-- | test/cdp/endpoint-test.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/cdp/endpoint-test.ts b/test/cdp/endpoint-test.ts index 57d6088..ee8f692 100644 --- a/test/cdp/endpoint-test.ts +++ b/test/cdp/endpoint-test.ts @@ -13,8 +13,10 @@ import { DEFAULT_REMOTE_CDP, describeCdpTarget, isValidTargetValue, + redactWsUrl, resolveCdpTarget, } from "../../src/cdp/endpoint"; +import { getBrowserSystemPrompt } from "../../src/prompt"; let passed = 0; let failed = 0; @@ -150,6 +152,50 @@ function main(): void { check(!isValidTargetValue("default"), "E13: \"default\" is handled as clear, not stored verbatim"); } + // E14: upstream's BU_CDP_WS is read by discoverEndpoint() before anything the + // fork resolves, so it must outrank BU_CDP_HTTP and the stored choice here + // too — otherwise status, /browser-target and the prompt name a browser the + // daemon is not driving. + { + const pinned = "ws://10.0.0.7:9229/devtools/browser/0b5c-uuid"; + const t = resolveCdpTarget({ BU_CDP_WS: pinned, BU_CDP_HTTP: "10.0.0.9:9333" }, "10.0.0.8:9444"); + check(t.kind === "remote", "E14: BU_CDP_WS resolves to a remote target"); + if (t.kind === "remote") { + check(t.host === "10.0.0.7" && t.port === 9229, "E14: it wins over BU_CDP_HTTP and the stored choice"); + check(t.source === "ws", "E14: it is marked as the pinned WebSocket"); + } + const blank = resolveCdpTarget({ BU_CDP_WS: " ", BU_CDP_HTTP: "10.0.0.9:9333" }); + check(blank.kind === "remote" && blank.source === "env", "E14: a blank BU_CDP_WS is ignored, as upstream does"); + } + + // E15: only host:port is ever shown. The path carries the browser id and a + // proxied endpoint may carry a token or credentials. + { + const secret = "wss://user:hunter2@cdp.example.com/devtools/browser/abc?token=s3cr3t"; + const t = resolveCdpTarget({ BU_CDP_WS: secret }); + const shown = describeCdpTarget(t); + check(t.kind === "remote" && t.port === 443, "E15: wss without a port means 443"); + check(shown.startsWith("cdp.example.com:443 (BU_CDP_WS"), `E15: described as host:port — got ${shown}`); + check(!/hunter2|user|abc|token|s3cr3t|devtools/.test(shown), "E15: no path, query or credentials leak"); + check(redactWsUrl(secret) === "cdp.example.com:443", "E15: redactWsUrl keeps host:port only"); + check(redactWsUrl("ws://[::1]:9222/x") === "::1:9222", "E15: IPv6 hosts lose their brackets like elsewhere"); + } + + // E16: an unusable BU_CDP_WS is reported, still without echoing it. + for (const bad of ["not a url", "http://10.0.0.7:9229/devtools/browser/x"]) { + const t = resolveCdpTarget({ BU_CDP_WS: bad }); + check(t.kind === "invalid" && t.source === "ws", `E16: "${bad}" is reported as an invalid BU_CDP_WS`); + check(!describeCdpTarget(t).includes("devtools"), "E16: the invalid value is not echoed"); + } + + // E17: the system prompt names the pinned endpoint, redacted. + { + const t = resolveCdpTarget({ BU_CDP_WS: "ws://10.0.0.7:9229/devtools/browser/0b5c-uuid" }); + const prompt = getBrowserSystemPrompt(true, t); + check(prompt.includes("10.0.0.7:9229"), "E17: the prompt names the pinned host:port"); + check(!prompt.includes("0b5c-uuid"), "E17: the prompt does not carry the browser id"); + } + console.log(`\n${passed} passed, ${failed} failed`); if (failed > 0) process.exit(1); } |
