mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-19 08:14:35 -07:00
fix(cli): conditionally suppress console output in headless and non-interactive modes
This commit is contained in:
@@ -272,7 +272,7 @@ export async function main() {
|
||||
const isDebugMode = cliConfig.isDebugMode(argv);
|
||||
const consolePatcher = new ConsolePatcher({
|
||||
stderr: true,
|
||||
suppressConsoleOutput: isHeadlessMode() ? true : false,
|
||||
suppressConsoleOutput: isHeadlessMode() && !isDebugMode,
|
||||
debugMode: isDebugMode,
|
||||
onNewMessage: (msg) => {
|
||||
coreEvents.emitConsoleLog(msg.type, msg.content);
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
CoreEvent,
|
||||
createWorkingStdio,
|
||||
recordToolCallInteractions,
|
||||
isHeadlessMode,
|
||||
ToolErrorType,
|
||||
Scheduler,
|
||||
ROOT_SCHEDULER_ID,
|
||||
@@ -63,9 +64,10 @@ export async function runNonInteractive({
|
||||
resumedSessionData,
|
||||
}: RunNonInteractiveParams): Promise<void> {
|
||||
return promptIdContext.run(prompt_id, async () => {
|
||||
const suppressConsoleOutput = isHeadlessMode() && !config.getDebugMode();
|
||||
const consolePatcher = new ConsolePatcher({
|
||||
stderr: true,
|
||||
suppressConsoleOutput: true,
|
||||
suppressConsoleOutput,
|
||||
debugMode: config.getDebugMode(),
|
||||
onNewMessage: (msg) => {
|
||||
coreEvents.emitConsoleLog(msg.type, msg.content);
|
||||
|
||||
@@ -43,6 +43,26 @@ describe('ConsolePatcher', () => {
|
||||
console.error = originalError;
|
||||
});
|
||||
|
||||
it('should NOT suppress console.error even when suppressConsoleOutput is true', () => {
|
||||
const originalError = console.error;
|
||||
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
||||
|
||||
patcher = new ConsolePatcher({
|
||||
debugMode: false,
|
||||
suppressConsoleOutput: true,
|
||||
stderr: true,
|
||||
});
|
||||
patcher.patch();
|
||||
|
||||
console.error('test error');
|
||||
|
||||
expect(errorSpy).toHaveBeenCalled();
|
||||
|
||||
patcher.cleanup();
|
||||
errorSpy.mockRestore();
|
||||
console.error = originalError;
|
||||
});
|
||||
|
||||
it('should NOT suppress output when suppressConsoleOutput is true but debugMode is true', () => {
|
||||
const originalError = console.error;
|
||||
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
||||
|
||||
@@ -50,7 +50,11 @@ export class ConsolePatcher {
|
||||
private patchConsoleMethod =
|
||||
(type: 'log' | 'warn' | 'error' | 'debug' | 'info') =>
|
||||
(...args: unknown[]) => {
|
||||
if (this.params.suppressConsoleOutput && !this.params.debugMode) {
|
||||
if (
|
||||
this.params.suppressConsoleOutput &&
|
||||
!this.params.debugMode &&
|
||||
type !== 'error'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user