refactor(debug): replace ConsolePatcher with debugLogger and update error reporting

- Replace ConsolePatcher with centralized debugLogger utility
- Refactor errorReporting to use debugLogger instead of file-based reporting
- Remove user-facing console message components:
  - Delete ConsolePatcher.ts, useConsoleMessages.ts/hook
  - Delete ConsoleSummaryDisplay.tsx, DetailedMessagesDisplay.tsx
- Update all tests in packages/core and packages/cli:
  - Mock debugLogger where needed
  - Remove assertions for console output on non-critical errors
  - Keep debugLogger assertions for fatal/network errors
  - Use HOME directory mocking for hermetic file system tests

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
tanzhenxin 2026-02-02 17:37:54 +08:00
parent 135df54f27
commit 89e3c2cd7a
64 changed files with 1240 additions and 2416 deletions

View file

@ -1,71 +0,0 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import util from 'node:util';
import type { ConsoleMessageItem } from '../types.js';
interface ConsolePatcherParams {
onNewMessage?: (message: Omit<ConsoleMessageItem, 'id'>) => void;
debugMode: boolean;
stderr?: boolean;
}
export class ConsolePatcher {
private originalConsoleLog = console.log;
private originalConsoleWarn = console.warn;
private originalConsoleError = console.error;
private originalConsoleDebug = console.debug;
private originalConsoleInfo = console.info;
private params: ConsolePatcherParams;
constructor(params: ConsolePatcherParams) {
this.params = params;
}
patch() {
console.log = this.patchConsoleMethod('log', this.originalConsoleLog);
console.warn = this.patchConsoleMethod('warn', this.originalConsoleWarn);
console.error = this.patchConsoleMethod('error', this.originalConsoleError);
console.debug = this.patchConsoleMethod('debug', this.originalConsoleDebug);
console.info = this.patchConsoleMethod('info', this.originalConsoleInfo);
}
cleanup = () => {
console.log = this.originalConsoleLog;
console.warn = this.originalConsoleWarn;
console.error = this.originalConsoleError;
console.debug = this.originalConsoleDebug;
console.info = this.originalConsoleInfo;
};
private formatArgs = (args: unknown[]): string => util.format(...args);
private patchConsoleMethod =
(
type: 'log' | 'warn' | 'error' | 'debug' | 'info',
originalMethod: (...args: unknown[]) => void,
) =>
(...args: unknown[]) => {
if (this.params.stderr) {
if (type !== 'debug' || this.params.debugMode) {
this.originalConsoleError(this.formatArgs(args));
}
} else {
if (this.params.debugMode) {
originalMethod.apply(console, args);
}
if (type !== 'debug' || this.params.debugMode) {
this.params.onNewMessage?.({
type,
content: this.formatArgs(args),
count: 1,
});
}
}
};
}