From 9f8dc82a9abee9775ba6dd121ad2a513bd6858b8 Mon Sep 17 00:00:00 2001 From: cliffhall Date: Sun, 23 Aug 2026 21:07:25 -0400 Subject: [PATCH] test(web): drop the double casts from the resources hook mock `as unknown as ReturnType` erased the hook's contract and hid that the mock omitted its required `error` and `listChanged` fields, which the repo's TypeScript rules disallow. Build the complete `UseManagedResourcesResult` through a small helper instead, so a future change to that interface fails the typecheck here. Signed-off-by: cliffhall --- clients/web/src/App.test.tsx | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/clients/web/src/App.test.tsx b/clients/web/src/App.test.tsx index a37ec645..923a5e1f 100644 --- a/clients/web/src/App.test.tsx +++ b/clients/web/src/App.test.tsx @@ -615,6 +615,8 @@ import type { } from "@inspector/core/mcp/types.js"; import type { AppBridgeFactoryDeps } from "./components/elements/AppRenderer/createAppBridgeFactory"; import { useManagedResources } from "@inspector/core/react/useManagedResources.js"; +import type { UseManagedResourcesResult } from "@inspector/core/react/useManagedResources.js"; +import type { Resource } from "@modelcontextprotocol/client"; // Default useInspectorClient return — capabilities empty (no task tool calls). // Individual tests override via vi.mocked(...).mockReturnValue(...). @@ -3143,6 +3145,19 @@ describe("App background command rejections (#2049)", () => { }); }); +/** A complete `useManagedResources` return, so the mock stays type-checked against the hook's contract. */ +function managedResourcesResult( + resources: Resource[], +): UseManagedResourcesResult { + return { + error: null, + resources, + listChanged: false, + refresh: vi.fn().mockResolvedValue(resources), + clearListChanged: vi.fn(), + }; +} + describe("App MCP App listed-resource metadata wiring (#2055)", () => { beforeEach(() => { appBridgeFactoryDeps.length = 0; @@ -3151,11 +3166,7 @@ describe("App MCP App listed-resource metadata wiring (#2055)", () => { afterEach(() => { // The hook mock is module-level and shared, so put the empty-list default // back rather than leaving a populated list for whatever runs next. - vi.mocked(useManagedResources).mockReturnValue({ - resources: [], - refresh: vi.fn(), - clearListChanged: vi.fn(), - } as unknown as ReturnType); + vi.mocked(useManagedResources).mockReturnValue(managedResourcesResult([])); }); it("hands the bridge factory a getListedResourceMeta reading the resources/list entries", async () => { @@ -3165,13 +3176,11 @@ describe("App MCP App listed-resource metadata wiring (#2055)", () => { const listedMeta = { ui: { csp: { connectDomains: ["https://api.example.com"] } }, }; - vi.mocked(useManagedResources).mockReturnValue({ - resources: [ + vi.mocked(useManagedResources).mockReturnValue( + managedResourcesResult([ { uri: "ui://weather/app.html", name: "app", _meta: listedMeta }, - ], - refresh: vi.fn(), - clearListChanged: vi.fn(), - } as unknown as ReturnType); + ]), + ); renderWithMantine(); await waitFor(() => expect(appBridgeFactoryDeps.length).toBeGreaterThan(0));