mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-20 18:14:29 -07:00
Remove separate --path argument for extensions install command (#10628)
This commit is contained in:
@@ -10,6 +10,7 @@ import yargs from 'yargs';
|
||||
|
||||
const mockInstallExtension = vi.hoisted(() => vi.fn());
|
||||
const mockRequestConsentNonInteractive = vi.hoisted(() => vi.fn());
|
||||
const mockStat = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock('../../config/extension.js', () => ({
|
||||
installExtension: mockInstallExtension,
|
||||
@@ -20,35 +21,20 @@ vi.mock('../../utils/errors.js', () => ({
|
||||
getErrorMessage: vi.fn((error: Error) => error.message),
|
||||
}));
|
||||
|
||||
vi.mock('node:fs/promises', () => ({
|
||||
stat: mockStat,
|
||||
default: {
|
||||
stat: mockStat,
|
||||
},
|
||||
}));
|
||||
|
||||
describe('extensions install command', () => {
|
||||
it('should fail if no source is provided', () => {
|
||||
const validationParser = yargs([]).command(installCommand).fail(false);
|
||||
expect(() => validationParser.parse('install')).toThrow(
|
||||
'Either source or --path must be provided.',
|
||||
'Not enough non-option arguments: got 0, need at least 1',
|
||||
);
|
||||
});
|
||||
|
||||
it('should fail if both git source and local path are provided', () => {
|
||||
const validationParser = yargs([])
|
||||
.command(installCommand)
|
||||
.fail(false)
|
||||
.locale('en');
|
||||
expect(() =>
|
||||
validationParser.parse('install some-url --path /some/path'),
|
||||
).toThrow('Arguments source and path are mutually exclusive');
|
||||
});
|
||||
|
||||
it('should fail if both auto update and local path are provided', () => {
|
||||
const validationParser = yargs([])
|
||||
.command(installCommand)
|
||||
.fail(false)
|
||||
.locale('en');
|
||||
expect(() =>
|
||||
validationParser.parse(
|
||||
'install some-url --path /some/path --auto-update',
|
||||
),
|
||||
).toThrow('Arguments path and auto-update are mutually exclusive');
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleInstall', () => {
|
||||
@@ -67,6 +53,7 @@ describe('handleInstall', () => {
|
||||
afterEach(() => {
|
||||
mockInstallExtension.mockClear();
|
||||
mockRequestConsentNonInteractive.mockClear();
|
||||
mockStat.mockClear();
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
|
||||
@@ -107,13 +94,12 @@ describe('handleInstall', () => {
|
||||
});
|
||||
|
||||
it('throws an error from an unknown source', async () => {
|
||||
mockStat.mockRejectedValue(new Error('ENOENT: no such file or directory'));
|
||||
await handleInstall({
|
||||
source: 'test://google.com',
|
||||
});
|
||||
|
||||
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
||||
'The source "test://google.com" is not a valid URL format.',
|
||||
);
|
||||
expect(consoleErrorSpy).toHaveBeenCalledWith('Install source not found.');
|
||||
expect(processSpy).toHaveBeenCalledWith(1);
|
||||
});
|
||||
|
||||
@@ -131,9 +117,9 @@ describe('handleInstall', () => {
|
||||
|
||||
it('should install an extension from a local path', async () => {
|
||||
mockInstallExtension.mockResolvedValue('local-extension');
|
||||
|
||||
mockStat.mockResolvedValue({});
|
||||
await handleInstall({
|
||||
path: '/some/path',
|
||||
source: '/some/path',
|
||||
});
|
||||
|
||||
expect(consoleLogSpy).toHaveBeenCalledWith(
|
||||
@@ -141,15 +127,6 @@ describe('handleInstall', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw an error if no source or path is provided', async () => {
|
||||
await handleInstall({});
|
||||
|
||||
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
||||
'Either --source or --path must be provided.',
|
||||
);
|
||||
expect(processSpy).toHaveBeenCalledWith(1);
|
||||
});
|
||||
|
||||
it('should throw an error if install extension fails', async () => {
|
||||
mockInstallExtension.mockRejectedValue(
|
||||
new Error('Install extension failed'),
|
||||
|
||||
Reference in New Issue
Block a user