Skip to content

Commit 5b02722

Browse files
committed
more type fixes
1 parent 50f2aab commit 5b02722

File tree

13 files changed

+52
-52
lines changed

13 files changed

+52
-52
lines changed

src/client/auth.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,7 @@ describe('OAuth Authorization', () => {
11221122
expect(mockFetch).toHaveBeenCalledTimes(1);
11231123
expect(mockFetch.mock.calls[0][0].toString()).toBe('https://auth.example.com/token');
11241124
expect(mockFetch.mock.calls[0][1].method).toBe('POST');
1125+
expect(mockFetch.mock.calls[0][1].headers.get('Content-Type')).toBe('application/x-www-form-urlencoded');
11251126

11261127
const body = mockFetch.mock.calls[0][1].body as URLSearchParams;
11271128
expect(body.get('grant_type')).toBe('authorization_code');

src/client/cross-spawn.test.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ import { StdioClientTransport, getDefaultEnvironment } from './stdio.js';
22
import spawn from 'cross-spawn';
33
import { JSONRPCMessage } from '../types.js';
44
import { ChildProcess } from 'node:child_process';
5+
import { Mock, MockedFunction } from 'vitest';
56

67
// mock cross-spawn
78
vi.mock('cross-spawn');
8-
const mockSpawn = spawn as vi.MockedFunction<typeof spawn>;
9+
const mockSpawn = spawn as unknown as MockedFunction<typeof spawn>;
910

1011
describe('StdioClientTransport using cross-spawn', () => {
1112
beforeEach(() => {
1213
// mock cross-spawn's return value
1314
mockSpawn.mockImplementation(() => {
1415
const mockProcess: {
15-
on: vi.Mock;
16-
stdin?: { on: vi.Mock; write: vi.Mock };
17-
stdout?: { on: vi.Mock };
16+
on: Mock;
17+
stdin?: { on: Mock; write: Mock };
18+
stdout?: { on: Mock };
1819
stderr?: null;
1920
} = {
2021
on: vi.fn((event: string, callback: () => void) => {
@@ -105,14 +106,14 @@ describe('StdioClientTransport using cross-spawn', () => {
105106

106107
// get the mock process object
107108
const mockProcess: {
108-
on: vi.Mock;
109+
on: Mock;
109110
stdin: {
110-
on: vi.Mock;
111-
write: vi.Mock;
112-
once: vi.Mock;
111+
on: Mock;
112+
write: Mock;
113+
once: Mock;
113114
};
114115
stdout: {
115-
on: vi.Mock;
116+
on: Mock;
116117
};
117118
stderr: null;
118119
} = {

src/client/middleware.test.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { withOAuth, withLogging, applyMiddlewares, createMiddleware } from './middleware.js';
22
import { OAuthClientProvider } from './auth.js';
33
import { FetchLike } from '../shared/transport.js';
4+
import { MockInstance, Mocked, MockedFunction } from 'vitest';
45

56
vi.mock('../client/auth.js', async () => {
67
const actual = await vi.importActual<typeof import('../client/auth.js')>('../client/auth.js');
@@ -13,12 +14,12 @@ vi.mock('../client/auth.js', async () => {
1314

1415
import { auth, extractWWWAuthenticateParams } from './auth.js';
1516

16-
const mockAuth = auth as vi.MockedFunction<typeof auth>;
17-
const mockExtractWWWAuthenticateParams = extractWWWAuthenticateParams as vi.MockedFunction<typeof extractWWWAuthenticateParams>;
17+
const mockAuth = auth as MockedFunction<typeof auth>;
18+
const mockExtractWWWAuthenticateParams = extractWWWAuthenticateParams as MockedFunction<typeof extractWWWAuthenticateParams>;
1819

1920
describe('withOAuth', () => {
20-
let mockProvider: vi.Mocked<OAuthClientProvider>;
21-
let mockFetch: vi.MockedFunction<FetchLike>;
21+
let mockProvider: Mocked<OAuthClientProvider>;
22+
let mockFetch: MockedFunction<FetchLike>;
2223

2324
beforeEach(() => {
2425
vi.clearAllMocks();
@@ -371,8 +372,8 @@ describe('withOAuth', () => {
371372
});
372373

373374
describe('withLogging', () => {
374-
let mockFetch: vi.MockedFunction<FetchLike>;
375-
let mockLogger: vi.MockedFunction<
375+
let mockFetch: MockedFunction<FetchLike>;
376+
let mockLogger: MockedFunction<
376377
(input: {
377378
method: string;
378379
url: string | URL;
@@ -384,8 +385,8 @@ describe('withLogging', () => {
384385
error?: Error;
385386
}) => void
386387
>;
387-
let consoleErrorSpy: vi.SpyInstance;
388-
let consoleLogSpy: vi.SpyInstance;
388+
let consoleErrorSpy: MockInstance;
389+
let consoleLogSpy: MockInstance;
389390

390391
beforeEach(() => {
391392
vi.clearAllMocks();
@@ -614,7 +615,7 @@ describe('withLogging', () => {
614615
});
615616

616617
describe('applyMiddleware', () => {
617-
let mockFetch: vi.MockedFunction<FetchLike>;
618+
let mockFetch: MockedFunction<FetchLike>;
618619

619620
beforeEach(() => {
620621
vi.clearAllMocks();
@@ -743,8 +744,8 @@ describe('applyMiddleware', () => {
743744
});
744745

745746
describe('Integration Tests', () => {
746-
let mockProvider: vi.Mocked<OAuthClientProvider>;
747-
let mockFetch: vi.MockedFunction<FetchLike>;
747+
let mockProvider: Mocked<OAuthClientProvider>;
748+
let mockFetch: MockedFunction<FetchLike>;
748749

749750
beforeEach(() => {
750751
vi.clearAllMocks();
@@ -914,7 +915,7 @@ describe('Integration Tests', () => {
914915
});
915916

916917
describe('createMiddleware', () => {
917-
let mockFetch: vi.MockedFunction<FetchLike>;
918+
let mockFetch: MockedFunction<FetchLike>;
918919

919920
beforeEach(() => {
920921
vi.clearAllMocks();

src/client/sse.test.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { SSEClientTransport } from './sse.js';
55
import { OAuthClientProvider, UnauthorizedError } from './auth.js';
66
import { OAuthTokens } from '../shared/auth.js';
77
import { InvalidClientError, InvalidGrantError, UnauthorizedClientError } from '../server/auth/errors.js';
8+
import { Mock, Mocked, MockedFunction, MockInstance } from 'vitest';
89

910
describe('SSEClientTransport', () => {
1011
let resourceServer: Server;
@@ -333,7 +334,7 @@ describe('SSEClientTransport', () => {
333334
})
334335
);
335336

336-
const calledHeaders = (global.fetch as vi.Mock).mock.calls[0][1].headers;
337+
const calledHeaders = (global.fetch as Mock).mock.calls[0][1].headers;
337338
expect(calledHeaders.get('Authorization')).toBe(customHeaders.Authorization);
338339
expect(calledHeaders.get('X-Custom-Header')).toBe(customHeaders['X-Custom-Header']);
339340
expect(calledHeaders.get('content-type')).toBe('application/json');
@@ -347,7 +348,7 @@ describe('SSEClientTransport', () => {
347348
describe('auth handling', () => {
348349
const authServerMetadataUrls = ['/.well-known/oauth-authorization-server', '/.well-known/openid-configuration'];
349350

350-
let mockAuthProvider: vi.Mocked<OAuthClientProvider>;
351+
let mockAuthProvider: Mocked<OAuthClientProvider>;
351352

352353
beforeEach(() => {
353354
mockAuthProvider = {
@@ -1124,19 +1125,10 @@ describe('SSEClientTransport', () => {
11241125
});
11251126

11261127
describe('custom fetch in auth code paths', () => {
1127-
let customFetch: vi.MockedFunction<typeof fetch>;
1128-
let globalFetchSpy: vi.SpyInstance;
1129-
let mockAuthProvider: vi.Mocked<OAuthClientProvider>;
1130-
let resourceServerHandler: vi.Mock<
1131-
void,
1132-
[
1133-
IncomingMessage,
1134-
ServerResponse<IncomingMessage> & {
1135-
req: IncomingMessage;
1136-
}
1137-
],
1138-
void
1139-
>;
1128+
let customFetch: MockedFunction<typeof fetch>;
1129+
let globalFetchSpy: MockInstance;
1130+
let mockAuthProvider: Mocked<OAuthClientProvider>;
1131+
let resourceServerHandler: Mock;
11401132

11411133
/**
11421134
* Helper function to create a mock auth provider with configurable behavior
@@ -1149,7 +1141,7 @@ describe('SSEClientTransport', () => {
11491141
clientRegistered?: boolean;
11501142
authorizationCode?: string;
11511143
} = {}
1152-
): vi.Mocked<OAuthClientProvider> => {
1144+
): Mocked<OAuthClientProvider> => {
11531145
const tokens = config.hasTokens
11541146
? {
11551147
access_token: config.tokensExpired ? 'expired-token' : 'valid-token',
@@ -1317,7 +1309,7 @@ describe('SSEClientTransport', () => {
13171309

13181310
it('uses custom fetch during auth flow on SSE connection 401 - no global fetch fallback', async () => {
13191311
// Set up resource server that returns 401 on SSE connection and provides OAuth metadata
1320-
resourceServerHandler.mockImplementation((req, res) => {
1312+
resourceServerHandler.mockImplementation((req: IncomingMessage, res: ServerResponse) => {
13211313
if (req.url === '/') {
13221314
// Return 401 to trigger auth flow
13231315
res.writeHead(401, {
@@ -1361,7 +1353,7 @@ describe('SSEClientTransport', () => {
13611353

13621354
it('uses custom fetch during auth flow on POST request 401 - no global fetch fallback', async () => {
13631355
// Set up resource server that accepts SSE connection but returns 401 on POST
1364-
resourceServerHandler.mockImplementation((req, res) => {
1356+
resourceServerHandler.mockImplementation((req: IncomingMessage, res: ServerResponse) => {
13651357
switch (req.method) {
13661358
case 'GET':
13671359
if (req.url === '/') {

src/server/auth/handlers/register.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { OAuthRegisteredClientsStore } from '../clients.js';
33
import { OAuthClientInformationFull, OAuthClientMetadata } from '../../../shared/auth.js';
44
import express from 'express';
55
import supertest from 'supertest';
6+
import { MockInstance } from 'vitest';
67

78
describe('Client Registration Handler', () => {
89
// Mock client store with registration support
@@ -45,7 +46,7 @@ describe('Client Registration Handler', () => {
4546

4647
describe('Request handling', () => {
4748
let app: express.Express;
48-
let spyRegisterClient: vi.SpyInstance;
49+
let spyRegisterClient: MockInstance;
4950

5051
beforeEach(() => {
5152
// Setup express app with registration handler

src/server/auth/handlers/revoke.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import express, { Response } from 'express';
66
import supertest from 'supertest';
77
import { AuthInfo } from '../types.js';
88
import { InvalidTokenError } from '../errors.js';
9+
import { MockInstance } from 'vitest';
910

1011
describe('Revocation Handler', () => {
1112
// Mock client data
@@ -130,7 +131,7 @@ describe('Revocation Handler', () => {
130131

131132
describe('Request handling', () => {
132133
let app: express.Express;
133-
let spyRevokeToken: vi.SpyInstance;
134+
let spyRevokeToken: MockInstance;
134135

135136
beforeEach(() => {
136137
// Setup express app with revocation handler

src/server/auth/middleware/bearerAuth.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Request, Response } from 'express';
2+
import { Mock } from 'vitest';
23
import { requireBearerAuth } from './bearerAuth.js';
34
import { AuthInfo } from '../types.js';
45
import { InsufficientScopeError, InvalidTokenError, CustomOAuthError, ServerError } from '../errors.js';
@@ -13,7 +14,7 @@ const mockVerifier: OAuthTokenVerifier = {
1314
describe('requireBearerAuth middleware', () => {
1415
let mockRequest: Partial<Request>;
1516
let mockResponse: Partial<Response>;
16-
let nextFunction: vi.Mock;
17+
let nextFunction: Mock;
1718

1819
beforeEach(() => {
1920
mockRequest = {

src/server/auth/providers/proxyProvider.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { OAuthClientInformationFull, OAuthTokens } from '../../../shared/auth.js
55
import { ServerError } from '../errors.js';
66
import { InvalidTokenError } from '../errors.js';
77
import { InsufficientScopeError } from '../errors.js';
8-
import { type Mock } from "vitest"
8+
import { type Mock } from 'vitest';
99

1010
describe('Proxy OAuth Server Provider', () => {
1111
// Mock client data

src/server/mcp.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,7 @@ describe('tool()', () => {
17051705
});
17061706

17071707
// Spy on console.warn to verify warnings are logged
1708-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation();
1708+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
17091709

17101710
// Test valid tool names
17111711
testServer.registerTool(

src/server/sse.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import http from 'http';
2+
import { type Mocked } from 'vitest';
23

34
import { SSEServerTransport } from './sse.js';
45
import { McpServer } from './mcp.js';
@@ -15,7 +16,7 @@ const createMockResponse = () => {
1516
end: vi.fn<http.ServerResponse['end']>().mockReturnThis()
1617
};
1718

18-
return res as unknown as vi.Mocked<http.ServerResponse>;
19+
return res as unknown as Mocked<http.ServerResponse>;
1920
};
2021

2122
const createMockRequest = ({ headers = {}, body }: { headers?: Record<string, string>; body?: string } = {}) => {

0 commit comments

Comments
 (0)