Repository navigation
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 addresses an issue where the CLI incorrectly defaulted to a legacy tier when the Code Assist API provided valid onboarding tiers without a designated default. By modifying the selection logic to favor the first available tier in such cases, the CLI now correctly handles user account licensing, preventing unnecessary 'invalid license' errors for personal or free accounts. 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 the 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 counterproductive. 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
|
|
📊 PR Size: size/M
|
|
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 updates the user onboarding logic to fallback to the first allowed tier when multiple tiers exist and none are marked as default, and adds corresponding unit tests. The feedback suggests improving the robustness of the fallback logic by using optional chaining to safely access the first allowed tier, and stubbing both GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_PROJECT_ID in tests to prevent potential test leakage.
| if (res.allowedTiers && res.allowedTiers.length > 0) { | ||
| return res.allowedTiers[0]; | ||
| } |
There was a problem hiding this comment.
Using optional chaining res.allowedTiers?.[0] is more robust and idiomatic. It safely handles cases where allowedTiers is null, undefined, or contains nullish elements, preventing potential runtime TypeErrors when properties are accessed on the returned tier.
| if (res.allowedTiers && res.allowedTiers.length > 0) { | |
| return res.allowedTiers[0]; | |
| } | |
| const firstTier = res.allowedTiers?.[0]; | |
| if (firstTier) { | |
| return firstTier; | |
| } |
References
- When consuming an object, if a property is optional in its type definition (interface), callers must handle the
undefinedcase (e.g., by providing a default with??). Do not rely on the implementation details of the function that creates the object to always provide a value, as this can change. Code against the interface contract.
| }); | ||
|
|
||
| it('should onboard using FREE when allowedTiers contains FREE without isDefault', async () => { | ||
| vi.stubEnv('GOOGLE_CLOUD_PROJECT', ''); |
There was a problem hiding this comment.
To prevent test leakage and ensure reliable test execution in environments where GOOGLE_CLOUD_PROJECT_ID might be set, stub both GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_PROJECT_ID to empty strings. Since setupUser falls back to GOOGLE_CLOUD_PROJECT_ID if GOOGLE_CLOUD_PROJECT is empty, failing to stub both can lead to unexpected test failures.
vi.stubEnv('GOOGLE_CLOUD_PROJECT', '');
vi.stubEnv('GOOGLE_CLOUD_PROJECT_ID', '');References
- When testing code that depends on environment variables, use vi.stubEnv('NAME', 'value') and avoid modifying process.env directly to prevent test leakage. To unset a variable, use an empty string vi.stubEnv('NAME', ''). (link)
|
@gemini-cli-robot review |
|
Hi there! Thank you for your interest in contributing to Gemini CLI. To ensure we maintain high code quality and focus on our prioritized roadmap, we only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. This PR will be closed in 7 days if it remains without that designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding. |
Summary
Fixes #29529.
When the Code Assist API returns allowed onboarding tiers without marking
one of them as the default, the CLI currently falls back to the legacy tier.
This can cause a valid personal/free account to receive:
This change makes the CLI respect the tiers explicitly returned by the backend.
Details
isDefaulttier selection behavior.allowedTierscontains tiers but none is marked as default, use the first allowed tier.LEGACYfallback when no allowed tiers are returned.Related Issues
Fixes #29529
Pre-Merge Checklist