mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 22:21:22 -07:00
fix(core): propagate User-Agent header to setup-phase CodeAssist API calls (#19182)
This commit is contained in:
@@ -64,6 +64,7 @@ describe('codeAssist', () => {
|
||||
expect(setupUser).toHaveBeenCalledWith(
|
||||
mockAuthClient,
|
||||
mockValidationHandler,
|
||||
httpOptions,
|
||||
);
|
||||
expect(MockedCodeAssistServer).toHaveBeenCalledWith(
|
||||
mockAuthClient,
|
||||
@@ -93,6 +94,7 @@ describe('codeAssist', () => {
|
||||
expect(setupUser).toHaveBeenCalledWith(
|
||||
mockAuthClient,
|
||||
mockValidationHandler,
|
||||
httpOptions,
|
||||
);
|
||||
expect(MockedCodeAssistServer).toHaveBeenCalledWith(
|
||||
mockAuthClient,
|
||||
|
||||
@@ -24,7 +24,11 @@ export async function createCodeAssistContentGenerator(
|
||||
authType === AuthType.COMPUTE_ADC
|
||||
) {
|
||||
const authClient = await getOauthClient(authType, config);
|
||||
const userData = await setupUser(authClient, config.getValidationHandler());
|
||||
const userData = await setupUser(
|
||||
authClient,
|
||||
config.getValidationHandler(),
|
||||
httpOptions,
|
||||
);
|
||||
return new CodeAssistServer(
|
||||
authClient,
|
||||
userData.projectId,
|
||||
|
||||
@@ -77,6 +77,27 @@ describe('setupUser for existing user', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should pass httpOptions to CodeAssistServer when provided', async () => {
|
||||
vi.stubEnv('GOOGLE_CLOUD_PROJECT', 'test-project');
|
||||
mockLoad.mockResolvedValue({
|
||||
currentTier: mockPaidTier,
|
||||
});
|
||||
const httpOptions = {
|
||||
headers: {
|
||||
'User-Agent': 'GeminiCLI/1.0.0/gemini-2.0-flash (darwin; arm64)',
|
||||
},
|
||||
};
|
||||
await setupUser({} as OAuth2Client, undefined, httpOptions);
|
||||
expect(CodeAssistServer).toHaveBeenCalledWith(
|
||||
{},
|
||||
'test-project',
|
||||
httpOptions,
|
||||
'',
|
||||
undefined,
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
|
||||
it('should ignore GOOGLE_CLOUD_PROJECT when project from server is set', async () => {
|
||||
vi.stubEnv('GOOGLE_CLOUD_PROJECT', 'test-project');
|
||||
mockLoad.mockResolvedValue({
|
||||
|
||||
@@ -12,6 +12,7 @@ import type {
|
||||
OnboardUserRequest,
|
||||
} from './types.js';
|
||||
import { UserTierId, IneligibleTierReasonCode } from './types.js';
|
||||
import type { HttpOptions } from './server.js';
|
||||
import { CodeAssistServer } from './server.js';
|
||||
import type { AuthClient } from 'google-auth-library';
|
||||
import type { ValidationHandler } from '../fallback/types.js';
|
||||
@@ -77,6 +78,7 @@ export interface UserData {
|
||||
export async function setupUser(
|
||||
client: AuthClient,
|
||||
validationHandler?: ValidationHandler,
|
||||
httpOptions: HttpOptions = {},
|
||||
): Promise<UserData> {
|
||||
const projectId =
|
||||
process.env['GOOGLE_CLOUD_PROJECT'] ||
|
||||
@@ -85,7 +87,7 @@ export async function setupUser(
|
||||
const caServer = new CodeAssistServer(
|
||||
client,
|
||||
projectId,
|
||||
{},
|
||||
httpOptions,
|
||||
'',
|
||||
undefined,
|
||||
undefined,
|
||||
|
||||
Reference in New Issue
Block a user