Skip to content

fix(test): silence policy-engine integration test noise#23465

Open
Fikri-20 wants to merge 2 commits intogoogle-gemini:mainfrom
Fikri-20:fix/silence-policy-engine-test-noise
Open

fix(test): silence policy-engine integration test noise#23465
Fikri-20 wants to merge 2 commits intogoogle-gemini:mainfrom
Fikri-20:fix/silence-policy-engine-test-noise

Conversation

@Fikri-20
Copy link
Copy Markdown

policy-engine.integration.test.ts dumps ~300 lines of [PolicyEngine.check] debug output to stdout on every run because debugLogger routes through console.debug/console.log and neither was mocked.

Fixed by spying on console.debug and console.log in beforeEach and restoring in afterEach. All 19 tests still pass, zero stdout noise.

Before (325 lines)

stdout | ...should create a working PolicyEngine from basic settings
[PolicyEngine.check] toolCall.name: run_shell_command, stringifiedArgs: undefined
[PolicyEngine.check] MATCHED rule: toolName=run_shell_command, decision=allow, priority=4.3, argsPattern=none

stdout | ...should create a working PolicyEngine from basic settings
[PolicyEngine.check] toolCall.name: write_file, stringifiedArgs: undefined
[PolicyEngine.check] MATCHED rule: toolName=write_file, decision=deny, priority=4.4, argsPattern=none
... (300+ more lines)

After (13 lines)

 ✓ src/config/policy-engine.integration.test.ts (19 tests) 206ms

 Test Files  1 passed (1)
      Tests  19 passed (19)

Relates to #23328.

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.
@Fikri-20 Fikri-20 requested a review from a team as a code owner March 22, 2026 17:27
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 policy-engine.integration.test.ts file during test runs. This improvement enhances the readability of test results by preventing debug messages from cluttering the stdout, making it easier to identify relevant test outcomes and focus on actual test failures or successes.

Highlights

  • Test Output Reduction: Silenced excessive debug output from policy-engine.integration.test.ts by mocking console.debug and console.log during tests.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@google-cla
Copy link
Copy Markdown

google-cla bot commented Mar 22, 2026

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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — removed vi.restoreAllMocks(). The spies get re-created each beforeEach anyway so no cleanup needed.

@gemini-cli gemini-cli bot added area/platform Issues related to Build infra, Release mgmt, Testing, Eval infra, Capacity, Quota mgmt 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/platform Issues related to Build infra, Release mgmt, Testing, Eval infra, Capacity, Quota mgmt 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant