fix(core): propagate User-Agent header to setup-phase CodeAssist API calls (#19182)

This commit is contained in:
Gaurav
2026-02-15 19:20:22 -08:00
committed by GitHub
parent 6eec9f3350
commit 8979fc5f6a
4 changed files with 31 additions and 2 deletions

View File

@@ -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,

View File

@@ -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,

View File

@@ -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({

View File

@@ -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,