mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
feat: add explicit license selection and status visibility (#6751)
This commit is contained in:
119
packages/cli/src/utils/license.test.ts
Normal file
119
packages/cli/src/utils/license.test.ts
Normal file
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { getLicenseDisplay } from './license.js';
|
||||
import { AuthType, UserTierId } from '@google/gemini-cli-core';
|
||||
|
||||
describe('getLicenseDisplay', () => {
|
||||
describe('Free Tier (Login with Google)', () => {
|
||||
it('should return Free Tier for LOGIN_WITH_GOOGLE', () => {
|
||||
expect(getLicenseDisplay(AuthType.LOGIN_WITH_GOOGLE)).toBe(
|
||||
'Free Tier (Login with Google)',
|
||||
);
|
||||
});
|
||||
|
||||
it('should ignore userTier for LOGIN_WITH_GOOGLE', () => {
|
||||
expect(
|
||||
getLicenseDisplay(AuthType.LOGIN_WITH_GOOGLE, UserTierId.STANDARD),
|
||||
).toBe('Free Tier (Login with Google)');
|
||||
expect(
|
||||
getLicenseDisplay(AuthType.LOGIN_WITH_GOOGLE, UserTierId.LEGACY),
|
||||
).toBe('Free Tier (Login with Google)');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Gemini Code Assist (Google Workspace)', () => {
|
||||
it('should return GCA Standard for LOGIN_WITH_GOOGLE_GCA with STANDARD tier', () => {
|
||||
expect(
|
||||
getLicenseDisplay(AuthType.LOGIN_WITH_GOOGLE_GCA, UserTierId.STANDARD),
|
||||
).toBe('Gemini Code Assist Standard (Google Workspace)');
|
||||
});
|
||||
|
||||
it('should return GCA Enterprise for LOGIN_WITH_GOOGLE_GCA with LEGACY tier', () => {
|
||||
expect(
|
||||
getLicenseDisplay(AuthType.LOGIN_WITH_GOOGLE_GCA, UserTierId.LEGACY),
|
||||
).toBe('Gemini Code Assist Enterprise (Google Workspace)');
|
||||
});
|
||||
|
||||
it('should return generic GCA for LOGIN_WITH_GOOGLE_GCA without tier', () => {
|
||||
expect(getLicenseDisplay(AuthType.LOGIN_WITH_GOOGLE_GCA)).toBe(
|
||||
'Gemini Code Assist (Google Workspace)',
|
||||
);
|
||||
});
|
||||
|
||||
it('should return generic GCA for LOGIN_WITH_GOOGLE_GCA with unknown tier', () => {
|
||||
expect(
|
||||
getLicenseDisplay(
|
||||
AuthType.LOGIN_WITH_GOOGLE_GCA,
|
||||
'unknown-tier' as UserTierId,
|
||||
),
|
||||
).toBe('Gemini Code Assist (Google Workspace)');
|
||||
});
|
||||
|
||||
it('should return generic GCA for LOGIN_WITH_GOOGLE_GCA with FREE tier', () => {
|
||||
expect(
|
||||
getLicenseDisplay(AuthType.LOGIN_WITH_GOOGLE_GCA, UserTierId.FREE),
|
||||
).toBe('Gemini Code Assist (Google Workspace)');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Gemini API Key', () => {
|
||||
it('should return Gemini API Key for USE_GEMINI', () => {
|
||||
expect(getLicenseDisplay(AuthType.USE_GEMINI)).toBe('Gemini API Key');
|
||||
});
|
||||
|
||||
it('should ignore userTier for USE_GEMINI', () => {
|
||||
expect(getLicenseDisplay(AuthType.USE_GEMINI, UserTierId.STANDARD)).toBe(
|
||||
'Gemini API Key',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Vertex AI', () => {
|
||||
it('should return Vertex AI for USE_VERTEX_AI', () => {
|
||||
expect(getLicenseDisplay(AuthType.USE_VERTEX_AI)).toBe('Vertex AI');
|
||||
});
|
||||
|
||||
it('should ignore userTier for USE_VERTEX_AI', () => {
|
||||
expect(getLicenseDisplay(AuthType.USE_VERTEX_AI, UserTierId.LEGACY)).toBe(
|
||||
'Vertex AI',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Cloud Shell', () => {
|
||||
it('should return Cloud Shell for CLOUD_SHELL', () => {
|
||||
expect(getLicenseDisplay(AuthType.CLOUD_SHELL)).toBe('Cloud Shell');
|
||||
});
|
||||
|
||||
it('should ignore userTier for CLOUD_SHELL', () => {
|
||||
expect(getLicenseDisplay(AuthType.CLOUD_SHELL, UserTierId.STANDARD)).toBe(
|
||||
'Cloud Shell',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Unknown auth types', () => {
|
||||
it('should return the auth type as-is for unknown values', () => {
|
||||
expect(getLicenseDisplay('custom-auth-type')).toBe('custom-auth-type');
|
||||
expect(getLicenseDisplay('oauth')).toBe('oauth');
|
||||
expect(getLicenseDisplay('unknown-auth')).toBe('unknown-auth');
|
||||
});
|
||||
|
||||
it('should handle undefined gracefully', () => {
|
||||
expect(getLicenseDisplay(undefined as unknown as string)).toBe(undefined);
|
||||
});
|
||||
|
||||
it('should handle null gracefully', () => {
|
||||
expect(getLicenseDisplay(null as unknown as string)).toBe(null);
|
||||
});
|
||||
|
||||
it('should handle empty string', () => {
|
||||
expect(getLicenseDisplay('')).toBe('');
|
||||
});
|
||||
});
|
||||
});
|
||||
43
packages/cli/src/utils/license.ts
Normal file
43
packages/cli/src/utils/license.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { AuthType, UserTierId } from '@google/gemini-cli-core';
|
||||
|
||||
/**
|
||||
* Get human-readable license display text based on auth type and user tier.
|
||||
* @param selectedAuthType - The authentication type selected by the user
|
||||
* @param userTier - Optional user tier information from the server
|
||||
* @returns Human-readable license information
|
||||
*/
|
||||
export function getLicenseDisplay(
|
||||
selectedAuthType: string,
|
||||
userTier?: UserTierId,
|
||||
): string {
|
||||
switch (selectedAuthType) {
|
||||
case AuthType.LOGIN_WITH_GOOGLE:
|
||||
return 'Free Tier (Login with Google)';
|
||||
|
||||
case AuthType.LOGIN_WITH_GOOGLE_GCA:
|
||||
if (userTier === UserTierId.STANDARD) {
|
||||
return 'Gemini Code Assist Standard (Google Workspace)';
|
||||
} else if (userTier === UserTierId.LEGACY) {
|
||||
return 'Gemini Code Assist Enterprise (Google Workspace)';
|
||||
}
|
||||
return 'Gemini Code Assist (Google Workspace)';
|
||||
|
||||
case AuthType.USE_GEMINI:
|
||||
return 'Gemini API Key';
|
||||
|
||||
case AuthType.USE_VERTEX_AI:
|
||||
return 'Vertex AI';
|
||||
|
||||
case AuthType.CLOUD_SHELL:
|
||||
return 'Cloud Shell';
|
||||
|
||||
default:
|
||||
return selectedAuthType;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user