mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-06-19 15:56:48 -07:00
feat(core): Support GDC air-gapped Service Identity after auth library update (#27956)
This commit is contained in:
committed by
GitHub
parent
83d7567329
commit
fbce3e51b6
@@ -508,13 +508,13 @@ describe('createContentGenerator', () => {
|
||||
|
||||
expect(GoogleGenAI).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
googleAuthOptions: {
|
||||
clientOptions: {
|
||||
transporterOptions: {
|
||||
googleAuthOptions: expect.objectContaining({
|
||||
clientOptions: expect.objectContaining({
|
||||
transporterOptions: expect.objectContaining({
|
||||
agent: expect.any(HttpsProxyAgent),
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -544,13 +544,13 @@ describe('createContentGenerator', () => {
|
||||
|
||||
expect(GoogleGenAI).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
googleAuthOptions: {
|
||||
clientOptions: {
|
||||
transporterOptions: {
|
||||
googleAuthOptions: expect.objectContaining({
|
||||
clientOptions: expect.objectContaining({
|
||||
transporterOptions: expect.objectContaining({
|
||||
agent: expect.any(HttpsProxyAgent),
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -582,13 +582,13 @@ describe('createContentGenerator', () => {
|
||||
|
||||
expect(GoogleGenAI).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
googleAuthOptions: {
|
||||
clientOptions: {
|
||||
transporterOptions: {
|
||||
googleAuthOptions: expect.objectContaining({
|
||||
clientOptions: expect.objectContaining({
|
||||
transporterOptions: expect.objectContaining({
|
||||
agent: expect.any(HttpProxyAgent),
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -618,13 +618,13 @@ describe('createContentGenerator', () => {
|
||||
|
||||
expect(GoogleGenAI).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
googleAuthOptions: {
|
||||
clientOptions: {
|
||||
transporterOptions: {
|
||||
googleAuthOptions: expect.objectContaining({
|
||||
clientOptions: expect.objectContaining({
|
||||
transporterOptions: expect.objectContaining({
|
||||
agent: expect.any(HttpsProxyAgent),
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -1003,6 +1003,38 @@ describe('createContentGenerator', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should inject apiEndpoint into googleAuthOptions.clientOptions when GOOGLE_VERTEX_BASE_URL is set', async () => {
|
||||
const mockConfig = {
|
||||
getModel: vi.fn().mockReturnValue('gemini-pro'),
|
||||
getProxy: vi.fn().mockReturnValue(undefined),
|
||||
getUsageStatisticsEnabled: () => false,
|
||||
getClientName: vi.fn().mockReturnValue(undefined),
|
||||
} as unknown as Config;
|
||||
|
||||
const mockGenerator = {
|
||||
models: {},
|
||||
} as unknown as GoogleGenAI;
|
||||
vi.mocked(GoogleGenAI).mockImplementation(() => mockGenerator as never);
|
||||
vi.stubEnv('GOOGLE_VERTEX_BASE_URL', 'https://vertex.test.local');
|
||||
|
||||
await createContentGenerator(
|
||||
{
|
||||
authType: AuthType.USE_VERTEX_AI,
|
||||
},
|
||||
mockConfig,
|
||||
);
|
||||
|
||||
expect(GoogleGenAI).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
googleAuthOptions: expect.objectContaining({
|
||||
clientOptions: expect.objectContaining({
|
||||
apiEndpoint: 'https://vertex.test.local',
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should prefer an explicit baseUrl over GOOGLE_GEMINI_BASE_URL', async () => {
|
||||
const mockConfig = {
|
||||
getModel: vi.fn().mockReturnValue('gemini-pro'),
|
||||
|
||||
@@ -361,7 +361,8 @@ export async function createContentGenerator(
|
||||
? new HttpProxyAgent(proxyUrl)
|
||||
: new HttpsProxyAgent(proxyUrl)
|
||||
: undefined;
|
||||
|
||||
const useVertex =
|
||||
config.vertexai ?? config.authType === AuthType.USE_VERTEX_AI;
|
||||
const googleGenAI = new GoogleGenAI({
|
||||
apiKey:
|
||||
config.authType === AuthType.GATEWAY
|
||||
@@ -372,10 +373,17 @@ export async function createContentGenerator(
|
||||
vertexai: config.vertexai ?? config.authType === AuthType.USE_VERTEX_AI,
|
||||
httpOptions,
|
||||
...(apiVersionEnv && { apiVersion: apiVersionEnv }),
|
||||
...(proxyAgent && {
|
||||
// Merge proxy and GDCH endpoint into googleAuthOptions if either exists
|
||||
...((proxyAgent || (useVertex && baseUrl)) && {
|
||||
googleAuthOptions: {
|
||||
clientOptions: {
|
||||
transporterOptions: { agent: proxyAgent },
|
||||
...(proxyAgent && {
|
||||
transporterOptions: { agent: proxyAgent },
|
||||
}),
|
||||
...(useVertex &&
|
||||
baseUrl && {
|
||||
apiEndpoint: baseUrl,
|
||||
}),
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user