feat: add explicit license selection and status visibility (#6751)

This commit is contained in:
jason
2025-08-23 05:01:01 +09:00
committed by GitHub
parent bb8a23ae80
commit 5030ced9e1
13 changed files with 382 additions and 40 deletions

View File

@@ -6,12 +6,12 @@
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
import { aboutCommand } from './aboutCommand.js';
import { type CommandContext } from './types.js';
import type { CommandContext } from './types.js';
import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
import * as versionUtils from '../../utils/version.js';
import { MessageType } from '../types.js';
import { IdeClient } from '../../../../core/src/ide/ide-client.js';
import type { IdeClient } from '@google/gemini-cli-core';
vi.mock('../../utils/version.js', () => ({
getCliVersion: vi.fn(),
@@ -29,10 +29,11 @@ describe('aboutCommand', () => {
getModel: vi.fn(),
getIdeClient: vi.fn(),
getIdeMode: vi.fn().mockReturnValue(true),
getGeminiClient: vi.fn(),
},
settings: {
merged: {
selectedAuthType: 'test-auth',
selectedAuthType: 'oauth-gca',
},
},
},
@@ -52,6 +53,11 @@ describe('aboutCommand', () => {
vi.spyOn(mockContext.services.config!, 'getIdeClient').mockReturnValue({
getDetectedIdeDisplayName: vi.fn().mockReturnValue('test-ide'),
} as Partial<IdeClient> as IdeClient);
vi.spyOn(mockContext.services.config!, 'getGeminiClient').mockReturnValue({
getUserTier: vi.fn().mockReturnValue(undefined),
} as unknown as ReturnType<
NonNullable<typeof mockContext.services.config>['getGeminiClient']
>);
});
afterEach(() => {
@@ -83,9 +89,10 @@ describe('aboutCommand', () => {
osVersion: 'test-os',
sandboxEnv: 'no sandbox',
modelVersion: 'test-model',
selectedAuthType: 'test-auth',
selectedAuthType: 'oauth-gca',
gcpProject: 'test-gcp-project',
ideClient: 'test-ide',
userTier: undefined,
},
expect.any(Number),
);
@@ -125,11 +132,14 @@ describe('aboutCommand', () => {
});
it('should not show ide client when it is not detected', async () => {
// Change to oauth type that doesn't use GCP project
mockContext.services.settings.merged.selectedAuthType = 'oauth';
vi.spyOn(mockContext.services.config!, 'getIdeClient').mockReturnValue({
getDetectedIdeDisplayName: vi.fn().mockReturnValue(undefined),
} as Partial<IdeClient> as IdeClient);
process.env.SANDBOX = '';
process.env['SANDBOX'] = '';
if (!aboutCommand.action) {
throw new Error('The about command must have an action.');
}
@@ -143,8 +153,8 @@ describe('aboutCommand', () => {
osVersion: 'test-os',
sandboxEnv: 'no sandbox',
modelVersion: 'test-model',
selectedAuthType: 'test-auth',
gcpProject: 'test-gcp-project',
selectedAuthType: 'oauth',
gcpProject: '',
ideClient: '',
}),
expect.any(Number),

View File

@@ -27,11 +27,18 @@ export const aboutCommand: SlashCommand = {
const cliVersion = await getCliVersion();
const selectedAuthType =
context.services.settings.merged.selectedAuthType || '';
const gcpProject = process.env['GOOGLE_CLOUD_PROJECT'] || '';
// Only show GCP Project for auth types that actually use it
const gcpProject =
selectedAuthType === 'oauth-gca' ||
selectedAuthType === 'vertex-ai' ||
selectedAuthType === 'cloud-shell'
? process.env['GOOGLE_CLOUD_PROJECT'] || ''
: '';
const ideClient =
(context.services.config?.getIdeMode() &&
context.services.config?.getIdeClient()?.getDetectedIdeDisplayName()) ||
'';
const userTier = context.services.config?.getGeminiClient()?.getUserTier();
const aboutItem: Omit<HistoryItemAbout, 'id'> = {
type: MessageType.ABOUT,
@@ -42,6 +49,7 @@ export const aboutCommand: SlashCommand = {
selectedAuthType,
gcpProject,
ideClient,
userTier,
};
context.ui.addItem(aboutItem, Date.now());

View File

@@ -8,6 +8,8 @@ import React from 'react';
import { Box, Text } from 'ink';
import { Colors } from '../colors.js';
import { GIT_COMMIT_INFO } from '../../generated/git-commit.js';
import { UserTierId } from '@google/gemini-cli-core';
import { getLicenseDisplay } from '../../utils/license.js';
interface AboutBoxProps {
cliVersion: string;
@@ -17,6 +19,7 @@ interface AboutBoxProps {
selectedAuthType: string;
gcpProject: string;
ideClient: string;
userTier?: UserTierId;
}
export const AboutBox: React.FC<AboutBoxProps> = ({
@@ -27,6 +30,7 @@ export const AboutBox: React.FC<AboutBoxProps> = ({
selectedAuthType,
gcpProject,
ideClient,
userTier,
}) => (
<Box
borderStyle="round"
@@ -105,6 +109,16 @@ export const AboutBox: React.FC<AboutBoxProps> = ({
</Text>
</Box>
</Box>
<Box flexDirection="row">
<Box width="35%">
<Text bold color={Colors.LightBlue}>
License
</Text>
</Box>
<Box>
<Text>{getLicenseDisplay(selectedAuthType, userTier)}</Text>
</Box>
</Box>
{gcpProject && (
<Box flexDirection="row">
<Box width="35%">

View File

@@ -62,9 +62,14 @@ export function AuthDialog({
});
const items = [
{
label: 'Login with Google',
label: 'Login with Google - Free Tier',
value: AuthType.LOGIN_WITH_GOOGLE,
},
{
label:
'Login with Google - Gemini Code Assist (Requires GOOGLE_CLOUD_PROJECT)',
value: AuthType.LOGIN_WITH_GOOGLE_GCA,
},
...(process.env['CLOUD_SHELL'] === 'true'
? [
{

View File

@@ -74,6 +74,7 @@ export const HistoryItemDisplay: React.FC<HistoryItemDisplayProps> = ({
selectedAuthType={item.selectedAuthType}
gcpProject={item.gcpProject}
ideClient={item.ideClient}
userTier={item.userTier}
/>
)}
{item.type === 'help' && commands && <Help commands={commands} />}

View File

@@ -7,6 +7,7 @@
import {
ToolCallConfirmationDetails,
ToolResultDisplay,
UserTierId,
} from '@google/gemini-cli-core';
// Only defining the state enum needed by the UI
@@ -96,6 +97,7 @@ export type HistoryItemAbout = HistoryItemBase & {
selectedAuthType: string;
gcpProject: string;
ideClient: string;
userTier?: UserTierId;
};
export type HistoryItemHelp = HistoryItemBase & {