Send the model and CLI version with the user agent (#14865)

This commit is contained in:
Christian Gunderman
2025-12-09 16:38:33 -08:00
committed by GitHub
parent d90356e8a3
commit d2a6b30398
14 changed files with 74 additions and 50 deletions

View File

@@ -6,6 +6,7 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { ReleaseChannel, getReleaseChannel } from '../../utils/channel.js';
import { getVersion } from '../../utils/version.js';
// Mock dependencies before importing the module under test
vi.mock('../../utils/channel.js', async () => {
@@ -16,6 +17,10 @@ vi.mock('../../utils/channel.js', async () => {
};
});
vi.mock('../../utils/version.js', async () => ({
getVersion: vi.fn(),
}));
describe('client_metadata', () => {
const originalPlatform = process.platform;
const originalArch = process.arch;
@@ -29,6 +34,7 @@ describe('client_metadata', () => {
await import('./client_metadata.js');
// Provide a default mock implementation for each test
vi.mocked(getReleaseChannel).mockResolvedValue(ReleaseChannel.STABLE);
vi.mocked(getVersion).mockResolvedValue('0.0.0');
});
afterEach(() => {
@@ -64,24 +70,14 @@ describe('client_metadata', () => {
});
describe('getClientMetadata', () => {
it('should use CLI_VERSION for ideVersion if set', async () => {
process.env['CLI_VERSION'] = '1.2.3';
Object.defineProperty(process, 'version', { value: 'v18.0.0' });
it('should use version from getCliVersion for ideVersion', async () => {
vi.mocked(getVersion).mockResolvedValue('1.2.3');
const { getClientMetadata } = await import('./client_metadata.js');
const metadata = await getClientMetadata();
expect(metadata.ideVersion).toBe('1.2.3');
});
it('should use process.version for ideVersion as a fallback', async () => {
delete process.env['CLI_VERSION'];
Object.defineProperty(process, 'version', { value: 'v20.0.0' });
const { getClientMetadata } = await import('./client_metadata.js');
const metadata = await getClientMetadata();
expect(metadata.ideVersion).toBe('v20.0.0');
});
it('should call getReleaseChannel to get the update channel', async () => {
vi.mocked(getReleaseChannel).mockResolvedValue(ReleaseChannel.NIGHTLY);
const { getClientMetadata } = await import('./client_metadata.js');

View File

@@ -8,6 +8,7 @@ import { getReleaseChannel } from '../../utils/channel.js';
import type { ClientMetadata, ClientMetadataPlatform } from '../types.js';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
import { getVersion } from '../../utils/version.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
@@ -47,7 +48,7 @@ export async function getClientMetadata(): Promise<ClientMetadata> {
clientMetadataPromise = (async () => ({
ideName: 'IDE_UNSPECIFIED',
pluginType: 'GEMINI',
ideVersion: process.env['CLI_VERSION'] || process.version,
ideVersion: await getVersion(),
platform: getPlatform(),
updateChannel: await getReleaseChannel(__dirname),
}))();