Skip to content

fix(auth): respect allowed onboarding tier - #29535

Open
Nisxzn wants to merge 3 commits into
google-gemini:mainfrom
Nisxzn:fix/license-validation-personal-account
Open

Nisxzn wants to merge 3 commits into
google-gemini:mainfrom
Nisxzn:fix/license-validation-personal-account

Conversation

@Nisxzn

@Nisxzn Nisxzn commented Sep 28, 2026 •

Copy link
Copy Markdown

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:

You do not have a valid license of this product

This change makes the CLI respect the tiers explicitly returned by the backend.

Details

  • Preserve the existing isDefault tier selection behavior.
  • When allowedTiers contains tiers but none is marked as default, use the first allowed tier.
  • Preserve the existing LEGACY fallback when no allowed tiers are returned.
  • Added regression tests covering the new behavior.

Related Issues

Fixes #29529

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker
  • Noted breaking changes (if any)

@Nisxzn
Nisxzn requested a review from a team as a code owner September 28, 2026 08:08
@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 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

  • Tier Selection Logic: Updated the onboarding tier selection to prioritize the first available tier from the backend response when no default tier is explicitly marked.
  • Legacy Fallback: Ensured that the legacy tier fallback remains active when the backend returns an empty or undefined list of allowed tiers.
  • Regression Testing: Added comprehensive unit tests to verify tier selection behavior across various scenarios, including empty lists and multiple non-default tiers.
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 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 .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 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

  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. ↩

@github-actions github-actions Bot added the size/m A medium sized PR label Sep 28, 2026
@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 60
  • Additions: +60
  • Deletions: -0
  • Files changed: 2

@google-cla

google-cla Bot commented Sep 28, 2026

Copy link
Copy Markdown

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.

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

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.

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.

Comment thread packages/core/src/code_assist/setup.ts Outdated
Comment on lines +321 to +323
if (res.allowedTiers && res.allowedTiers.length > 0) {
return res.allowedTiers[0];
}

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 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.

Suggested change
if (res.allowedTiers && res.allowedTiers.length > 0) {
return res.allowedTiers[0];
}
const firstTier = res.allowedTiers?.[0];
if (firstTier) {
return firstTier;
}
References
  1. When consuming an object, if a property is optional in its type definition (interface), callers must handle the undefined case (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', '');

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

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
  1. 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 gemini-cli Bot added the area/enterprise Issues related to Telemetry, Policy, Quota / Licensing label Sep 28, 2026
@Nisxzn

Nisxzn commented Sep 28, 2026

Copy link
Copy Markdown
Author

@gemini-cli-robot review

@gemini-cli

gemini-cli Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

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.

This branch has not been deployed

No deployments
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 size/m A medium sized PR status/pr-nudge-sent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

error you do not have a valid license of this product

1 participant