From dc026acfea66d03a69c2481e01446728fd1fca9e Mon Sep 17 00:00:00 2001 From: cliffhall Date: Wed, 26 Aug 2026 20:54:39 -0400 Subject: [PATCH] chore(web): drop the double cast from the useSessionRef test fixture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses Copilot's review on #2152. The client stand-in was `({ tag }) as unknown as InspectorClient` — a double cast with no justification, which AGENTS.md rejects. `Object.create(InspectorClient.prototype)` gives a real prototype chain without running the constructor, so it needs only a single cast and still drags in no transport or environment. The tag went with it: every assertion compares identity, and `Object.create` already returns a distinct object per call. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01MZdpUwhHf943FoprcLVzEm Signed-off-by: cliffhall --- clients/web/src/hooks/useSessionRef.test.tsx | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/clients/web/src/hooks/useSessionRef.test.tsx b/clients/web/src/hooks/useSessionRef.test.tsx index fb84e68f..d5b063c3 100644 --- a/clients/web/src/hooks/useSessionRef.test.tsx +++ b/clients/web/src/hooks/useSessionRef.test.tsx @@ -1,5 +1,5 @@ import { describe, it, expect } from "vitest"; -import type { InspectorClient } from "@inspector/core/mcp/index.js"; +import { InspectorClient } from "@inspector/core/mcp/index.js"; import type { ServerEntry } from "@inspector/core/mcp/types.js"; import { renderWithMantine } from "../test/renderWithMantine"; import type { PendingReauth } from "../utils/pendingReauth"; @@ -17,8 +17,15 @@ const entry = (id: string, name = id): ServerEntry => ({ connection: { status: "disconnected" }, }); -/** A stand-in for the live client — the hook only ever stores the reference. */ -const client = (tag: string) => ({ tag }) as unknown as InspectorClient; +/** + * A distinct client identity per call. `Object.create` does not run the + * constructor, so this is a real `InspectorClient` prototype chain with no + * transport or environment behind it — which is all that is needed here: the + * hook only stores the reference, and every assertion compares identity rather + * than reading a property off it. + */ +const client = (): InspectorClient => + Object.create(InspectorClient.prototype) as InspectorClient; const stepUp = (serverId: string): PendingStepUp => ({ serverId, @@ -69,7 +76,7 @@ function harness(initial: SessionValues): Harness { describe("useSessionRef", () => { it("seeds the snapshot from the first render's values", () => { const servers = [entry("a")]; - const c = client("first"); + const c = client(); const h = harness( values({ activeServerId: "a", servers, inspectorClient: c }), ); @@ -91,7 +98,7 @@ describe("useSessionRef", () => { it("mirrors every field on a later render", () => { const h = harness(values()); const servers = [entry("a"), entry("b")]; - const c = client("later"); + const c = client(); const up = stepUp("a"); const re = reauth("b"); h.update( @@ -117,7 +124,7 @@ describe("useSessionRef", () => { values({ activeServerId: "a", servers: [entry("a")], - inspectorClient: client("x"), + inspectorClient: client(), pendingStepUp: stepUp("a"), pendingReauth: reauth("a"), }),