test: switch integration project to folder-based manifest (#1314) (#1318)

* test: switch integration project to folder-based manifest (#1314)

Replace the `integrationTests` enumeration in vite.config.ts with a
folder glob (`src/test/integration/**/*.test.ts`). Files under that
folder run in the integration vitest project (node env, 30s timeouts);
everything else runs in the unit project (happy-dom).

This removes the silent misclassification trap from #1307: a new
integration-style test no longer falls into the unit project (and
happy-dom) just because someone forgot to add it to the array.

The 13 ported v1.5 tests + their helpers move under src/test/integration/
in a strict mirror of core/ source layout (mcp/, auth/, auth/node/,
storage/). Renames use git mv so history is preserved.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test: address PR review on #1318 (glob extensions + AGENTS doc)

- vite.config.ts: widen integrationGlob from `*.test.ts` to
  `*.test.{ts,tsx}` so the integration folder fully owns its contents.
  Without this, a `.test.tsx` placed under src/test/integration/ would
  match the unit project's `{ts,tsx}` include, fail the unit `.ts`-only
  exclude, and silently land under happy-dom — the exact misclassification
  trap this PR set out to close.
- AGENTS.md: update the line describing where integration tests live;
  it still pointed at the old `src/test/core/` location and the removed
  `integrationTests` enumeration.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cliff Hall 2026-05-18 11:54:49 -04:00 • committed by GitHub
commit 8bb389c8e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,200 @@
import {
describe,
it,
expect,
vi,
beforeEach,
afterEach,
afterAll,
} from "vitest";
import * as path from "node:path";
import * as os from "node:os";
import * as fs from "node:fs/promises";
import { InspectorClient } from "@inspector/core/mcp/inspectorClient.js";
import { createTransportNode } from "@inspector/core/mcp/node/transport.js";
import type { MCPServerConfig } from "@inspector/core/mcp/types.js";
import { NodeOAuthStorage } from "@inspector/core/auth/node/storage-node.js";
import { createOAuthClientConfig } from "../helpers/oauth-client-fixtures.js";
import type { InspectorClientOptions } from "@inspector/core/mcp/inspectorClient.js";
const oauthTestStatePath = path.join(
os.tmpdir(),
`mcp-oauth-${process.pid}-inspectorClient-oauth-fetchFn.json`,
);
function createTestOAuthConfig(
options: Parameters<typeof createOAuthClientConfig>[0],
) {
return {
...createOAuthClientConfig(options),
storage: new NodeOAuthStorage(oauthTestStatePath),
};
}
const mockAuth = vi.fn();
vi.mock("@modelcontextprotocol/sdk/client/auth.js", () => ({
auth: (...args: unknown[]) => mockAuth(...args),
}));
describe("InspectorClient OAuth fetchFn", () => {
let client: InspectorClient;
afterAll(async () => {
try {
await fs.unlink(oauthTestStatePath);
} catch {
// Ignore if file does not exist or already removed
}
});
beforeEach(() => {
vi.clearAllMocks();
vi.spyOn(console, "log").mockImplementation(() => {});
mockAuth.mockImplementation(
async (provider: { redirectToAuthorization: (url: URL) => void }) => {
provider.redirectToAuthorization(
new URL("http://example.com/oauth/authorize"),
);
return "REDIRECT";
},
);
});
afterEach(async () => {
if (client) {
try {
await client.disconnect();
} catch {
// Ignore disconnect errors
}
}
vi.restoreAllMocks();
});
it("should pass fetchFn to auth() when provided", async () => {
const mockFetchFn = vi.fn();
const oauthConfig = createTestOAuthConfig({
mode: "static",
clientId: "test-client",
redirectUrl: "http://localhost:3000/callback",
});
client = new InspectorClient(
{ type: "sse", url: "http://localhost:3000/sse" } as MCPServerConfig,
{
environment: {
transport: createTransportNode,
fetch: mockFetchFn,
oauth: {
storage: oauthConfig.storage,
navigation: oauthConfig.navigation,
redirectUrlProvider: oauthConfig.redirectUrlProvider,
},
},
oauth: {
clientId: oauthConfig.clientId,
clientSecret: oauthConfig.clientSecret,
clientMetadataUrl: oauthConfig.clientMetadataUrl,
scope: oauthConfig.scope,
},
},
);
const url = await client.authenticate();
expect(url).toBeInstanceOf(URL);
expect(mockAuth).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
fetchFn: expect.any(Function),
}),
);
});
it("should pass fetchFn to auth() when not provided (uses default fetch)", async () => {
const oauthConfig = createTestOAuthConfig({
mode: "static",
clientId: "test-client",
redirectUrl: "http://localhost:3000/callback",
});
client = new InspectorClient(
{ type: "sse", url: "http://localhost:3000/sse" } as MCPServerConfig,
{
environment: {
transport: createTransportNode,
oauth: {
storage: oauthConfig.storage,
navigation: oauthConfig.navigation,
redirectUrlProvider: oauthConfig.redirectUrlProvider,
},
},
oauth: {
clientId: oauthConfig.clientId,
clientSecret: oauthConfig.clientSecret,
clientMetadataUrl: oauthConfig.clientMetadataUrl,
scope: oauthConfig.scope,
},
} as InspectorClientOptions,
);
await client.authenticate();
expect(mockAuth).toHaveBeenCalled();
const callArgs = mockAuth.mock.calls[0]!;
const options = callArgs[1];
expect(options).toHaveProperty("fetchFn");
expect(typeof options.fetchFn).toBe("function");
});
it("should pass fetchFn to auth() in completeOAuthFlow when provided", async () => {
const mockFetchFn = vi.fn();
mockAuth.mockImplementation(
async (provider: { saveTokens: (tokens: unknown) => void }) => {
provider.saveTokens({
access_token: "test-token",
token_type: "Bearer",
});
return "AUTHORIZED";
},
);
const oauthConfig = createTestOAuthConfig({
mode: "static",
clientId: "test-client",
redirectUrl: "http://localhost:3000/callback",
});
client = new InspectorClient(
{ type: "sse", url: "http://localhost:3000/sse" } as MCPServerConfig,
{
environment: {
transport: createTransportNode,
fetch: mockFetchFn,
oauth: {
storage: oauthConfig.storage,
navigation: oauthConfig.navigation,
redirectUrlProvider: oauthConfig.redirectUrlProvider,
},
},
oauth: {
clientId: oauthConfig.clientId,
clientSecret: oauthConfig.clientSecret,
clientMetadataUrl: oauthConfig.clientMetadataUrl,
scope: oauthConfig.scope,
},
},
);
await client.completeOAuthFlow("test-authorization-code");
expect(mockAuth).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
authorizationCode: "test-authorization-code",
fetchFn: expect.any(Function),
}),
);
});
});