mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 22:21:22 -07:00
feat(ide): fallback to GEMINI_CLI_IDE_AUTH_TOKEN env var (#14843)
This commit is contained in:
@@ -59,6 +59,7 @@ describe('IdeClient', () => {
|
|||||||
delete process.env['GEMINI_CLI_IDE_SERVER_PORT'];
|
delete process.env['GEMINI_CLI_IDE_SERVER_PORT'];
|
||||||
delete process.env['GEMINI_CLI_IDE_SERVER_STDIO_COMMAND'];
|
delete process.env['GEMINI_CLI_IDE_SERVER_STDIO_COMMAND'];
|
||||||
delete process.env['GEMINI_CLI_IDE_SERVER_STDIO_ARGS'];
|
delete process.env['GEMINI_CLI_IDE_SERVER_STDIO_ARGS'];
|
||||||
|
delete process.env['GEMINI_CLI_IDE_AUTH_TOKEN'];
|
||||||
|
|
||||||
// Mock dependencies
|
// Mock dependencies
|
||||||
vi.spyOn(process, 'cwd').mockReturnValue('/test/workspace/sub-dir');
|
vi.spyOn(process, 'cwd').mockReturnValue('/test/workspace/sub-dir');
|
||||||
@@ -923,5 +924,35 @@ describe('IdeClient', () => {
|
|||||||
IDEConnectionStatus.Connected,
|
IDEConnectionStatus.Connected,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should connect with an auth token from environment variable if config file is missing', async () => {
|
||||||
|
vi.mocked(fs.promises.readFile).mockRejectedValue(
|
||||||
|
new Error('File not found'),
|
||||||
|
);
|
||||||
|
(
|
||||||
|
vi.mocked(fs.promises.readdir) as Mock<
|
||||||
|
(path: fs.PathLike) => Promise<string[]>
|
||||||
|
>
|
||||||
|
).mockResolvedValue([]);
|
||||||
|
process.env['GEMINI_CLI_IDE_SERVER_PORT'] = '9090';
|
||||||
|
process.env['GEMINI_CLI_IDE_AUTH_TOKEN'] = 'env-auth-token';
|
||||||
|
|
||||||
|
const ideClient = await IdeClient.getInstance();
|
||||||
|
await ideClient.connect();
|
||||||
|
|
||||||
|
expect(StreamableHTTPClientTransport).toHaveBeenCalledWith(
|
||||||
|
new URL('http://127.0.0.1:9090/mcp'),
|
||||||
|
expect.objectContaining({
|
||||||
|
requestInit: {
|
||||||
|
headers: {
|
||||||
|
Authorization: 'Bearer env-auth-token',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(ideClient.getConnectionStatus().status).toBe(
|
||||||
|
IDEConnectionStatus.Connected,
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -151,9 +151,10 @@ export class IdeClient {
|
|||||||
this.setState(IDEConnectionStatus.Connecting);
|
this.setState(IDEConnectionStatus.Connecting);
|
||||||
|
|
||||||
this.connectionConfig = await this.getConnectionConfigFromFile();
|
this.connectionConfig = await this.getConnectionConfigFromFile();
|
||||||
if (this.connectionConfig?.authToken) {
|
this.authToken =
|
||||||
this.authToken = this.connectionConfig.authToken;
|
this.connectionConfig?.authToken ??
|
||||||
}
|
process.env['GEMINI_CLI_IDE_AUTH_TOKEN'];
|
||||||
|
|
||||||
const workspacePath =
|
const workspacePath =
|
||||||
this.connectionConfig?.workspacePath ??
|
this.connectionConfig?.workspacePath ??
|
||||||
process.env['GEMINI_CLI_IDE_WORKSPACE_PATH'];
|
process.env['GEMINI_CLI_IDE_WORKSPACE_PATH'];
|
||||||
|
|||||||
Reference in New Issue
Block a user