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

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),
);
});

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);
}

View File

@@ -17,6 +17,7 @@ import type {
DeclarativeTool,
ToolResult,
} from './tools.js';
import { debugLogger } from '../utils/debugLogger.js';
/**
* A declarative tool that supports a modify operation.
@@ -128,13 +129,13 @@ function deleteTempFiles(oldPath: string, newPath: string): void {
try {
fs.unlinkSync(oldPath);
} catch {
console.error(`Error deleting temp diff file: ${oldPath}`);
debugLogger.error(`Error deleting temp diff file: ${oldPath}`);
}
try {
fs.unlinkSync(newPath);
} catch {
console.error(`Error deleting temp diff file: ${newPath}`);
debugLogger.error(`Error deleting temp diff file: ${newPath}`);
}
}

View File

@@ -91,14 +91,14 @@ describe('InstallationManager', () => {
readSpy.mockImplementationOnce(() => {
throw new Error('Read error');
});
const consoleErrorSpy = vi
.spyOn(console, 'error')
const consoleWarnSpy = vi
.spyOn(console, 'warn')
.mockImplementation(() => {});
const id = installationManager.getInstallationId();
expect(id).toBe('123456789');
expect(consoleErrorSpy).toHaveBeenCalled();
expect(consoleWarnSpy).toHaveBeenCalled();
});
});
});

View File

@@ -8,6 +8,7 @@ import * as fs from 'node:fs';
import { randomUUID } from 'node:crypto';
import * as path from 'node:path';
import { Storage } from '../config/storage.js';
import { debugLogger } from './debugLogger.js';
export class InstallationManager {
private getInstallationIdPath(): string {
@@ -48,7 +49,7 @@ export class InstallationManager {
return installationId;
} catch (error) {
console.error(
debugLogger.warn(
'Error accessing installation ID file, generating ephemeral ID:',
error,
);