mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-12 14:22:00 -07:00
fix: handle missing local extension config and skip hooks when disabled (#14744)
This commit is contained in:
@@ -43,6 +43,7 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||
debugLogger: {
|
||||
error: vi.fn(),
|
||||
log: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
},
|
||||
};
|
||||
});
|
||||
@@ -263,6 +264,25 @@ describe('github.ts', () => {
|
||||
ExtensionUpdateState.UP_TO_DATE,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return NOT_UPDATABLE if local extension config cannot be loaded', async () => {
|
||||
vi.mocked(mockExtensionManager.loadExtensionConfig).mockImplementation(
|
||||
() => {
|
||||
throw new Error('Config not found');
|
||||
},
|
||||
);
|
||||
|
||||
const ext = {
|
||||
name: 'local-ext',
|
||||
version: '1.0.0',
|
||||
path: '/path/to/installed/ext',
|
||||
installMetadata: { type: 'local', source: '/path/to/source/ext' },
|
||||
} as unknown as GeminiCLIExtension;
|
||||
|
||||
expect(await checkForExtensionUpdate(ext, mockExtensionManager)).toBe(
|
||||
ExtensionUpdateState.NOT_UPDATABLE,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('downloadFromGitHubRelease', () => {
|
||||
|
||||
@@ -19,6 +19,7 @@ import * as path from 'node:path';
|
||||
import * as tar from 'tar';
|
||||
import extract from 'extract-zip';
|
||||
import { fetchJson, getGitHubToken } from './github_fetch.js';
|
||||
import type { ExtensionConfig } from '../extension.js';
|
||||
import type { ExtensionManager } from '../extension-manager.js';
|
||||
import { EXTENSIONS_CONFIG_FILENAME } from './variables.js';
|
||||
|
||||
@@ -172,14 +173,23 @@ export async function checkForExtensionUpdate(
|
||||
): Promise<ExtensionUpdateState> {
|
||||
const installMetadata = extension.installMetadata;
|
||||
if (installMetadata?.type === 'local') {
|
||||
const latestConfig = extensionManager.loadExtensionConfig(
|
||||
installMetadata.source,
|
||||
);
|
||||
let latestConfig: ExtensionConfig | undefined;
|
||||
try {
|
||||
latestConfig = extensionManager.loadExtensionConfig(
|
||||
installMetadata.source,
|
||||
);
|
||||
} catch (e) {
|
||||
debugLogger.warn(
|
||||
`Failed to check for update for local extension "${extension.name}". Could not load extension from source path: ${installMetadata.source}. Error: ${getErrorMessage(e)}`,
|
||||
);
|
||||
return ExtensionUpdateState.NOT_UPDATABLE;
|
||||
}
|
||||
|
||||
if (!latestConfig) {
|
||||
debugLogger.error(
|
||||
debugLogger.warn(
|
||||
`Failed to check for update for local extension "${extension.name}". Could not load extension from source path: ${installMetadata.source}`,
|
||||
);
|
||||
return ExtensionUpdateState.ERROR;
|
||||
return ExtensionUpdateState.NOT_UPDATABLE;
|
||||
}
|
||||
if (latestConfig.version !== extension.version) {
|
||||
return ExtensionUpdateState.UPDATE_AVAILABLE;
|
||||
|
||||
Reference in New Issue
Block a user