mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 05:12:55 -07:00
fix(cli): Enable typechecking for more test files (#11455)
This commit is contained in:
@@ -23,7 +23,7 @@ import {
|
|||||||
} from '@google/gemini-cli-core';
|
} from '@google/gemini-cli-core';
|
||||||
import type { Part } from '@google/genai';
|
import type { Part } from '@google/genai';
|
||||||
import { runNonInteractive } from './nonInteractiveCli.js';
|
import { runNonInteractive } from './nonInteractiveCli.js';
|
||||||
import { vi } from 'vitest';
|
import { vi, type Mock, type MockInstance } from 'vitest';
|
||||||
import type { LoadedSettings } from './config/settings.js';
|
import type { LoadedSettings } from './config/settings.js';
|
||||||
|
|
||||||
// Mock core modules
|
// Mock core modules
|
||||||
@@ -63,13 +63,13 @@ describe('runNonInteractive', () => {
|
|||||||
let mockConfig: Config;
|
let mockConfig: Config;
|
||||||
let mockSettings: LoadedSettings;
|
let mockSettings: LoadedSettings;
|
||||||
let mockToolRegistry: ToolRegistry;
|
let mockToolRegistry: ToolRegistry;
|
||||||
let mockCoreExecuteToolCall: vi.Mock;
|
let mockCoreExecuteToolCall: Mock;
|
||||||
let mockShutdownTelemetry: vi.Mock;
|
let mockShutdownTelemetry: Mock;
|
||||||
let consoleErrorSpy: vi.SpyInstance;
|
let consoleErrorSpy: MockInstance;
|
||||||
let processStdoutSpy: vi.SpyInstance;
|
let processStdoutSpy: MockInstance;
|
||||||
let mockGeminiClient: {
|
let mockGeminiClient: {
|
||||||
sendMessageStream: vi.Mock;
|
sendMessageStream: Mock;
|
||||||
getChatRecordingService: vi.Mock;
|
getChatRecordingService: Mock;
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
|||||||
@@ -4,17 +4,14 @@
|
|||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { describe, it, expect, vi } from 'vitest';
|
import { describe, it, expect, vi, type Mock } from 'vitest';
|
||||||
import { render } from 'ink-testing-library';
|
import { render } from 'ink-testing-library';
|
||||||
import { Text, useIsScreenReaderEnabled } from 'ink';
|
import { Text, useIsScreenReaderEnabled } from 'ink';
|
||||||
|
import { makeFakeConfig } from '@google/gemini-cli-core';
|
||||||
import { App } from './App.js';
|
import { App } from './App.js';
|
||||||
import { UIStateContext, type UIState } from './contexts/UIStateContext.js';
|
import { UIStateContext, type UIState } from './contexts/UIStateContext.js';
|
||||||
import { StreamingState } from './types.js';
|
import { StreamingState } from './types.js';
|
||||||
import {
|
import { ConfigContext } from './contexts/ConfigContext.js';
|
||||||
ConfigContext,
|
|
||||||
type Config,
|
|
||||||
type Telemetry,
|
|
||||||
} from './contexts/ConfigContext.js';
|
|
||||||
|
|
||||||
vi.mock('ink', async (importOriginal) => {
|
vi.mock('ink', async (importOriginal) => {
|
||||||
const original = await importOriginal<typeof import('ink')>();
|
const original = await importOriginal<typeof import('ink')>();
|
||||||
@@ -64,9 +61,7 @@ describe('App', () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockConfig = {
|
const mockConfig = makeFakeConfig();
|
||||||
telemetry: {} as Telemetry,
|
|
||||||
} as Config;
|
|
||||||
|
|
||||||
const renderWithProviders = (ui: React.ReactElement, state: UIState) =>
|
const renderWithProviders = (ui: React.ReactElement, state: UIState) =>
|
||||||
render(
|
render(
|
||||||
@@ -132,7 +127,7 @@ describe('App', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should render ScreenReaderAppLayout when screen reader is enabled', () => {
|
it('should render ScreenReaderAppLayout when screen reader is enabled', () => {
|
||||||
(useIsScreenReaderEnabled as vi.Mock).mockReturnValue(true);
|
(useIsScreenReaderEnabled as Mock).mockReturnValue(true);
|
||||||
|
|
||||||
const { lastFrame } = renderWithProviders(<App />, mockUIState as UIState);
|
const { lastFrame } = renderWithProviders(<App />, mockUIState as UIState);
|
||||||
|
|
||||||
@@ -142,7 +137,7 @@ describe('App', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should render DefaultAppLayout when screen reader is not enabled', () => {
|
it('should render DefaultAppLayout when screen reader is not enabled', () => {
|
||||||
(useIsScreenReaderEnabled as vi.Mock).mockReturnValue(false);
|
(useIsScreenReaderEnabled as Mock).mockReturnValue(false);
|
||||||
|
|
||||||
const { lastFrame } = renderWithProviders(<App />, mockUIState as UIState);
|
const { lastFrame } = renderWithProviders(<App />, mockUIState as UIState);
|
||||||
|
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ describe('SessionStatsContext', () => {
|
|||||||
accept: 1,
|
accept: 1,
|
||||||
reject: 0,
|
reject: 0,
|
||||||
modify: 0,
|
modify: 0,
|
||||||
|
auto_accept: 0,
|
||||||
},
|
},
|
||||||
byName: {
|
byName: {
|
||||||
'test-tool': {
|
'test-tool': {
|
||||||
@@ -95,10 +96,15 @@ describe('SessionStatsContext', () => {
|
|||||||
accept: 1,
|
accept: 1,
|
||||||
reject: 0,
|
reject: 0,
|
||||||
modify: 0,
|
modify: 0,
|
||||||
|
auto_accept: 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
files: {
|
||||||
|
totalLinesAdded: 0,
|
||||||
|
totalLinesRemoved: 0,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
@@ -152,9 +158,13 @@ describe('SessionStatsContext', () => {
|
|||||||
totalSuccess: 0,
|
totalSuccess: 0,
|
||||||
totalFail: 0,
|
totalFail: 0,
|
||||||
totalDurationMs: 0,
|
totalDurationMs: 0,
|
||||||
totalDecisions: { accept: 0, reject: 0, modify: 0 },
|
totalDecisions: { accept: 0, reject: 0, modify: 0, auto_accept: 0 },
|
||||||
byName: {},
|
byName: {},
|
||||||
},
|
},
|
||||||
|
files: {
|
||||||
|
totalLinesAdded: 0,
|
||||||
|
totalLinesRemoved: 0,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
|
|||||||
@@ -86,7 +86,9 @@ describe('themeManager.loadCustomThemes', () => {
|
|||||||
delete legacyTheme.DiffAdded;
|
delete legacyTheme.DiffAdded;
|
||||||
delete legacyTheme.DiffRemoved;
|
delete legacyTheme.DiffRemoved;
|
||||||
|
|
||||||
themeManager.loadCustomThemes({ 'Legacy Custom Theme': legacyTheme });
|
themeManager.loadCustomThemes({
|
||||||
|
'Legacy Custom Theme': legacyTheme as CustomTheme,
|
||||||
|
});
|
||||||
const result = themeManager.getTheme('Legacy Custom Theme')!;
|
const result = themeManager.getTheme('Legacy Custom Theme')!;
|
||||||
|
|
||||||
expect(result.colors.DiffAdded).toBe(darkTheme.DiffAdded);
|
expect(result.colors.DiffAdded).toBe(darkTheme.DiffAdded);
|
||||||
|
|||||||
@@ -4,20 +4,39 @@
|
|||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
import {
|
||||||
|
describe,
|
||||||
|
it,
|
||||||
|
expect,
|
||||||
|
vi,
|
||||||
|
beforeEach,
|
||||||
|
afterEach,
|
||||||
|
type MockInstance,
|
||||||
|
type Mock,
|
||||||
|
} from 'vitest';
|
||||||
import { validateNonInteractiveAuth } from './validateNonInterActiveAuth.js';
|
import { validateNonInteractiveAuth } from './validateNonInterActiveAuth.js';
|
||||||
import { AuthType, OutputFormat } from '@google/gemini-cli-core';
|
import {
|
||||||
|
AuthType,
|
||||||
|
OutputFormat,
|
||||||
|
makeFakeConfig,
|
||||||
|
} from '@google/gemini-cli-core';
|
||||||
import type { Config } from '@google/gemini-cli-core';
|
import type { Config } from '@google/gemini-cli-core';
|
||||||
import * as auth from './config/auth.js';
|
import * as auth from './config/auth.js';
|
||||||
import { type LoadedSettings } from './config/settings.js';
|
import { type LoadedSettings } from './config/settings.js';
|
||||||
|
|
||||||
|
function createLocalMockConfig(overrides: Partial<Config> = {}): Config {
|
||||||
|
const config = makeFakeConfig();
|
||||||
|
Object.assign(config, overrides);
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
describe('validateNonInterActiveAuth', () => {
|
describe('validateNonInterActiveAuth', () => {
|
||||||
let originalEnvGeminiApiKey: string | undefined;
|
let originalEnvGeminiApiKey: string | undefined;
|
||||||
let originalEnvVertexAi: string | undefined;
|
let originalEnvVertexAi: string | undefined;
|
||||||
let originalEnvGcp: string | undefined;
|
let originalEnvGcp: string | undefined;
|
||||||
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
|
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
|
||||||
let processExitSpy: ReturnType<typeof vi.spyOn>;
|
let processExitSpy: MockInstance;
|
||||||
let refreshAuthMock: vi.Mock;
|
let refreshAuthMock: Mock;
|
||||||
let mockSettings: LoadedSettings;
|
let mockSettings: LoadedSettings;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -28,11 +47,16 @@ describe('validateNonInterActiveAuth', () => {
|
|||||||
delete process.env['GOOGLE_GENAI_USE_VERTEXAI'];
|
delete process.env['GOOGLE_GENAI_USE_VERTEXAI'];
|
||||||
delete process.env['GOOGLE_GENAI_USE_GCA'];
|
delete process.env['GOOGLE_GENAI_USE_GCA'];
|
||||||
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
||||||
processExitSpy = vi.spyOn(process, 'exit').mockImplementation((code) => {
|
processExitSpy = vi
|
||||||
|
.spyOn(process, 'exit')
|
||||||
|
.mockImplementation((code?: string | number | null | undefined) => {
|
||||||
throw new Error(`process.exit(${code}) called`);
|
throw new Error(`process.exit(${code}) called`);
|
||||||
});
|
});
|
||||||
vi.spyOn(auth, 'validateAuthMethod').mockReturnValue(null);
|
vi.spyOn(auth, 'validateAuthMethod').mockReturnValue(null);
|
||||||
refreshAuthMock = vi.fn().mockResolvedValue('refreshed');
|
refreshAuthMock = vi.fn().mockImplementation(async () => {
|
||||||
|
console.log('DEBUG: refreshAuthMock called');
|
||||||
|
return 'refreshed';
|
||||||
|
});
|
||||||
mockSettings = {
|
mockSettings = {
|
||||||
system: { path: '', settings: {} },
|
system: { path: '', settings: {} },
|
||||||
systemDefaults: { path: '', settings: {} },
|
systemDefaults: { path: '', settings: {} },
|
||||||
@@ -74,13 +98,13 @@ describe('validateNonInterActiveAuth', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('exits if no auth type is configured or env vars set', async () => {
|
it('exits if no auth type is configured or env vars set', async () => {
|
||||||
const nonInteractiveConfig = {
|
const nonInteractiveConfig = createLocalMockConfig({
|
||||||
refreshAuth: refreshAuthMock,
|
refreshAuth: refreshAuthMock,
|
||||||
getOutputFormat: vi.fn().mockReturnValue(OutputFormat.TEXT),
|
getOutputFormat: vi.fn().mockReturnValue(OutputFormat.TEXT),
|
||||||
getContentGeneratorConfig: vi
|
getContentGeneratorConfig: vi
|
||||||
.fn()
|
.fn()
|
||||||
.mockReturnValue({ authType: undefined }),
|
.mockReturnValue({ authType: undefined }),
|
||||||
};
|
});
|
||||||
try {
|
try {
|
||||||
await validateNonInteractiveAuth(
|
await validateNonInteractiveAuth(
|
||||||
undefined,
|
undefined,
|
||||||
@@ -100,9 +124,9 @@ describe('validateNonInterActiveAuth', () => {
|
|||||||
|
|
||||||
it('uses LOGIN_WITH_GOOGLE if GOOGLE_GENAI_USE_GCA is set', async () => {
|
it('uses LOGIN_WITH_GOOGLE if GOOGLE_GENAI_USE_GCA is set', async () => {
|
||||||
process.env['GOOGLE_GENAI_USE_GCA'] = 'true';
|
process.env['GOOGLE_GENAI_USE_GCA'] = 'true';
|
||||||
const nonInteractiveConfig = {
|
const nonInteractiveConfig = createLocalMockConfig({
|
||||||
refreshAuth: refreshAuthMock,
|
refreshAuth: refreshAuthMock,
|
||||||
};
|
});
|
||||||
await validateNonInteractiveAuth(
|
await validateNonInteractiveAuth(
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
@@ -114,9 +138,9 @@ describe('validateNonInterActiveAuth', () => {
|
|||||||
|
|
||||||
it('uses USE_GEMINI if GEMINI_API_KEY is set', async () => {
|
it('uses USE_GEMINI if GEMINI_API_KEY is set', async () => {
|
||||||
process.env['GEMINI_API_KEY'] = 'fake-key';
|
process.env['GEMINI_API_KEY'] = 'fake-key';
|
||||||
const nonInteractiveConfig = {
|
const nonInteractiveConfig = createLocalMockConfig({
|
||||||
refreshAuth: refreshAuthMock,
|
refreshAuth: refreshAuthMock,
|
||||||
};
|
});
|
||||||
await validateNonInteractiveAuth(
|
await validateNonInteractiveAuth(
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
@@ -130,9 +154,9 @@ describe('validateNonInterActiveAuth', () => {
|
|||||||
process.env['GOOGLE_GENAI_USE_VERTEXAI'] = 'true';
|
process.env['GOOGLE_GENAI_USE_VERTEXAI'] = 'true';
|
||||||
process.env['GOOGLE_CLOUD_PROJECT'] = 'test-project';
|
process.env['GOOGLE_CLOUD_PROJECT'] = 'test-project';
|
||||||
process.env['GOOGLE_CLOUD_LOCATION'] = 'us-central1';
|
process.env['GOOGLE_CLOUD_LOCATION'] = 'us-central1';
|
||||||
const nonInteractiveConfig = {
|
const nonInteractiveConfig = createLocalMockConfig({
|
||||||
refreshAuth: refreshAuthMock,
|
refreshAuth: refreshAuthMock,
|
||||||
};
|
});
|
||||||
await validateNonInteractiveAuth(
|
await validateNonInteractiveAuth(
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
@@ -145,9 +169,9 @@ describe('validateNonInterActiveAuth', () => {
|
|||||||
it('uses USE_VERTEX_AI if GOOGLE_GENAI_USE_VERTEXAI is true and GOOGLE_API_KEY is set', async () => {
|
it('uses USE_VERTEX_AI if GOOGLE_GENAI_USE_VERTEXAI is true and GOOGLE_API_KEY is set', async () => {
|
||||||
process.env['GOOGLE_GENAI_USE_VERTEXAI'] = 'true';
|
process.env['GOOGLE_GENAI_USE_VERTEXAI'] = 'true';
|
||||||
process.env['GOOGLE_API_KEY'] = 'vertex-api-key';
|
process.env['GOOGLE_API_KEY'] = 'vertex-api-key';
|
||||||
const nonInteractiveConfig = {
|
const nonInteractiveConfig = createLocalMockConfig({
|
||||||
refreshAuth: refreshAuthMock,
|
refreshAuth: refreshAuthMock,
|
||||||
};
|
});
|
||||||
await validateNonInteractiveAuth(
|
await validateNonInteractiveAuth(
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
@@ -163,9 +187,9 @@ describe('validateNonInterActiveAuth', () => {
|
|||||||
process.env['GOOGLE_GENAI_USE_VERTEXAI'] = 'true';
|
process.env['GOOGLE_GENAI_USE_VERTEXAI'] = 'true';
|
||||||
process.env['GOOGLE_CLOUD_PROJECT'] = 'test-project';
|
process.env['GOOGLE_CLOUD_PROJECT'] = 'test-project';
|
||||||
process.env['GOOGLE_CLOUD_LOCATION'] = 'us-central1';
|
process.env['GOOGLE_CLOUD_LOCATION'] = 'us-central1';
|
||||||
const nonInteractiveConfig = {
|
const nonInteractiveConfig = createLocalMockConfig({
|
||||||
refreshAuth: refreshAuthMock,
|
refreshAuth: refreshAuthMock,
|
||||||
};
|
});
|
||||||
await validateNonInteractiveAuth(
|
await validateNonInteractiveAuth(
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
@@ -180,9 +204,9 @@ describe('validateNonInterActiveAuth', () => {
|
|||||||
process.env['GOOGLE_GENAI_USE_VERTEXAI'] = 'true';
|
process.env['GOOGLE_GENAI_USE_VERTEXAI'] = 'true';
|
||||||
process.env['GOOGLE_CLOUD_PROJECT'] = 'test-project';
|
process.env['GOOGLE_CLOUD_PROJECT'] = 'test-project';
|
||||||
process.env['GOOGLE_CLOUD_LOCATION'] = 'us-central1';
|
process.env['GOOGLE_CLOUD_LOCATION'] = 'us-central1';
|
||||||
const nonInteractiveConfig = {
|
const nonInteractiveConfig = createLocalMockConfig({
|
||||||
refreshAuth: refreshAuthMock,
|
refreshAuth: refreshAuthMock,
|
||||||
};
|
});
|
||||||
await validateNonInteractiveAuth(
|
await validateNonInteractiveAuth(
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
@@ -197,9 +221,9 @@ describe('validateNonInterActiveAuth', () => {
|
|||||||
process.env['GEMINI_API_KEY'] = 'fake-key';
|
process.env['GEMINI_API_KEY'] = 'fake-key';
|
||||||
process.env['GOOGLE_CLOUD_PROJECT'] = 'test-project';
|
process.env['GOOGLE_CLOUD_PROJECT'] = 'test-project';
|
||||||
process.env['GOOGLE_CLOUD_LOCATION'] = 'us-central1';
|
process.env['GOOGLE_CLOUD_LOCATION'] = 'us-central1';
|
||||||
const nonInteractiveConfig = {
|
const nonInteractiveConfig = createLocalMockConfig({
|
||||||
refreshAuth: refreshAuthMock,
|
refreshAuth: refreshAuthMock,
|
||||||
};
|
});
|
||||||
await validateNonInteractiveAuth(
|
await validateNonInteractiveAuth(
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
@@ -211,9 +235,9 @@ describe('validateNonInterActiveAuth', () => {
|
|||||||
|
|
||||||
it('uses configuredAuthType over environment variables', async () => {
|
it('uses configuredAuthType over environment variables', async () => {
|
||||||
process.env['GEMINI_API_KEY'] = 'fake-key';
|
process.env['GEMINI_API_KEY'] = 'fake-key';
|
||||||
const nonInteractiveConfig = {
|
const nonInteractiveConfig = createLocalMockConfig({
|
||||||
refreshAuth: refreshAuthMock,
|
refreshAuth: refreshAuthMock,
|
||||||
};
|
});
|
||||||
await validateNonInteractiveAuth(
|
await validateNonInteractiveAuth(
|
||||||
AuthType.LOGIN_WITH_GOOGLE,
|
AuthType.LOGIN_WITH_GOOGLE,
|
||||||
undefined,
|
undefined,
|
||||||
@@ -226,13 +250,13 @@ describe('validateNonInterActiveAuth', () => {
|
|||||||
it('exits if validateAuthMethod returns error', async () => {
|
it('exits if validateAuthMethod returns error', async () => {
|
||||||
// Mock validateAuthMethod to return error
|
// Mock validateAuthMethod to return error
|
||||||
vi.spyOn(auth, 'validateAuthMethod').mockReturnValue('Auth error!');
|
vi.spyOn(auth, 'validateAuthMethod').mockReturnValue('Auth error!');
|
||||||
const nonInteractiveConfig = {
|
const nonInteractiveConfig = createLocalMockConfig({
|
||||||
refreshAuth: refreshAuthMock,
|
refreshAuth: refreshAuthMock,
|
||||||
getOutputFormat: vi.fn().mockReturnValue(OutputFormat.TEXT),
|
getOutputFormat: vi.fn().mockReturnValue(OutputFormat.TEXT),
|
||||||
getContentGeneratorConfig: vi
|
getContentGeneratorConfig: vi
|
||||||
.fn()
|
.fn()
|
||||||
.mockReturnValue({ authType: undefined }),
|
.mockReturnValue({ authType: undefined }),
|
||||||
};
|
});
|
||||||
try {
|
try {
|
||||||
await validateNonInteractiveAuth(
|
await validateNonInteractiveAuth(
|
||||||
AuthType.USE_GEMINI,
|
AuthType.USE_GEMINI,
|
||||||
@@ -253,10 +277,9 @@ describe('validateNonInterActiveAuth', () => {
|
|||||||
const validateAuthMethodSpy = vi
|
const validateAuthMethodSpy = vi
|
||||||
.spyOn(auth, 'validateAuthMethod')
|
.spyOn(auth, 'validateAuthMethod')
|
||||||
.mockReturnValue('Auth error!');
|
.mockReturnValue('Auth error!');
|
||||||
const nonInteractiveConfig = {
|
const nonInteractiveConfig = createLocalMockConfig({
|
||||||
refreshAuth: refreshAuthMock,
|
refreshAuth: refreshAuthMock,
|
||||||
};
|
});
|
||||||
|
|
||||||
// Even with an invalid auth type, it should not exit
|
// Even with an invalid auth type, it should not exit
|
||||||
// because validation is skipped.
|
// because validation is skipped.
|
||||||
await validateNonInteractiveAuth(
|
await validateNonInteractiveAuth(
|
||||||
@@ -274,11 +297,11 @@ describe('validateNonInterActiveAuth', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('succeeds if effectiveAuthType matches enforcedAuthType', async () => {
|
it('succeeds if effectiveAuthType matches enforcedAuthType', async () => {
|
||||||
mockSettings.merged.security.auth.enforcedType = AuthType.USE_GEMINI;
|
mockSettings.merged.security!.auth!.enforcedType = AuthType.USE_GEMINI;
|
||||||
process.env['GEMINI_API_KEY'] = 'fake-key';
|
process.env['GEMINI_API_KEY'] = 'fake-key';
|
||||||
const nonInteractiveConfig = {
|
const nonInteractiveConfig = createLocalMockConfig({
|
||||||
refreshAuth: refreshAuthMock,
|
refreshAuth: refreshAuthMock,
|
||||||
};
|
});
|
||||||
await validateNonInteractiveAuth(
|
await validateNonInteractiveAuth(
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
@@ -289,11 +312,12 @@ describe('validateNonInterActiveAuth', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('exits if configuredAuthType does not match enforcedAuthType', async () => {
|
it('exits if configuredAuthType does not match enforcedAuthType', async () => {
|
||||||
mockSettings.merged.security.auth.enforcedType = AuthType.LOGIN_WITH_GOOGLE;
|
mockSettings.merged.security!.auth!.enforcedType =
|
||||||
const nonInteractiveConfig = {
|
AuthType.LOGIN_WITH_GOOGLE;
|
||||||
|
const nonInteractiveConfig = createLocalMockConfig({
|
||||||
refreshAuth: refreshAuthMock,
|
refreshAuth: refreshAuthMock,
|
||||||
getOutputFormat: vi.fn().mockReturnValue(OutputFormat.TEXT),
|
getOutputFormat: vi.fn().mockReturnValue(OutputFormat.TEXT),
|
||||||
};
|
});
|
||||||
try {
|
try {
|
||||||
await validateNonInteractiveAuth(
|
await validateNonInteractiveAuth(
|
||||||
AuthType.USE_GEMINI,
|
AuthType.USE_GEMINI,
|
||||||
@@ -312,12 +336,13 @@ describe('validateNonInterActiveAuth', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('exits if auth from env var does not match enforcedAuthType', async () => {
|
it('exits if auth from env var does not match enforcedAuthType', async () => {
|
||||||
mockSettings.merged.security.auth.enforcedType = AuthType.LOGIN_WITH_GOOGLE;
|
mockSettings.merged.security!.auth!.enforcedType =
|
||||||
|
AuthType.LOGIN_WITH_GOOGLE;
|
||||||
process.env['GEMINI_API_KEY'] = 'fake-key';
|
process.env['GEMINI_API_KEY'] = 'fake-key';
|
||||||
const nonInteractiveConfig = {
|
const nonInteractiveConfig = createLocalMockConfig({
|
||||||
refreshAuth: refreshAuthMock,
|
refreshAuth: refreshAuthMock,
|
||||||
getOutputFormat: vi.fn().mockReturnValue(OutputFormat.TEXT),
|
getOutputFormat: vi.fn().mockReturnValue(OutputFormat.TEXT),
|
||||||
};
|
});
|
||||||
try {
|
try {
|
||||||
await validateNonInteractiveAuth(
|
await validateNonInteractiveAuth(
|
||||||
undefined,
|
undefined,
|
||||||
@@ -337,20 +362,20 @@ describe('validateNonInterActiveAuth', () => {
|
|||||||
|
|
||||||
describe('JSON output mode', () => {
|
describe('JSON output mode', () => {
|
||||||
it('prints JSON error when no auth is configured and exits with code 1', async () => {
|
it('prints JSON error when no auth is configured and exits with code 1', async () => {
|
||||||
const nonInteractiveConfig = {
|
const nonInteractiveConfig = createLocalMockConfig({
|
||||||
refreshAuth: refreshAuthMock,
|
refreshAuth: refreshAuthMock,
|
||||||
getOutputFormat: vi.fn().mockReturnValue(OutputFormat.JSON),
|
getOutputFormat: vi.fn().mockReturnValue(OutputFormat.JSON),
|
||||||
getContentGeneratorConfig: vi
|
getContentGeneratorConfig: vi
|
||||||
.fn()
|
.fn()
|
||||||
.mockReturnValue({ authType: undefined }),
|
.mockReturnValue({ authType: undefined }),
|
||||||
};
|
});
|
||||||
|
|
||||||
let thrown: Error | undefined;
|
let thrown: Error | undefined;
|
||||||
try {
|
try {
|
||||||
await validateNonInteractiveAuth(
|
await validateNonInteractiveAuth(
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
nonInteractiveConfig as unknown as Config,
|
nonInteractiveConfig,
|
||||||
mockSettings,
|
mockSettings,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -368,21 +393,21 @@ describe('validateNonInterActiveAuth', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('prints JSON error when enforced auth mismatches current auth and exits with code 1', async () => {
|
it('prints JSON error when enforced auth mismatches current auth and exits with code 1', async () => {
|
||||||
mockSettings.merged.security.auth.enforcedType = AuthType.USE_GEMINI;
|
mockSettings.merged.security!.auth!.enforcedType = AuthType.USE_GEMINI;
|
||||||
const nonInteractiveConfig = {
|
const nonInteractiveConfig = createLocalMockConfig({
|
||||||
refreshAuth: refreshAuthMock,
|
refreshAuth: refreshAuthMock,
|
||||||
getOutputFormat: vi.fn().mockReturnValue(OutputFormat.JSON),
|
getOutputFormat: vi.fn().mockReturnValue(OutputFormat.JSON),
|
||||||
getContentGeneratorConfig: vi
|
getContentGeneratorConfig: vi
|
||||||
.fn()
|
.fn()
|
||||||
.mockReturnValue({ authType: undefined }),
|
.mockReturnValue({ authType: undefined }),
|
||||||
};
|
});
|
||||||
|
|
||||||
let thrown: Error | undefined;
|
let thrown: Error | undefined;
|
||||||
try {
|
try {
|
||||||
await validateNonInteractiveAuth(
|
await validateNonInteractiveAuth(
|
||||||
AuthType.LOGIN_WITH_GOOGLE,
|
AuthType.LOGIN_WITH_GOOGLE,
|
||||||
undefined,
|
undefined,
|
||||||
nonInteractiveConfig as unknown as Config,
|
nonInteractiveConfig,
|
||||||
mockSettings,
|
mockSettings,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -405,20 +430,20 @@ describe('validateNonInterActiveAuth', () => {
|
|||||||
vi.spyOn(auth, 'validateAuthMethod').mockReturnValue('Auth error!');
|
vi.spyOn(auth, 'validateAuthMethod').mockReturnValue('Auth error!');
|
||||||
process.env['GEMINI_API_KEY'] = 'fake-key';
|
process.env['GEMINI_API_KEY'] = 'fake-key';
|
||||||
|
|
||||||
const nonInteractiveConfig = {
|
const nonInteractiveConfig = createLocalMockConfig({
|
||||||
refreshAuth: refreshAuthMock,
|
refreshAuth: refreshAuthMock,
|
||||||
getOutputFormat: vi.fn().mockReturnValue(OutputFormat.JSON),
|
getOutputFormat: vi.fn().mockReturnValue(OutputFormat.JSON),
|
||||||
getContentGeneratorConfig: vi
|
getContentGeneratorConfig: vi
|
||||||
.fn()
|
.fn()
|
||||||
.mockReturnValue({ authType: undefined }),
|
.mockReturnValue({ authType: undefined }),
|
||||||
};
|
});
|
||||||
|
|
||||||
let thrown: Error | undefined;
|
let thrown: Error | undefined;
|
||||||
try {
|
try {
|
||||||
await validateNonInteractiveAuth(
|
await validateNonInteractiveAuth(
|
||||||
AuthType.USE_GEMINI,
|
AuthType.USE_GEMINI,
|
||||||
undefined,
|
undefined,
|
||||||
nonInteractiveConfig as unknown as Config,
|
nonInteractiveConfig,
|
||||||
mockSettings,
|
mockSettings,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -17,14 +17,9 @@
|
|||||||
"node_modules",
|
"node_modules",
|
||||||
"dist",
|
"dist",
|
||||||
// TODO(5691): Fix type errors and remove excludes.
|
// TODO(5691): Fix type errors and remove excludes.
|
||||||
"src/nonInteractiveCli.test.ts",
|
|
||||||
"src/services/FileCommandLoader.test.ts",
|
|
||||||
"src/services/prompt-processors/argumentProcessor.test.ts",
|
|
||||||
"src/utils/cleanup.test.ts",
|
"src/utils/cleanup.test.ts",
|
||||||
"src/utils/handleAutoUpdate.test.ts",
|
"src/utils/handleAutoUpdate.test.ts",
|
||||||
"src/utils/startupWarnings.test.ts",
|
"src/utils/startupWarnings.test.ts",
|
||||||
"src/ui/App.test.tsx",
|
|
||||||
"src/ui/contexts/SessionContext.test.tsx",
|
|
||||||
"src/ui/hooks/slashCommandProcessor.test.ts",
|
"src/ui/hooks/slashCommandProcessor.test.ts",
|
||||||
"src/ui/hooks/useAtCompletion.test.ts",
|
"src/ui/hooks/useAtCompletion.test.ts",
|
||||||
"src/ui/hooks/useConsoleMessages.test.ts",
|
"src/ui/hooks/useConsoleMessages.test.ts",
|
||||||
@@ -35,11 +30,7 @@
|
|||||||
"src/ui/hooks/useKeypress.test.ts",
|
"src/ui/hooks/useKeypress.test.ts",
|
||||||
"src/ui/hooks/usePhraseCycler.test.ts",
|
"src/ui/hooks/usePhraseCycler.test.ts",
|
||||||
"src/ui/hooks/vim.test.ts",
|
"src/ui/hooks/vim.test.ts",
|
||||||
"src/ui/utils/computeStats.test.ts",
|
"src/ui/utils/computeStats.test.ts"
|
||||||
"src/ui/themes/theme.test.ts",
|
|
||||||
"src/validateNonInterActiveAuth.test.ts",
|
|
||||||
"src/services/prompt-processors/shellProcessor.test.ts",
|
|
||||||
"src/commands/extensions/examples/**"
|
|
||||||
],
|
],
|
||||||
"references": [{ "path": "../core" }]
|
"references": [{ "path": "../core" }]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user