Telemtry(extensions) - Add logging for extension events (#8339)

Co-authored-by: Shi Shu <shii@google.com>
This commit is contained in:
shishu314
2025-09-22 12:55:43 -04:00
committed by GitHub
parent 6c490661ec
commit afc42fa22f
8 changed files with 80 additions and 48 deletions
+33 -19
View File
@@ -24,9 +24,8 @@ import {
import {
GEMINI_DIR,
type GeminiCLIExtension,
ClearcutLogger,
type Config,
ExtensionUninstallEvent,
ExtensionEnableEvent,
} from '@google/gemini-cli-core';
import { execSync } from 'node:child_process';
import { SettingScope } from './settings.js';
@@ -69,20 +68,18 @@ vi.mock('./trustedFolders.js', async (importOriginal) => {
};
});
const mockLogExtensionEnable = vi.hoisted(() => vi.fn());
const mockLogExtensionInstallEvent = vi.hoisted(() => vi.fn());
const mockLogExtensionUninstall = vi.hoisted(() => vi.fn());
vi.mock('@google/gemini-cli-core', async (importOriginal) => {
const actual =
await importOriginal<typeof import('@google/gemini-cli-core')>();
const mockLogExtensionInstallEvent = vi.fn();
const mockLogExtensionUninstallEvent = vi.fn();
return {
...actual,
ClearcutLogger: {
getInstance: vi.fn(() => ({
logExtensionInstallEvent: mockLogExtensionInstallEvent,
logExtensionUninstallEvent: mockLogExtensionUninstallEvent,
})),
},
Config: vi.fn(),
logExtensionEnable: mockLogExtensionEnable,
logExtensionInstallEvent: mockLogExtensionInstallEvent,
logExtensionUninstall: mockLogExtensionUninstall,
ExtensionEnableEvent: vi.fn(),
ExtensionInstallEvent: vi.fn(),
ExtensionUninstallEvent: vi.fn(),
};
@@ -763,8 +760,7 @@ describe('extension tests', () => {
await installExtension({ source: sourceExtDir, type: 'local' });
const logger = ClearcutLogger.getInstance({} as Config);
expect(logger?.logExtensionInstallEvent).toHaveBeenCalled();
expect(mockLogExtensionInstallEvent).toHaveBeenCalled();
});
it('should show users information on their mcp server when installing', async () => {
@@ -948,9 +944,10 @@ describe('extension tests', () => {
await uninstallExtension('my-local-extension');
const logger = ClearcutLogger.getInstance({} as Config);
expect(logger?.logExtensionUninstallEvent).toHaveBeenCalledWith(
new ExtensionUninstallEvent('my-local-extension', 'success'),
expect(mockLogExtensionUninstall).toHaveBeenCalled();
expect(ExtensionUninstallEvent).toHaveBeenCalledWith(
'my-local-extension',
'success',
);
});
@@ -969,9 +966,10 @@ describe('extension tests', () => {
await uninstallExtension(gitUrl);
expect(fs.existsSync(sourceExtDir)).toBe(false);
const logger = ClearcutLogger.getInstance({} as Config);
expect(logger?.logExtensionUninstallEvent).toHaveBeenCalledWith(
new ExtensionUninstallEvent('gemini-sql-extension', 'success'),
expect(mockLogExtensionUninstall).toHaveBeenCalled();
expect(ExtensionUninstallEvent).toHaveBeenCalledWith(
'gemini-sql-extension',
'success',
);
});
@@ -1233,6 +1231,22 @@ describe('extension tests', () => {
expect(activeExtensions).toHaveLength(1);
expect(activeExtensions[0].name).toBe('ext1');
});
it('should log an enable event', () => {
createExtension({
extensionsDir: userExtensionsDir,
name: 'ext1',
version: '1.0.0',
});
disableExtension('ext1', SettingScope.Workspace);
enableExtension('ext1', SettingScope.Workspace);
expect(mockLogExtensionEnable).toHaveBeenCalled();
expect(ExtensionEnableEvent).toHaveBeenCalledWith(
'ext1',
SettingScope.Workspace,
);
});
});
});