refactor(core): replace magic numbers with named constants in policy …#20573
refactor(core): replace magic numbers with named constants in policy …#20573cc-fuyu wants to merge 1 commit intogoogle-gemini:mainfrom
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 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
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
|
|
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 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.
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.