From 6d300099a86cfdb92b7869dc2b4f33094554b24c Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Tue, 28 Jul 2026 21:48:35 +0530 Subject: fix: make --browser-debug-clicks and BU_CDP_WS actually work MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both were documented and inert. --browser-debug-clicks was registered as a flag and never read; the only real switch was the undocumented BH_DEBUG_CLICKS env var. The flag now feeds util/debug.ts, which the click tool consults, and the env var keeps working as an equivalent. BU_CDP_WS was read in the client and handed to transport.connect(), but the daemon transport discards that argument and always dials the daemon socket — and the daemon's own discovery never looked at the variable, so setting it did nothing. The override now lives in discoverEndpoint, which is what both processes go through, and the client's redundant read is gone. The variable must be set before the daemon spawns. Co-Authored-By: Claude Opus 5 (1M context) --- test/cdp/discovery-test.ts | 29 +++++++++++++++++++++++++++++ test/util/debug-test.ts | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 test/cdp/discovery-test.ts create mode 100644 test/util/debug-test.ts (limited to 'test') diff --git a/test/cdp/discovery-test.ts b/test/cdp/discovery-test.ts new file mode 100644 index 0000000..7fc18fb --- /dev/null +++ b/test/cdp/discovery-test.ts @@ -0,0 +1,29 @@ +import { test, describe } from "node:test"; +import assert from "node:assert/strict"; +import { endpointFromEnv } from "../../src/cdp/discovery"; + +describe("BU_CDP_WS endpoint override", () => { + test("an unset variable leaves discovery to run normally", () => { + assert.equal(endpointFromEnv({}), undefined); + }); + + test("a set variable becomes the endpoint", () => { + const e = endpointFromEnv({ BU_CDP_WS: "ws://127.0.0.1:9333/devtools/browser/abc" }); + assert.equal(e?.wsUrl, "ws://127.0.0.1:9333/devtools/browser/abc"); + }); + + test("no userDataDir is claimed for a remote endpoint", () => { + const e = endpointFromEnv({ BU_CDP_WS: "ws://example.test/x" }); + assert.equal(e?.userDataDir, undefined); + }); + + test("surrounding whitespace is trimmed", () => { + const e = endpointFromEnv({ BU_CDP_WS: " ws://127.0.0.1:9222/x " }); + assert.equal(e?.wsUrl, "ws://127.0.0.1:9222/x"); + }); + + test("an empty or whitespace-only variable is ignored, not treated as an endpoint", () => { + assert.equal(endpointFromEnv({ BU_CDP_WS: "" }), undefined); + assert.equal(endpointFromEnv({ BU_CDP_WS: " " }), undefined); + }); +}); diff --git a/test/util/debug-test.ts b/test/util/debug-test.ts new file mode 100644 index 0000000..08236dd --- /dev/null +++ b/test/util/debug-test.ts @@ -0,0 +1,32 @@ +import { test, describe, afterEach } from "node:test"; +import assert from "node:assert/strict"; +import { debugClicksEnabled, setDebugClicks } from "../../src/util/debug"; + +describe("debug click overlay switch", () => { + afterEach(() => { + setDebugClicks(false); + }); + + test("off when neither the flag nor the env var is set", () => { + assert.equal(debugClicksEnabled({}), false); + }); + + test("the --browser-debug-clicks flag turns it on", () => { + setDebugClicks(true); + assert.equal(debugClicksEnabled({}), true); + }); + + test("BH_DEBUG_CLICKS still turns it on without the flag", () => { + assert.equal(debugClicksEnabled({ BH_DEBUG_CLICKS: "1" }), true); + }); + + test("an empty BH_DEBUG_CLICKS does not turn it on", () => { + assert.equal(debugClicksEnabled({ BH_DEBUG_CLICKS: "" }), false); + }); + + test("the flag can be turned back off", () => { + setDebugClicks(true); + setDebugClicks(false); + assert.equal(debugClicksEnabled({}), false); + }); +}); -- cgit v1.2.3