# 🚀 Sync Gemini CLI v0.2.1 - Major Feature Update (#483)

This commit is contained in:
tanzhenxin
2025-09-01 14:48:55 +08:00
committed by GitHub
parent 1610c1586e
commit 2572faf726
292 changed files with 19401 additions and 5941 deletions

View File

@@ -4,11 +4,11 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { render } from 'ink-testing-library';
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { AuthDialog } from './AuthDialog.js';
import { LoadedSettings, SettingScope } from '../../config/settings.js';
import { AuthType } from '@qwen-code/qwen-code-core';
import { renderWithProviders } from '../../test-utils/render.js';
describe('AuthDialog', () => {
const wait = (ms = 50) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -17,8 +17,8 @@ describe('AuthDialog', () => {
beforeEach(() => {
originalEnv = { ...process.env };
process.env.GEMINI_API_KEY = '';
process.env.GEMINI_DEFAULT_AUTH_TYPE = '';
process.env['GEMINI_API_KEY'] = '';
process.env['GEMINI_DEFAULT_AUTH_TYPE'] = '';
vi.clearAllMocks();
});
@@ -27,7 +27,7 @@ describe('AuthDialog', () => {
});
it('should show an error if the initial auth type is invalid', () => {
process.env.GEMINI_API_KEY = '';
process.env['GEMINI_API_KEY'] = '';
const settings: LoadedSettings = new LoadedSettings(
{
@@ -47,7 +47,7 @@ describe('AuthDialog', () => {
[],
);
const { lastFrame } = render(
const { lastFrame } = renderWithProviders(
<AuthDialog
onSelect={() => {}}
settings={settings}
@@ -62,7 +62,7 @@ describe('AuthDialog', () => {
describe('GEMINI_API_KEY environment variable', () => {
it('should detect GEMINI_API_KEY environment variable', () => {
process.env.GEMINI_API_KEY = 'foobar';
process.env['GEMINI_API_KEY'] = 'foobar';
const settings: LoadedSettings = new LoadedSettings(
{
@@ -84,7 +84,7 @@ describe('AuthDialog', () => {
[],
);
const { lastFrame } = render(
const { lastFrame } = renderWithProviders(
<AuthDialog onSelect={() => {}} settings={settings} />,
);
@@ -94,8 +94,8 @@ describe('AuthDialog', () => {
});
it('should not show the GEMINI_API_KEY message if GEMINI_DEFAULT_AUTH_TYPE is set to something else', () => {
process.env.GEMINI_API_KEY = 'foobar';
process.env.GEMINI_DEFAULT_AUTH_TYPE = AuthType.LOGIN_WITH_GOOGLE;
process.env['GEMINI_API_KEY'] = 'foobar';
process.env['GEMINI_DEFAULT_AUTH_TYPE'] = AuthType.LOGIN_WITH_GOOGLE;
const settings: LoadedSettings = new LoadedSettings(
{
@@ -117,7 +117,7 @@ describe('AuthDialog', () => {
[],
);
const { lastFrame } = render(
const { lastFrame } = renderWithProviders(
<AuthDialog onSelect={() => {}} settings={settings} />,
);
@@ -127,8 +127,8 @@ describe('AuthDialog', () => {
});
it('should show the GEMINI_API_KEY message if GEMINI_DEFAULT_AUTH_TYPE is set to use api key', () => {
process.env.GEMINI_API_KEY = 'foobar';
process.env.GEMINI_DEFAULT_AUTH_TYPE = AuthType.USE_GEMINI;
process.env['GEMINI_API_KEY'] = 'foobar';
process.env['GEMINI_DEFAULT_AUTH_TYPE'] = AuthType.USE_GEMINI;
const settings: LoadedSettings = new LoadedSettings(
{
@@ -150,7 +150,7 @@ describe('AuthDialog', () => {
[],
);
const { lastFrame } = render(
const { lastFrame } = renderWithProviders(
<AuthDialog onSelect={() => {}} settings={settings} />,
);
@@ -162,7 +162,7 @@ describe('AuthDialog', () => {
describe('GEMINI_DEFAULT_AUTH_TYPE environment variable', () => {
it('should select the auth type specified by GEMINI_DEFAULT_AUTH_TYPE', () => {
process.env.GEMINI_DEFAULT_AUTH_TYPE = AuthType.USE_OPENAI;
process.env['GEMINI_DEFAULT_AUTH_TYPE'] = AuthType.USE_OPENAI;
const settings: LoadedSettings = new LoadedSettings(
{
@@ -184,7 +184,7 @@ describe('AuthDialog', () => {
[],
);
const { lastFrame } = render(
const { lastFrame } = renderWithProviders(
<AuthDialog onSelect={() => {}} settings={settings} />,
);
@@ -213,7 +213,7 @@ describe('AuthDialog', () => {
[],
);
const { lastFrame } = render(
const { lastFrame } = renderWithProviders(
<AuthDialog onSelect={() => {}} settings={settings} />,
);
@@ -222,7 +222,7 @@ describe('AuthDialog', () => {
});
it('should show an error and fall back to default if GEMINI_DEFAULT_AUTH_TYPE is invalid', () => {
process.env.GEMINI_DEFAULT_AUTH_TYPE = 'invalid-auth-type';
process.env['GEMINI_DEFAULT_AUTH_TYPE'] = 'invalid-auth-type';
const settings: LoadedSettings = new LoadedSettings(
{
@@ -244,7 +244,7 @@ describe('AuthDialog', () => {
[],
);
const { lastFrame } = render(
const { lastFrame } = renderWithProviders(
<AuthDialog onSelect={() => {}} settings={settings} />,
);
@@ -254,43 +254,6 @@ describe('AuthDialog', () => {
});
});
// it('should prevent exiting when no auth method is selected and show error message', async () => {
// const onSelect = vi.fn();
// const settings: LoadedSettings = new LoadedSettings(
// {
// settings: {},
// path: '',
// },
// {
// settings: {
// selectedAuthType: undefined,
// },
// path: '',
// },
// {
// settings: {},
// path: '',
// },
// [],
// );
// const { lastFrame, stdin, unmount } = render(
// <AuthDialog onSelect={onSelect} settings={settings} />,
// );
// await wait();
// // Simulate pressing escape key
// stdin.write('\u001b'); // ESC key
// await wait(100); // Increased wait time for CI environment
// // Should show error message instead of calling onSelect
// expect(lastFrame()).toContain(
// 'You must select an auth method to proceed. Press Ctrl+C twice to exit.',
// );
// expect(onSelect).not.toHaveBeenCalled();
// unmount();
// });
it('should not exit if there is already an error message', async () => {
const onSelect = vi.fn();
const settings: LoadedSettings = new LoadedSettings(
@@ -313,7 +276,7 @@ describe('AuthDialog', () => {
[],
);
const { lastFrame, stdin, unmount } = render(
const { lastFrame, stdin, unmount } = renderWithProviders(
<AuthDialog
onSelect={onSelect}
settings={settings}
@@ -355,7 +318,7 @@ describe('AuthDialog', () => {
[],
);
const { stdin, unmount } = render(
const { stdin, unmount } = renderWithProviders(
<AuthDialog onSelect={onSelect} settings={settings} />,
);
await wait();