Skip to content

Commit 373f8e9

Browse files
cliffhallclaude
andcommitted
test(cli,tui): address review — real spy signatures, config typecheck, nits
Responds to the @claude review of #1799: - App.test.tsx: type the OAuth spies against the real InspectorClient method signatures (`vi.fn<InspectorClient["…"]>()`) and forward `Parameters<…>` tuples from the FakeClient wrappers, so `toHaveBeenCalledWith(...)` on the six OAuth-lifecycle spies stays argument-checked under the new gate rather than accepting anything via `unknown[]`. `getOAuthState` regains its wide `OAuthConnectionState | undefined` return. - Typecheck the client config files too: add `vitest.config.ts` / `tsup.config.ts` (and tui `dev.ts`) to each src `tsconfig.json` include — they were the one first-party surface still getting no tsc pass. - Trim the redundant `src/**/*` from each `tsconfig.test.json` include (tsc pulls in the src the tests import; the src-only config already checks it). - Rename the tui settings helper to `oauth-test-fakes.ts` to match cli's, and soften both factories' docstrings to stop naming a loader they don't mirror field-for-field. - Fix a stale `@modelcontextprotocol/inspector-core/...` specifier in a createRemoteTransport JSDoc example (the same wrong package name the gate caught in the cli tests, surviving in a comment). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5
1 parent 09bdac4 commit 373f8e9

9 files changed

Lines changed: 57 additions & 35 deletions

File tree

‎clients/cli/__tests__/helpers/oauth-test-fakes.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ export function makeFakeCliOAuthClient(
3333
}
3434

3535
/**
36-
* A full {@link InspectorServerSettings} carrying the same product defaults the
37-
* server-list loader applies (`storedFieldsToInspectorSettings`). Pass
36+
* A full {@link InspectorServerSettings} with representative defaults for its
37+
* required fields (the timeouts at 0 = "SDK default", `taskTtl` /
38+
* `maxFetchRequests` at their product defaults, empty lists elsewhere). Pass
3839
* `overrides` for the field(s) under test (e.g. `{ enterpriseManaged: true }`).
3940
*/
4041
export function makeFakeServerSettings(

‎clients/cli/tsconfig.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
"@inspector/core/*": ["../../core/*"]
2121
}
2222
},
23-
"include": ["src/**/*"],
23+
"include": ["src/**/*", "vitest.config.ts", "tsup.config.ts"],
2424
"exclude": ["node_modules", "**/*.test.ts", "**/*.test.tsx", "build"]
2525
}

‎clients/cli/tsconfig.test.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
"vitest": ["./node_modules/vitest"]
1717
}
1818
},
19-
"include": ["src/**/*", "__tests__/**/*"],
19+
// Only the tests root the project; tsc pulls in the `src` they import. The
20+
// src-only tsconfig.json already validates all of `src` (without the
21+
// test-only aliases), so listing it here too would just check it twice.
22+
"include": ["__tests__/**/*"],
2023
"exclude": ["node_modules", "build"]
2124
}

‎clients/tui/__tests__/App.test.tsx‎

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,30 @@ const h = vi.hoisted(() => {
4848
const openUrl = vi.fn().mockResolvedValue(undefined);
4949
// Shared OAuth-related spies so a test can configure resolve/reject and
5050
// assert calls regardless of which per-server FakeClient instance App built.
51-
// The OAuth-lifecycle spies are given explicit `(...a: unknown[]) => …`
52-
// signatures so the FakeClient wrappers below (which forward `...a`) typecheck
53-
// against them, and so a wide return type (e.g. AuthChallengeOutcome) lets a
54-
// test `mockResolvedValue` any variant rather than only the impl's literal.
51+
// Each spy is typed against the real InspectorClient method signature so that
52+
// `toHaveBeenCalledWith(...)` assertions against them stay argument-checked
53+
// under the new gate — and the FakeClient wrappers below forward the same
54+
// `Parameters<…>` tuple, which spreads cleanly (a tuple, not `unknown[]`).
55+
// `authenticate` keeps a string-returning stub (the real method returns a
56+
// `URL`); it takes no arguments, so there is nothing to arg-check there.
5557
const clientSpies = {
56-
authenticate: vi.fn<(...a: unknown[]) => Promise<string | undefined>>(
58+
authenticate: vi.fn<() => Promise<string | undefined>>(
5759
async () => "https://auth.example/start",
5860
),
59-
clearOAuthTokens: vi.fn(),
60-
completeOAuthFlow: vi.fn<(...a: unknown[]) => Promise<void>>(
61+
clearOAuthTokens: vi.fn<InspectorClient["clearOAuthTokens"]>(),
62+
completeOAuthFlow: vi.fn<InspectorClient["completeOAuthFlow"]>(
6163
async () => {},
6264
),
63-
getOAuthState: vi.fn<(...a: unknown[]) => Promise<undefined>>(
65+
getOAuthState: vi.fn<InspectorClient["getOAuthState"]>(
6466
async () => undefined,
6567
),
6668
callTool: vi.fn(),
67-
checkAuthChallengeSatisfied: vi.fn<(...a: unknown[]) => Promise<boolean>>(
68-
async () => false,
69+
checkAuthChallengeSatisfied: vi.fn<
70+
InspectorClient["checkAuthChallengeSatisfied"]
71+
>(async () => false),
72+
handleAuthChallenge: vi.fn<InspectorClient["handleAuthChallenge"]>(
73+
async () => ({ kind: "satisfied" }),
6974
),
70-
handleAuthChallenge: vi.fn<
71-
(...a: unknown[]) => Promise<AuthChallengeOutcome>
72-
>(async () => ({ kind: "satisfied" })),
7375
};
7476
// Captured options from the most recent callbackServer.start(), so a test can
7577
// drive the onCallback / onError handlers the OAuth flows register.
@@ -136,16 +138,19 @@ const h = vi.hoisted(() => {
136138
| "sse"
137139
| "streamable-http",
138140
);
139-
authenticate = (...a: unknown[]) => clientSpies.authenticate(...a);
140-
clearOAuthTokens = (...a: unknown[]) => clientSpies.clearOAuthTokens(...a);
141-
completeOAuthFlow = (...a: unknown[]) =>
142-
clientSpies.completeOAuthFlow(...a);
143-
getOAuthState = (...a: unknown[]) => clientSpies.getOAuthState(...a);
141+
authenticate = () => clientSpies.authenticate();
142+
clearOAuthTokens = () => clientSpies.clearOAuthTokens();
143+
completeOAuthFlow = (
144+
...a: Parameters<InspectorClient["completeOAuthFlow"]>
145+
) => clientSpies.completeOAuthFlow(...a);
146+
getOAuthState = () => clientSpies.getOAuthState();
144147
callTool = (...a: unknown[]) => clientSpies.callTool(...a);
145-
checkAuthChallengeSatisfied = (...a: unknown[]) =>
146-
clientSpies.checkAuthChallengeSatisfied(...a);
147-
handleAuthChallenge = (...a: unknown[]) =>
148-
clientSpies.handleAuthChallenge(...a);
148+
checkAuthChallengeSatisfied = (
149+
...a: Parameters<InspectorClient["checkAuthChallengeSatisfied"]>
150+
) => clientSpies.checkAuthChallengeSatisfied(...a);
151+
handleAuthChallenge = (
152+
...a: Parameters<InspectorClient["handleAuthChallenge"]>
153+
) => clientSpies.handleAuthChallenge(...a);
149154
readResource = vi.fn(async () => ({
150155
result: { contents: [{ uri: "file://x", text: "hello" }] },
151156
}));
@@ -275,12 +280,12 @@ vi.mock("../src/utils/openUrl.js", () => ({
275280
}));
276281

277282
import App from "../src/App.js";
283+
import type { InspectorClient } from "@inspector/core/mcp/index.js";
278284
import type { TuiServer } from "../src/tui-servers.js";
279285
import {
280286
AuthRecoveryRequiredError,
281287
EMA_STEP_UP_PENDING_URL,
282288
} from "@inspector/core/auth/challenge.js";
283-
import type { AuthChallengeOutcome } from "@inspector/core/auth/challenge.js";
284289
import { EmaClientNotConfiguredError } from "@inspector/core/auth/ema/clientConfigError.js";
285290

286291
const tick = () => new Promise((r) => setTimeout(r, 25));

clients/tui/__tests__/helpers/server-settings.ts renamed to clients/tui/__tests__/helpers/oauth-test-fakes.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import {
55
import type { InspectorServerSettings } from "@inspector/core/mcp/types.js";
66

77
/**
8-
* A full {@link InspectorServerSettings} carrying the same product defaults the
9-
* server-list loader applies. Lets a test supply only the field(s) under test
10-
* (e.g. `{ enterpriseManaged: true }`) while `tsc` still sees a complete object,
11-
* avoiding `as unknown as` casts (see #1791 and the AGENTS.md `as`-cast policy).
8+
* A full {@link InspectorServerSettings} with representative defaults for its
9+
* required fields (the timeouts at 0 = "SDK default", `taskTtl` /
10+
* `maxFetchRequests` at their product defaults, empty lists elsewhere). Lets a
11+
* test supply only the field(s) under test (e.g. `{ enterpriseManaged: true }`)
12+
* while `tsc` still sees a complete object, avoiding `as unknown as` casts (see
13+
* #1791 and the AGENTS.md `as`-cast policy).
1214
*/
1315
export function makeFakeServerSettings(
1416
overrides: Partial<InspectorServerSettings> = {},

‎clients/tui/__tests__/tuiOAuth.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
stepUpConfirmMessage,
66
stepUpInsufficientScopeMessage,
77
} from "../src/utils/tuiOAuth.js";
8-
import { makeFakeServerSettings } from "./helpers/server-settings.js";
8+
import { makeFakeServerSettings } from "./helpers/oauth-test-fakes.js";
99

1010
describe("tuiOAuth", () => {
1111
it("detects standard OAuth step-up", () => {

‎clients/tui/tsconfig.json‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
"react/jsx-runtime": ["./node_modules/@types/react/jsx-runtime"]
2626
}
2727
},
28-
"include": ["index.ts", "tui.tsx", "src/**/*"],
28+
"include": [
29+
"index.ts",
30+
"tui.tsx",
31+
"src/**/*",
32+
"dev.ts",
33+
"vitest.config.ts",
34+
"tsup.config.ts"
35+
],
2936
"exclude": ["node_modules", "**/*.test.ts", "**/*.test.tsx", "build"]
3037
}

‎clients/tui/tsconfig.test.json‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"vitest": ["./node_modules/vitest"]
1313
}
1414
},
15-
"include": ["index.ts", "tui.tsx", "src/**/*", "__tests__/**/*"],
15+
// Only the tests root the project; tsc pulls in the `src` they import. The
16+
// src-only tsconfig.json already validates `src` (and index.ts / tui.tsx)
17+
// without the test-only aliases, so listing them here too would just check
18+
// them twice.
19+
"include": ["__tests__/**/*"],
1620
"exclude": ["node_modules", "build"]
1721
}

‎core/mcp/remote/createRemoteTransport.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface RemoteTransportFactoryOptions {
2626
* connecting to the given remote server.
2727
*
2828
* @example
29-
* import { API_SERVER_ENV_VARS } from '@modelcontextprotocol/inspector-core/mcp/remote';
29+
* import { API_SERVER_ENV_VARS } from '@inspector/core/mcp/remote/constants.js';
3030
* const createTransport = createRemoteTransport({
3131
* baseUrl: 'http://localhost:3000',
3232
* authToken: process.env[API_SERVER_ENV_VARS.AUTH_TOKEN],

0 commit comments

Comments
 (0)