From 0fe64593bcc3379032840b35833ea39f23aa9322 Mon Sep 17 00:00:00 2001 From: Aman Kumar <145339995+amankumarsingh77@users.noreply.github.com> Date: Sun, 11 Oct 2026 23:33:25 +0530 Subject: fix(daemon): stop importing typebox in the daemon process (#38) pi installs packages with dev and peer dependencies omitted and supplies typebox only to the extension host. The daemon is a separate Node process whose import graph reached typebox via src/cdp/discovery.ts, so from a pi-managed install it crashed with "Cannot find module 'typebox'" before binding its socket. Parse /json/version with the package's own guards, and add a test that keeps every package reachable from the daemon a runtime dependency. Fixes #34 Co-Authored-By: Claude Fable 5.1 --- test/cdp/discovery-test.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'test/cdp') diff --git a/test/cdp/discovery-test.ts b/test/cdp/discovery-test.ts index 7fc18fb..61b42b7 100644 --- a/test/cdp/discovery-test.ts +++ b/test/cdp/discovery-test.ts @@ -1,6 +1,6 @@ import { test, describe } from "node:test"; import assert from "node:assert/strict"; -import { endpointFromEnv } from "../../src/cdp/discovery"; +import { endpointFromEnv, parseVersionResponse } from "../../src/cdp/discovery"; describe("BU_CDP_WS endpoint override", () => { test("an unset variable leaves discovery to run normally", () => { @@ -27,3 +27,20 @@ describe("BU_CDP_WS endpoint override", () => { assert.equal(endpointFromEnv({ BU_CDP_WS: " " }), undefined); }); }); + +describe("/json/version parsing", () => { + test("extracts webSocketDebuggerUrl from a well-formed response", () => { + const raw = JSON.stringify({ Browser: "Chrome/154.0", webSocketDebuggerUrl: "ws://127.0.0.1:9222/devtools/browser/abc" }); + assert.equal(parseVersionResponse(raw), "ws://127.0.0.1:9222/devtools/browser/abc"); + }); + + test("a response without the url yields null", () => { + assert.equal(parseVersionResponse(JSON.stringify({ Browser: "Chrome/154.0" })), null); + }); + + test("a non-string url, a non-object body, and invalid JSON all yield null", () => { + assert.equal(parseVersionResponse(JSON.stringify({ webSocketDebuggerUrl: 42 })), null); + assert.equal(parseVersionResponse(JSON.stringify([1, 2])), null); + assert.equal(parseVersionResponse("not json"), null); + }); +}); -- cgit v1.2.3