Skip to content

refactor(core): replace magic numbers with named constants in policy …#20573

Open
cc-fuyu wants to merge 1 commit intogoogle-gemini:mainfrom
cc-fuyu:refactor-policy-test-magic-numbers
Open

refactor(core): replace magic numbers with named constants in policy …#20573
cc-fuyu wants to merge 1 commit intogoogle-gemini:mainfrom
cc-fuyu:refactor-policy-test-magic-numbers

Conversation

@cc-fuyu
Copy link

@cc-fuyu cc-fuyu commented Feb 27, 2026

The policy config tests in config.test.ts had a bunch of hardcoded priority numbers like 4.3, 4.9, 1.998 etc. scattered across 22 test cases, and if you weren't already familiar with the priority system it was pretty hard to tell what each number meant without reading the comments. The source file config.ts already exports nicely named constants like ALLOWED_TOOLS_FLAG_PRIORITY, MCP_EXCLUDED_PRIORITY, DEFAULT_POLICY_TIER and so on, so I just imported those and replaced all the magic numbers with the corresponding constants.

This way if the priority values ever change in the source, the tests won't need manual updates, and it's also way easier to understand what each assertion is actually checking. All 22 existing tests still pass with no changes to test logic.

Closes #20464.

@cc-fuyu cc-fuyu requested a review from a team as a code owner February 27, 2026 16:53
@gemini-code-assist
Copy link
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 refactors the policy configuration tests to eliminate magic numbers by introducing named constants for policy priority values. This change significantly enhances the readability and maintainability of the test suite, making it easier for developers to understand the intent behind specific priority assignments and reducing the likelihood of errors when future policy logic changes occur.

Highlights

  • Refactor Policy Configuration Tests: Replaced hardcoded numeric priority values in config.test.ts with descriptive named constants imported from config.js.
  • Improved Readability and Maintainability: The use of named constants like ALLOWED_TOOLS_FLAG_PRIORITY, EXCLUDE_TOOLS_FLAG_PRIORITY, and DEFAULT_POLICY_TIER makes the policy priority logic clearer and easier to understand.
  • Enhanced Test Clarity: Updated comments within the tests to reflect the new constant names, further improving the clarity of priority assignments.
Changelog
  • packages/core/src/policy/config.test.ts
    • Replaced magic numbers with named constants for policy priority values.
    • Updated comments to reflect the use of new constants.
Activity
  • The pull request description is a template, indicating no specific human activity or comments have been made yet.
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.

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

  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

google-cla bot commented Feb 27, 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
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 effectively refactors the config.test.ts file by replacing various magic numbers with named constants imported from config.ts. This change significantly improves the readability and maintainability of the policy priority tests. By using named constants, the code becomes more self-documenting and less prone to errors if the underlying priority values need to be adjusted in the future. The changes are well-implemented and align perfectly with the goal of reducing magic numbers in the codebase.

@gemini-cli gemini-cli bot added the area/enterprise Issues related to Telemetry, Policy, Quota / Licensing label Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/enterprise Issues related to Telemetry, Policy, Quota / Licensing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor policy tests to use tier constants instead of hardcoded integers

1 participant