From 9f2ef1cf87251ce12f6b6432c48c6e7d2017b6b5 Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Mon, 27 Jul 2026 00:48:45 +0530 Subject: refactor(cdp): make session.call generic over the command table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit call/callOnTarget/callBrowser now take a known method and return its decoded result type. The session is where unknown ends; transport keeps returning unknown. Removes the casts in session.ts and target-factory.ts, including the session's own internal Target.*/Browser.* calls, which now decode through the same path as the public call methods. Also completes two params-schema gaps in commands.ts surfaced by this migration: Target.createTarget was missing openerId and Runtime.evaluate was missing userGesture, both real CDP fields src/cdp/ already sends. tsc is red project-wide (6 errors, all in src/domains/) — the sanctioned state between Tasks 4 and 7. Co-Authored-By: Claude Opus 5 (1M context) --- test/cdp/session-call-test.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/cdp/session-call-test.ts (limited to 'test') diff --git a/test/cdp/session-call-test.ts b/test/cdp/session-call-test.ts new file mode 100644 index 0000000..b318eb4 --- /dev/null +++ b/test/cdp/session-call-test.ts @@ -0,0 +1,28 @@ +import { test, describe } from "node:test"; +import assert from "node:assert/strict"; +import { decodeResult } from "../../src/cdp/commands"; + +describe("typed call decoding", () => { + test("a valid transport payload decodes to typed data", () => { + const fromTransport: unknown = { sessionId: "abc123" }; + const r = decodeResult("Target.attachToTarget", fromTransport); + assert.equal(r.success, true); + if (r.success) { + const sid: string = r.data.sessionId; + assert.equal(sid, "abc123"); + } + }); + + test("a garbage transport payload becomes invalid_response", () => { + const r = decodeResult("Target.attachToTarget", { sessionId: 42 }); + assert.equal(r.success, false); + if (!r.success) assert.equal(r.error.kind, "invalid_response"); + }); + + test("extra Chrome fields on a result are tolerated", () => { + const r = decodeResult("Target.getTargetInfo", { + targetInfo: { targetId: "t", type: "page", title: "T", url: "u", futureField: 1 }, + }); + assert.equal(r.success, true); + }); +}); -- cgit v1.2.3