metrics(extension) - Add logging for disable extension (#9238)

Co-authored-by: Shi Shu <shii@google.com>
This commit is contained in:
shishu314
2025-09-23 14:37:35 -04:00
committed by GitHub
parent 31c609daec
commit 98461ff667
9 changed files with 123 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ import {
GEMINI_DIR,
type GeminiCLIExtension,
ExtensionUninstallEvent,
ExtensionDisableEvent,
ExtensionEnableEvent,
} from '@google/gemini-cli-core';
import { execSync } from 'node:child_process';
@@ -71,6 +72,7 @@ vi.mock('./trustedFolders.js', async (importOriginal) => {
const mockLogExtensionEnable = vi.hoisted(() => vi.fn());
const mockLogExtensionInstallEvent = vi.hoisted(() => vi.fn());
const mockLogExtensionUninstall = vi.hoisted(() => vi.fn());
const mockLogExtensionDisable = vi.hoisted(() => vi.fn());
vi.mock('@google/gemini-cli-core', async (importOriginal) => {
const actual =
await importOriginal<typeof import('@google/gemini-cli-core')>();
@@ -79,9 +81,11 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
logExtensionEnable: mockLogExtensionEnable,
logExtensionInstallEvent: mockLogExtensionInstallEvent,
logExtensionUninstall: mockLogExtensionUninstall,
logExtensionDisable: mockLogExtensionDisable,
ExtensionEnableEvent: vi.fn(),
ExtensionInstallEvent: vi.fn(),
ExtensionUninstallEvent: vi.fn(),
ExtensionDisableEvent: vi.fn(),
};
});
@@ -1178,6 +1182,16 @@ This extension will run the following MCP servers:
disableExtension('my-extension', SettingScope.System),
).toThrow('System and SystemDefaults scopes are not supported.');
});
it('should log a disable event', () => {
disableExtension('ext1', SettingScope.Workspace);
expect(mockLogExtensionDisable).toHaveBeenCalled();
expect(ExtensionDisableEvent).toHaveBeenCalledWith(
'ext1',
SettingScope.Workspace,
);
});
});
describe('enableExtension', () => {

View File

@@ -15,10 +15,12 @@ import {
Config,
ExtensionInstallEvent,
ExtensionUninstallEvent,
ExtensionDisableEvent,
ExtensionEnableEvent,
logExtensionEnable,
logExtensionInstallEvent,
logExtensionUninstall,
logExtensionDisable,
} from '@google/gemini-cli-core';
import * as fs from 'node:fs';
import * as path from 'node:path';
@@ -648,6 +650,7 @@ export function disableExtension(
scope: SettingScope,
cwd: string = process.cwd(),
) {
const config = getTelemetryConfig(cwd);
if (scope === SettingScope.System || scope === SettingScope.SystemDefaults) {
throw new Error('System and SystemDefaults scopes are not supported.');
}
@@ -657,6 +660,7 @@ export function disableExtension(
);
const scopePath = scope === SettingScope.Workspace ? cwd : os.homedir();
manager.disable(name, true, scopePath);
logExtensionDisable(config, new ExtensionDisableEvent(name, scope));
}
export function enableExtension(