Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,24 @@ export default [
argsIgnorePattern: '^_',
varsIgnorePattern: '^_'
}],
'import/exports-last': 2,
'import/group-exports': 1,
'id-length': ['error', {
min: 2,
properties: 'never',
exceptions: ['a', 'b', 'i', 'j', 'k', '_']
}],
'n/no-process-exit': 0,
// Disallow console.log/info in runtime to protect STDIO; allow warn/error
'no-console': ['error', { allow: ['warn', 'error'] }]
}
},

// Test files
{
files: ['src/*.d.ts'],
rules: {
'import/group-exports': 0
}
},
{
files: [
'**/*.test.ts',
Expand All @@ -87,12 +98,12 @@ export default [
],
rules: {
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/ban-ts-comment': 1,
'@typescript-eslint/ban-ts-comment': 0,
'import/exports-last': 0,
'import/group-exports': 0,
'no-sparse-arrays': 0,
// Allow console usage in tests (spies, debug)
'no-console': 0,
// Relax stylistic padding in tests to reduce churn
'@stylistic/padding-line-between-statements': 0
'no-console': 0
}
}
];
2 changes: 2 additions & 0 deletions src/__tests__/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ describe('registerStderrSubscriber', () => {
const stderrSpy = jest.spyOn(process.stderr, 'write').mockImplementation(() => true as any);

const unsubscribe = registerStderrSubscriber(getLoggerOptions());

publish('debug', getLoggerOptions(), 'debug suppressed');
publish('info', getLoggerOptions(), 'lorem ipsum', 123, { a: 1 });

Expand Down Expand Up @@ -210,6 +211,7 @@ describe('createLogger', () => {
const stderrSpy = jest.spyOn(process.stderr, 'write').mockImplementation(() => true as any);

const unsubscribe = createLogger(getLoggerOptions());

publish('debug', getLoggerOptions(), 'debug suppressed');
publish('info', getLoggerOptions(), 'lorem ipsum', 123, { a: 1 });

Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ describe('parseCliOptions', () => {
it('parses from a provided argv independent of process.argv', () => {
const customArgv = ['node', 'cli', '--http', '--port', '3101'];
const result = parseCliOptions(customArgv);

expect(result.http?.port).toBe(3101);
});

it('trims spaces in list flags', () => {
const argv = ['node', 'cli', '--http', '--allowed-hosts', ' localhost , 127.0.0.1 '];
const result = parseCliOptions(argv);

expect(result.http?.allowedHosts).toEqual(['localhost', '127.0.0.1']);
});
});
4 changes: 2 additions & 2 deletions src/__tests__/server.caching.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ describe('memo', () => {

try {
successValue = await value();
} catch (e) {
const error = e as Error;
} catch (err) {
const error = err as Error;

errorValue = error.message;
}
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/server.http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describe('startHttpTransport', () => {

MockCreateServer.mockImplementation((handler: any) => {
mockRequestHandler = handler;

return mockHttpServer as any;
});
});
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/server.logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ describe('createServerLogger', () => {
setOptions({ logging: { stderr: true, level: 'debug' } as any });

const stderrSpy = jest.spyOn(process.stderr, 'write').mockImplementation(() => true as any);

class MockServer { sendLoggingMessage = jest.fn(async () => {}); }
const server = new MockServer() as any;

Expand Down
2 changes: 1 addition & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const publish = (level: LogLevel, options: LoggingSession = getLoggerOptions(),
event.args = args;
}
} else {
const arr = [msg, ...args].filter(v => v !== undefined);
const arr = [msg, ...args].filter(value => value !== undefined);

if (arr.length) {
event.args = arr as unknown[];
Expand Down
7 changes: 7 additions & 0 deletions tests/utils/fetchMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const startHttpFixture = (
// String pattern with wildcards
const pattern = regexRoute.url.replace(/\*/g, '.*');
const regex = new RegExp(`^${pattern}$`);

if (regex.test(pathname) || regex.test(`http://${address}${pathname}`)) {
route = {
status: regexRoute.status || 200,
Expand Down Expand Up @@ -251,6 +252,7 @@ export const setupFetchMock = async (options: FetchMockSetup = {}): Promise<Fetc

// Start fixture server with regex routes for dynamic matching
const fixtureOptions: StartHttpFixtureOptions = { routes: fixtureRoutes, address };

if (port) {
fixtureOptions.port = port;
}
Expand All @@ -260,12 +262,15 @@ export const setupFetchMock = async (options: FetchMockSetup = {}): Promise<Fetc
const matchRoute = (url: string): FetchRoute | undefined => {
// Extract pathname from URL for matching
let pathname: string;

try {
const urlObj = new URL(url);

pathname = urlObj.pathname;
} catch {
// If URL parsing fails, try to extract pathname manually
const match = url.match(/^https?:\/\/[^/]+(\/.*)$/);

pathname = match && match[1] ? match[1] : url;
}

Expand Down Expand Up @@ -307,6 +312,7 @@ export const setupFetchMock = async (options: FetchMockSetup = {}): Promise<Fetc
// For regex/pattern matches, extract the pathname from the matched URL
try {
const urlObj = new URL(url);

fixturePath = urlObj.pathname;
} catch {
// If URL parsing fails, fall back to index-based path
Expand All @@ -318,6 +324,7 @@ export const setupFetchMock = async (options: FetchMockSetup = {}): Promise<Fetc
// Note: This is important for stdio servers that run in separate processes
// and make real HTTP requests to the fixture server
const normalizedPath = fixturePath.startsWith('/') ? fixturePath : `/${fixturePath}`;

if (fixture.addRoute) {
// Check if route already exists to avoid overwriting
if (!fixtureRoutes[normalizedPath]) {
Expand Down
1 change: 1 addition & 0 deletions tests/utils/httpTransportClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const startServer = async (
try {
// Construct base URL from options
const baseUrl = `http://${host}:${port}/mcp`;

httpClientUrl = new URL(baseUrl);
} catch (error) {
throw new Error(`Failed to construct base URL: ${error}, host: ${host}, port: ${port}`);
Expand Down
Loading