fix(cli): skip console log/info in headless mode#22739
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request aims to prevent unnecessary console output from polluting the terminal when the CLI is run in headless mode. By introducing a new suppression mechanism in the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to suppress console output in headless modes, which is a good improvement for non-interactive use cases. The implementation is straightforward, adding a suppressConsoleOutput flag to ConsolePatcher and applying it in both interactive and non-interactive entry points. The changes are accompanied by new unit tests. I've found one issue in the new tests that should be addressed to ensure they correctly validate the new behavior.
|
Size Change: +161 B (0%) Total Size: 26.2 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Code Review
This pull request introduces a headlessMode to the ConsolePatcher utility, which suppresses console.log and console.info messages when active and not in debug mode. The main CLI entry point (gemini.tsx) now dynamically enables this mode based on isHeadlessMode(), while the non-interactive CLI (nonInteractiveCli.ts) always sets headlessMode: true. Corresponding integration tests and non-interactive CLI tests are updated to run in debug mode to ensure visibility of logs. A new comprehensive test file (ConsolePatcher.test.ts) has been added to validate the behavior of ConsolePatcher with the new headlessMode and existing stderr and debugMode parameters.
There was a problem hiding this comment.
Code Review
The pull request introduces a headlessMode parameter to the ConsolePatcher to control console output, specifically to suppress log and info messages when in headless mode and not in debug mode. This involved adding a new test file for ConsolePatcher, importing isHeadlessMode in gemini.tsx, and configuring ConsolePatcher with headlessMode in gemini.tsx and nonInteractiveCli.ts, along with adding --debug flags to integration tests and updating mock configurations. However, a critical issue was identified in gemini.tsx where the ConsolePatcher is incorrectly configured with stderr: true unconditionally, which would prevent console logs from reaching the UI's debug console. The reviewer suggests making stderr conditional based on isHeadlessMode() and simplifying the headlessMode assignment.
jackwotherspoon
left a comment
There was a problem hiding this comment.
LGTM ✅
Tested and works 😄
Summary
Skip output in headless mode to avoid polluting the terminal with raw console logs and info, unless debug mode is enabled.
Details
headlessModeparameter to ConsolePatcher.headlessModeis true anddebugModeis false,ConsolePatcherwill skip printing to the original console for type 'info' and 'log'.headlessModeinnonInteractiveCli.tsand conditionally ingemini.tsxbased on isHeadlessMode().ConsolePatcherto prevent regression.-debugto match expected text since in integration test it automatically treat it as headlessRelated Issues
Fixes #22168
How to Validate
--debugis used.Pre-Merge Checklist