mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-12 12:54:07 -07:00
clean up extension tests (#10857)
This commit is contained in:
@@ -20,7 +20,6 @@ import {
|
|||||||
loadExtensionConfig,
|
loadExtensionConfig,
|
||||||
loadExtensions,
|
loadExtensions,
|
||||||
performWorkspaceExtensionMigration,
|
performWorkspaceExtensionMigration,
|
||||||
requestConsentNonInteractive,
|
|
||||||
uninstallExtension,
|
uninstallExtension,
|
||||||
} from './extension.js';
|
} from './extension.js';
|
||||||
import {
|
import {
|
||||||
@@ -99,15 +98,6 @@ vi.mock('child_process', async (importOriginal) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const mockQuestion = vi.hoisted(() => vi.fn());
|
|
||||||
const mockClose = vi.hoisted(() => vi.fn());
|
|
||||||
vi.mock('node:readline', () => ({
|
|
||||||
createInterface: vi.fn(() => ({
|
|
||||||
question: mockQuestion,
|
|
||||||
close: mockClose,
|
|
||||||
})),
|
|
||||||
}));
|
|
||||||
|
|
||||||
const EXTENSIONS_DIRECTORY_NAME = path.join(GEMINI_DIR, 'extensions');
|
const EXTENSIONS_DIRECTORY_NAME = path.join(GEMINI_DIR, 'extensions');
|
||||||
|
|
||||||
describe('extension tests', () => {
|
describe('extension tests', () => {
|
||||||
@@ -128,7 +118,6 @@ describe('extension tests', () => {
|
|||||||
vi.mocked(os.homedir).mockReturnValue(tempHomeDir);
|
vi.mocked(os.homedir).mockReturnValue(tempHomeDir);
|
||||||
vi.mocked(isWorkspaceTrusted).mockReturnValue(true);
|
vi.mocked(isWorkspaceTrusted).mockReturnValue(true);
|
||||||
vi.spyOn(process, 'cwd').mockReturnValue(tempWorkspaceDir);
|
vi.spyOn(process, 'cwd').mockReturnValue(tempWorkspaceDir);
|
||||||
mockQuestion.mockImplementation((_query, callback) => callback('y'));
|
|
||||||
vi.mocked(execSync).mockClear();
|
vi.mocked(execSync).mockClear();
|
||||||
Object.values(mockGit).forEach((fn) => fn.mockReset());
|
Object.values(mockGit).forEach((fn) => fn.mockReset());
|
||||||
});
|
});
|
||||||
@@ -137,8 +126,6 @@ describe('extension tests', () => {
|
|||||||
fs.rmSync(tempHomeDir, { recursive: true, force: true });
|
fs.rmSync(tempHomeDir, { recursive: true, force: true });
|
||||||
fs.rmSync(tempWorkspaceDir, { recursive: true, force: true });
|
fs.rmSync(tempWorkspaceDir, { recursive: true, force: true });
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
mockQuestion.mockClear();
|
|
||||||
mockClose.mockClear();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('loadExtensions', () => {
|
describe('loadExtensions', () => {
|
||||||
@@ -806,8 +793,8 @@ describe('extension tests', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should install an extension from a git URL', async () => {
|
it('should install an extension from a git URL', async () => {
|
||||||
const gitUrl = 'https://github.com/google/gemini-extensions.git';
|
const gitUrl = 'https://somehost.com/somerepo.git';
|
||||||
const extensionName = 'gemini-extensions';
|
const extensionName = 'some-extension';
|
||||||
const targetExtDir = path.join(userExtensionsDir, extensionName);
|
const targetExtDir = path.join(userExtensionsDir, extensionName);
|
||||||
const metadataPath = path.join(targetExtDir, INSTALL_METADATA_FILENAME);
|
const metadataPath = path.join(targetExtDir, INSTALL_METADATA_FILENAME);
|
||||||
|
|
||||||
@@ -834,7 +821,6 @@ describe('extension tests', () => {
|
|||||||
source: gitUrl,
|
source: gitUrl,
|
||||||
type: 'git',
|
type: 'git',
|
||||||
});
|
});
|
||||||
fs.rmSync(targetExtDir, { recursive: true, force: true });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should install a linked extension', async () => {
|
it('should install a linked extension', async () => {
|
||||||
@@ -881,7 +867,6 @@ describe('extension tests', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should show users information on their ansi escaped mcp servers when installing', async () => {
|
it('should show users information on their ansi escaped mcp servers when installing', async () => {
|
||||||
const consoleInfoSpy = vi.spyOn(console, 'info');
|
|
||||||
const sourceExtDir = createExtension({
|
const sourceExtDir = createExtension({
|
||||||
extensionsDir: tempHomeDir,
|
extensionsDir: tempHomeDir,
|
||||||
name: 'my-local-extension',
|
name: 'my-local-extension',
|
||||||
@@ -899,16 +884,17 @@ describe('extension tests', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
mockQuestion.mockImplementation((_query, callback) => callback('y'));
|
const mockRequestConsent = vi.fn();
|
||||||
|
mockRequestConsent.mockResolvedValue(true);
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
installExtension(
|
installExtension(
|
||||||
{ source: sourceExtDir, type: 'local' },
|
{ source: sourceExtDir, type: 'local' },
|
||||||
requestConsentNonInteractive,
|
mockRequestConsent,
|
||||||
),
|
),
|
||||||
).resolves.toBe('my-local-extension');
|
).resolves.toBe('my-local-extension');
|
||||||
|
|
||||||
expect(consoleInfoSpy).toHaveBeenCalledWith(
|
expect(mockRequestConsent).toHaveBeenCalledWith(
|
||||||
`Installing extension "my-local-extension".
|
`Installing extension "my-local-extension".
|
||||||
**Extensions may introduce unexpected behavior. Ensure you have investigated the extension source and trust the author.**
|
**Extensions may introduce unexpected behavior. Ensure you have investigated the extension source and trust the author.**
|
||||||
This extension will run the following MCP servers:
|
This extension will run the following MCP servers:
|
||||||
@@ -930,19 +916,12 @@ This extension will run the following MCP servers:
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
mockQuestion.mockImplementation((_query, callback) => callback('y'));
|
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
installExtension(
|
installExtension(
|
||||||
{ source: sourceExtDir, type: 'local' },
|
{ source: sourceExtDir, type: 'local' },
|
||||||
requestConsentNonInteractive,
|
async () => true,
|
||||||
),
|
),
|
||||||
).resolves.toBe('my-local-extension');
|
).resolves.toBe('my-local-extension');
|
||||||
|
|
||||||
expect(mockQuestion).toHaveBeenCalledWith(
|
|
||||||
expect.stringContaining('Do you want to continue? [Y/n]: '),
|
|
||||||
expect.any(Function),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should cancel installation if user declines prompt for local extension with mcp servers', async () => {
|
it('should cancel installation if user declines prompt for local extension with mcp servers', async () => {
|
||||||
@@ -958,19 +937,12 @@ This extension will run the following MCP servers:
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
mockQuestion.mockImplementation((_query, callback) => callback('n'));
|
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
installExtension(
|
installExtension(
|
||||||
{ source: sourceExtDir, type: 'local' },
|
{ source: sourceExtDir, type: 'local' },
|
||||||
requestConsentNonInteractive,
|
async () => false,
|
||||||
),
|
),
|
||||||
).rejects.toThrow('Installation cancelled for "my-local-extension".');
|
).rejects.toThrow('Installation cancelled for "my-local-extension".');
|
||||||
|
|
||||||
expect(mockQuestion).toHaveBeenCalledWith(
|
|
||||||
expect.stringContaining('Do you want to continue? [Y/n]: '),
|
|
||||||
expect.any(Function),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should save the autoUpdate flag to the install metadata', async () => {
|
it('should save the autoUpdate flag to the install metadata', async () => {
|
||||||
@@ -1041,7 +1013,10 @@ This extension will run the following MCP servers:
|
|||||||
});
|
});
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
installExtension({ source: sourceExtDir, type: 'local' }),
|
installExtension(
|
||||||
|
{ source: sourceExtDir, type: 'local' },
|
||||||
|
async () => true,
|
||||||
|
),
|
||||||
).rejects.toThrow('Invalid extension name: "bad_name"');
|
).rejects.toThrow('Invalid extension name: "bad_name"');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user