mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-02-01 22:48:03 +00:00
WIP Test fixes
This commit is contained in:
@@ -11,6 +11,15 @@ import { Settings } from './settings.js';
|
||||
import { Extension } from './extension.js';
|
||||
import * as ServerConfig from '@google/gemini-cli-core';
|
||||
|
||||
vi.mock('fs', async (importOriginal) => {
|
||||
const actualFs = await importOriginal<typeof import('fs')>();
|
||||
return {
|
||||
...actualFs,
|
||||
mkdirSync: vi.fn(),
|
||||
writeFileSync: vi.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('os', async (importOriginal) => {
|
||||
const actualOs = await importOriginal<typeof os>();
|
||||
return {
|
||||
|
||||
@@ -221,7 +221,7 @@ export const useSlashCommandProcessor = (
|
||||
} catch (_err) {
|
||||
return [];
|
||||
}
|
||||
}, [config]);
|
||||
}, [storage]);
|
||||
|
||||
// Define legacy commands
|
||||
// This list contains all commands that have NOT YET been migrated to the
|
||||
@@ -934,8 +934,8 @@ export const useSlashCommandProcessor = (
|
||||
}
|
||||
},
|
||||
action: async (_mainCommand, subCommand, _args) => {
|
||||
const checkpointDir = config?.getProjectTempDir()
|
||||
? path.join(config.getProjectTempDir(), 'checkpoints')
|
||||
const checkpointDir = storage?.getProjectTempDir()
|
||||
? path.join(storage.getProjectTempDir(), 'checkpoints')
|
||||
: undefined;
|
||||
|
||||
if (!checkpointDir) {
|
||||
@@ -1052,6 +1052,7 @@ export const useSlashCommandProcessor = (
|
||||
setPendingCompressionItem,
|
||||
clearItems,
|
||||
refreshStatic,
|
||||
storage,
|
||||
]);
|
||||
|
||||
const handleSlashCommand = useCallback(
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
UnauthorizedError,
|
||||
UserPromptEvent,
|
||||
DEFAULT_GEMINI_FLASH_MODEL,
|
||||
Storage,
|
||||
} from '@google/gemini-cli-core';
|
||||
import { type Part, type PartListUnion } from '@google/genai';
|
||||
import {
|
||||
@@ -111,6 +112,13 @@ export const useGeminiStream = (
|
||||
return new GitService(config.getProjectRoot());
|
||||
}, [config]);
|
||||
|
||||
const storage = useMemo(() => {
|
||||
if (!config.getProjectRoot()) {
|
||||
return;
|
||||
}
|
||||
return new Storage(config.getProjectRoot());
|
||||
}, [config]);
|
||||
|
||||
const [toolCalls, scheduleToolCalls, markToolsAsSubmitted] =
|
||||
useReactToolScheduler(
|
||||
async (completedToolCallsFromScheduler) => {
|
||||
@@ -769,8 +777,8 @@ export const useGeminiStream = (
|
||||
);
|
||||
|
||||
if (restorableToolCalls.length > 0) {
|
||||
const checkpointDir = config.getProjectTempDir()
|
||||
? path.join(config.getProjectTempDir(), 'checkpoints')
|
||||
const checkpointDir = storage?.getProjectTempDir()
|
||||
? path.join(storage.getProjectTempDir(), 'checkpoints')
|
||||
: undefined;
|
||||
|
||||
if (!checkpointDir) {
|
||||
@@ -854,7 +862,15 @@ export const useGeminiStream = (
|
||||
}
|
||||
};
|
||||
saveRestorableToolCalls();
|
||||
}, [toolCalls, config, onDebugMessage, gitService, history, geminiClient]);
|
||||
}, [
|
||||
toolCalls,
|
||||
config,
|
||||
onDebugMessage,
|
||||
gitService,
|
||||
history,
|
||||
geminiClient,
|
||||
storage,
|
||||
]);
|
||||
|
||||
return {
|
||||
streamingState,
|
||||
|
||||
@@ -4,15 +4,16 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import * as os from 'os';
|
||||
vi.mock('os');
|
||||
|
||||
import { renderHook, act, waitFor } from '@testing-library/react';
|
||||
import { useShellHistory } from './useShellHistory.js';
|
||||
import * as fs from 'fs/promises';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import * as crypto from 'crypto';
|
||||
|
||||
vi.mock('fs/promises');
|
||||
vi.mock('os');
|
||||
vi.mock('crypto');
|
||||
|
||||
const MOCKED_PROJECT_ROOT = '/test/project';
|
||||
|
||||
@@ -4,20 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach, afterEach, Mock } from 'vitest';
|
||||
import { getOauthClient } from './oauth2.js';
|
||||
import { UserAccountManager } from '../utils/userAccountManager.js';
|
||||
import { OAuth2Client, Compute } from 'google-auth-library';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import http from 'http';
|
||||
import open from 'open';
|
||||
import crypto from 'crypto';
|
||||
import * as os from 'os';
|
||||
import { AuthType } from '../core/contentGenerator.js';
|
||||
import { Config } from '../config/config.js';
|
||||
import readline from 'node:readline';
|
||||
|
||||
vi.mock('os', async (importOriginal) => {
|
||||
const os = await importOriginal<typeof import('os')>();
|
||||
return {
|
||||
@@ -26,6 +13,20 @@ vi.mock('os', async (importOriginal) => {
|
||||
};
|
||||
});
|
||||
|
||||
import { describe, it, expect, vi, beforeEach, afterEach, Mock } from 'vitest';
|
||||
import { getOauthClient } from './oauth2.js';
|
||||
import { UserAccountManager } from '../utils/userAccountManager.js';
|
||||
import { Storage } from '../config/storage.js';
|
||||
import { OAuth2Client, Compute } from 'google-auth-library';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import http from 'http';
|
||||
import open from 'open';
|
||||
import crypto from 'crypto';
|
||||
import { AuthType } from '../core/contentGenerator.js';
|
||||
import { Config } from '../config/config.js';
|
||||
import readline from 'node:readline';
|
||||
|
||||
vi.mock('google-auth-library');
|
||||
vi.mock('http');
|
||||
vi.mock('open');
|
||||
@@ -170,7 +171,10 @@ describe('oauth2', () => {
|
||||
});
|
||||
|
||||
// Verify the getCachedGoogleAccount function works
|
||||
expect(getCachedGoogleAccount()).toBe('test-google-account@gmail.com');
|
||||
const userAccountManager = new UserAccountManager(new Storage(tempHomeDir));
|
||||
expect(userAccountManager.getCachedGoogleAccount()).toBe(
|
||||
'test-google-account@gmail.com',
|
||||
);
|
||||
});
|
||||
|
||||
it('should perform login with user code', async () => {
|
||||
|
||||
@@ -28,7 +28,12 @@ export class Storage {
|
||||
}
|
||||
|
||||
getGlobalGeminiDir(): string {
|
||||
const geminiDir = path.join(os.homedir(), GEMINI_DIR);
|
||||
const homeDir = os.homedir();
|
||||
if (!homeDir) {
|
||||
// This is a fallback for testing environments where homedir is not defined.
|
||||
return path.join(os.tmpdir(), '.gemini');
|
||||
}
|
||||
const geminiDir = path.join(homeDir, GEMINI_DIR);
|
||||
return geminiDir;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ let mockSendMessageStream: any;
|
||||
|
||||
vi.mock('fs', () => ({
|
||||
statSync: vi.fn(),
|
||||
mkdirSync: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../core/client.js', () => ({
|
||||
|
||||
Reference in New Issue
Block a user