migrating console.error to debugger for installationManager, oauth-provider, modifiable-tool (#12279)

This commit is contained in:
Sehoon Shon
2025-10-31 14:17:51 -04:00
committed by GitHub
parent c158923b27
commit ab013fb7e9
5 changed files with 26 additions and 11 deletions
+10 -2
View File
@@ -27,6 +27,11 @@ vi.mock('./oauth-token-storage.js', () => {
})),
};
});
vi.mock('../utils/events.js', () => ({
coreEvents: {
emitFeedback: vi.fn(),
},
}));
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import * as http from 'node:http';
@@ -43,6 +48,7 @@ import type {
OAuthAuthorizationServerMetadata,
OAuthProtectedResourceMetadata,
} from './oauth-utils.js';
import { coreEvents } from '../utils/events.js';
// Mock fetch globally
const mockFetch = vi.fn();
@@ -938,8 +944,10 @@ describe('MCPOAuthProvider', () => {
expect(tokenStorage.deleteCredentials).toHaveBeenCalledWith(
'test-server',
);
expect(console.error).toHaveBeenCalledWith(
expect.stringContaining('Failed to refresh token'),
expect(coreEvents.emitFeedback).toHaveBeenCalledWith(
'error',
expect.stringContaining('Failed to refresh auth token'),
expect.any(Error),
);
});
+8 -3
View File
@@ -13,6 +13,7 @@ import type { OAuthToken } from './token-storage/types.js';
import { MCPOAuthTokenStorage } from './oauth-token-storage.js';
import { getErrorMessage } from '../utils/errors.js';
import { OAuthUtils } from './oauth-utils.js';
import { coreEvents } from '../utils/events.js';
import { debugLogger } from '../utils/debugLogger.js';
export const OAUTH_DISPLAY_MESSAGE_EVENT = 'oauth-display-message' as const;
@@ -811,12 +812,12 @@ ${authUrl}
`✓ Token verification successful (fingerprint: ${tokenFingerprint})`,
);
} else {
console.error(
debugLogger.warn(
'Token verification failed: token not found or invalid after save',
);
}
} catch (saveError) {
console.error(`Failed to save token: ${getErrorMessage(saveError)}`);
debugLogger.error('Failed to save auth token.', saveError);
throw saveError;
}
@@ -889,7 +890,11 @@ ${authUrl}
return newToken.accessToken;
} catch (error) {
console.error(`Failed to refresh token: ${getErrorMessage(error)}`);
coreEvents.emitFeedback(
'error',
'Failed to refresh auth token.',
error,
);
// Remove invalid token
await this.tokenStorage.deleteCredentials(serverName);
}