test: address Copilot review — tighten progress-token guard and de-flake relay tests (#2028)

- progressTokenOf now delegates to the SDK's ProgressTokenSchema instead of a
  bare typeof check, so fractional and past-MAX_SAFE_INTEGER numbers are
  rejected (matching isProgressToken in inspectorClient.ts); tests cover both.
- Browser relay timeout tests use fake timers with advanceTimersByTimeAsync and
  flush the SSE consumer between pushes, replacing real-sleep windows that a
  loaded runner could race (#1596).
- The log-only timeout test holds and awaits its rejection rather than
  swallowing it in an empty catch.
- progressToken.test.ts gains a file header; the remote-session malformed-token
  fixture uses a single-cast helper instead of `as unknown as`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PsmUAZ6aLUAFqenjJKSSRp
Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-09-13 21:30:29 -04:00
commit fb28b0fe64

View file

@ -7,11 +7,16 @@
*/
import { describe, it, expect, vi } from "vitest";
import type { Transport } from "@modelcontextprotocol/client";
import type { Transport, JSONRPCMessage } from "@modelcontextprotocol/client";
import { RemoteSession } from "@inspector/core/mcp/remote/node/remote-session.js";
import type { FetchRequestEntryBase } from "@inspector/core/mcp/types.js";
import { AuthChallengeError } from "@inspector/core/auth/challenge.js";
// Stage a deliberately off-spec message as `unknown` and narrow with a single
// cast — the guard branches these fixtures exercise are ones the typed
// `JSONRPCMessage` shape forbids, and `unknown` is the safe top type to pass in.
const asMsg = (m: unknown): JSONRPCMessage => m as JSONRPCMessage;
function makeFetchEntry(
overrides: Partial<FetchRequestEntryBase> = {},
): FetchRequestEntryBase {
@ -289,11 +294,13 @@ describe("RemoteSession", () => {
const wait = session.waitForRequestResponse(8, 1000);
const rejection = expect(wait).rejects.toThrow(/timed out/);
// A malformed token (object) must be ignored, not coerced to a key.
session.onMessage({
jsonrpc: "2.0",
method: "notifications/progress",
params: { progressToken: { bad: true }, progress: 1 },
} as unknown as Parameters<RemoteSession["onMessage"]>[0]);
session.onMessage(
asMsg({
jsonrpc: "2.0",
method: "notifications/progress",
params: { progressToken: { bad: true }, progress: 1 },
}),
);
await vi.advanceTimersByTimeAsync(1000);
await rejection;
vi.useRealTimers();