Skip to content

Commit dc026ac

Browse files
cliffhallclaude
andcommitted
chore(web): drop the double cast from the useSessionRef test fixture
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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MZdpUwhHf943FoprcLVzEm Signed-off-by: cliffhall <cliff@futurescale.com>
1 parent 104b3c0 commit dc026ac

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

‎clients/web/src/hooks/useSessionRef.test.tsx‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect } from "vitest";
2-
import type { InspectorClient } from "@inspector/core/mcp/index.js";
2+
import { InspectorClient } from "@inspector/core/mcp/index.js";
33
import type { ServerEntry } from "@inspector/core/mcp/types.js";
44
import { renderWithMantine } from "../test/renderWithMantine";
55
import type { PendingReauth } from "../utils/pendingReauth";
@@ -17,8 +17,15 @@ const entry = (id: string, name = id): ServerEntry => ({
1717
connection: { status: "disconnected" },
1818
});
1919

20-
/** A stand-in for the live client — the hook only ever stores the reference. */
21-
const client = (tag: string) => ({ tag }) as unknown as InspectorClient;
20+
/**
21+
* A distinct client identity per call. `Object.create` does not run the
22+
* constructor, so this is a real `InspectorClient` prototype chain with no
23+
* transport or environment behind it — which is all that is needed here: the
24+
* hook only stores the reference, and every assertion compares identity rather
25+
* than reading a property off it.
26+
*/
27+
const client = (): InspectorClient =>
28+
Object.create(InspectorClient.prototype) as InspectorClient;
2229

2330
const stepUp = (serverId: string): PendingStepUp => ({
2431
serverId,
@@ -69,7 +76,7 @@ function harness(initial: SessionValues): Harness {
6976
describe("useSessionRef", () => {
7077
it("seeds the snapshot from the first render's values", () => {
7178
const servers = [entry("a")];
72-
const c = client("first");
79+
const c = client();
7380
const h = harness(
7481
values({ activeServerId: "a", servers, inspectorClient: c }),
7582
);
@@ -91,7 +98,7 @@ describe("useSessionRef", () => {
9198
it("mirrors every field on a later render", () => {
9299
const h = harness(values());
93100
const servers = [entry("a"), entry("b")];
94-
const c = client("later");
101+
const c = client();
95102
const up = stepUp("a");
96103
const re = reauth("b");
97104
h.update(
@@ -117,7 +124,7 @@ describe("useSessionRef", () => {
117124
values({
118125
activeServerId: "a",
119126
servers: [entry("a")],
120-
inspectorClient: client("x"),
127+
inspectorClient: client(),
121128
pendingStepUp: stepUp("a"),
122129
pendingReauth: reauth("a"),
123130
}),

0 commit comments

Comments
 (0)