aboutsummaryrefslogtreecommitdiff
path: root/test/cdp
diff options
context:
space:
mode:
authorAman Kumar <145339995+amankumarsingh77@users.noreply.github.com>2026-10-11 23:33:25 +0530
committerGitHub <noreply@github.com>2026-10-11 23:33:25 +0530
commit0fe64593bcc3379032840b35833ea39f23aa9322 (patch)
treef01055f53a8a3d92a244b7fc7ecb0b88b6bf252b /test/cdp
parent7833e2ecd5dc5fd9d7e63322680711d341d885ee (diff)
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 <noreply@anthropic.com>
Diffstat (limited to 'test/cdp')
-rw-r--r--test/cdp/discovery-test.ts19
1 files changed, 18 insertions, 1 deletions
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);
+ });
+});