fix(test): silence policy-engine integration test noise#23465
fix(test): silence policy-engine integration test noise#23465Fikri-20 wants to merge 2 commits intogoogle-gemini:mainfrom
Conversation
Mock console.debug and console.log in beforeEach to suppress debugLogger output that was flooding stdout with ~300 lines of [PolicyEngine.check] trace per run.
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 significantly reduces the console output noise generated by the Highlights
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. Footnotes
|
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request aims to silence noisy debug output from the policy engine integration tests. The approach of spying on console.debug and console.log in beforeEach is correct. However, the use of vi.restoreAllMocks() in afterEach introduces a critical issue by resetting module-level mocks, which can break test isolation. I've provided a suggestion to fix this. I've adjusted the severity to 'high'.
| afterEach(() => vi.unstubAllEnvs()); | ||
| afterEach(() => { | ||
| vi.unstubAllEnvs(); | ||
| vi.restoreAllMocks(); |
There was a problem hiding this comment.
Using vi.restoreAllMocks() is too broad and will unintentionally restore the module-level mock for @google/gemini-cli-core (defined with vi.mock at the top of this file). This breaks test isolation for subsequent tests in this suite, as they will no longer use the mocked Storage methods and could interact with the real file system.
Since the console spies are re-created in beforeEach for every test, you can simply remove this line. The spies will not leak to other test files, and not restoring them after the last test in this suite is generally acceptable within a test runner environment.
There was a problem hiding this comment.
Good catch — removed vi.restoreAllMocks(). The spies get re-created each beforeEach anyway so no cleanup needed.
policy-engine.integration.test.tsdumps ~300 lines of[PolicyEngine.check]debug output to stdout on every run becausedebugLoggerroutes throughconsole.debug/console.logand neither was mocked.Fixed by spying on
console.debugandconsole.loginbeforeEachand restoring inafterEach. All 19 tests still pass, zero stdout noise.Before (325 lines)
After (13 lines)
Relates to #23328.