mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-15 04:20:57 -07:00
add extension IDs (#11377)
This commit is contained in:
@@ -8,6 +8,7 @@ import { vi } from 'vitest';
|
||||
import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
import { createHash } from 'node:crypto';
|
||||
import {
|
||||
EXTENSIONS_CONFIG_FILENAME,
|
||||
ExtensionStorage,
|
||||
@@ -509,6 +510,163 @@ describe('extension tests', () => {
|
||||
);
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
|
||||
describe('id generation', () => {
|
||||
it('should generate id from source for non-github git urls', () => {
|
||||
const extensionDir = createExtension({
|
||||
extensionsDir: userExtensionsDir,
|
||||
name: 'my-ext',
|
||||
version: '1.0.0',
|
||||
installMetadata: {
|
||||
type: 'git',
|
||||
source: 'http://somehost.com/foo/bar',
|
||||
},
|
||||
});
|
||||
|
||||
const extension = loadExtension({
|
||||
extensionDir,
|
||||
workspaceDir: tempWorkspaceDir,
|
||||
});
|
||||
|
||||
const expectedHash = createHash('sha256')
|
||||
.update('http://somehost.com/foo/bar')
|
||||
.digest('hex');
|
||||
expect(extension?.id).toBe(expectedHash);
|
||||
});
|
||||
|
||||
it('should generate id from owner/repo for github http urls', () => {
|
||||
const extensionDir = createExtension({
|
||||
extensionsDir: userExtensionsDir,
|
||||
name: 'my-ext',
|
||||
version: '1.0.0',
|
||||
installMetadata: {
|
||||
type: 'git',
|
||||
source: 'http://github.com/foo/bar',
|
||||
},
|
||||
});
|
||||
|
||||
const extension = loadExtension({
|
||||
extensionDir,
|
||||
workspaceDir: tempWorkspaceDir,
|
||||
});
|
||||
|
||||
const expectedHash = createHash('sha256')
|
||||
.update('https://github.com/foo/bar')
|
||||
.digest('hex');
|
||||
expect(extension?.id).toBe(expectedHash);
|
||||
});
|
||||
|
||||
it('should generate id from owner/repo for github ssh urls', () => {
|
||||
const extensionDir = createExtension({
|
||||
extensionsDir: userExtensionsDir,
|
||||
name: 'my-ext',
|
||||
version: '1.0.0',
|
||||
installMetadata: {
|
||||
type: 'git',
|
||||
source: 'git@github.com:foo/bar',
|
||||
},
|
||||
});
|
||||
|
||||
const extension = loadExtension({
|
||||
extensionDir,
|
||||
workspaceDir: tempWorkspaceDir,
|
||||
});
|
||||
|
||||
const expectedHash = createHash('sha256')
|
||||
.update('https://github.com/foo/bar')
|
||||
.digest('hex');
|
||||
expect(extension?.id).toBe(expectedHash);
|
||||
});
|
||||
|
||||
it('should generate id from source for github-release extension', () => {
|
||||
const extensionDir = createExtension({
|
||||
extensionsDir: userExtensionsDir,
|
||||
name: 'my-ext',
|
||||
version: '1.0.0',
|
||||
installMetadata: {
|
||||
type: 'github-release',
|
||||
source: 'https://github.com/foo/bar',
|
||||
},
|
||||
});
|
||||
|
||||
const extension = loadExtension({
|
||||
extensionDir,
|
||||
workspaceDir: tempWorkspaceDir,
|
||||
});
|
||||
|
||||
const expectedHash = createHash('sha256')
|
||||
.update('https://github.com/foo/bar')
|
||||
.digest('hex');
|
||||
expect(extension?.id).toBe(expectedHash);
|
||||
});
|
||||
|
||||
it('should generate id from the original source for local extension', () => {
|
||||
const extensionDir = createExtension({
|
||||
extensionsDir: userExtensionsDir,
|
||||
name: 'local-ext-name',
|
||||
version: '1.0.0',
|
||||
installMetadata: {
|
||||
type: 'local',
|
||||
source: '/some/path',
|
||||
},
|
||||
});
|
||||
|
||||
const extension = loadExtension({
|
||||
extensionDir,
|
||||
workspaceDir: tempWorkspaceDir,
|
||||
});
|
||||
|
||||
const expectedHash = createHash('sha256')
|
||||
.update('/some/path')
|
||||
.digest('hex');
|
||||
expect(extension?.id).toBe(expectedHash);
|
||||
});
|
||||
|
||||
it('should generate id from the original source for linked extensions', async () => {
|
||||
const extDevelopmentDir = path.join(tempHomeDir, 'local_extensions');
|
||||
const actualExtensionDir = createExtension({
|
||||
extensionsDir: extDevelopmentDir,
|
||||
name: 'link-ext-name',
|
||||
version: '1.0.0',
|
||||
});
|
||||
const extensionName = await installOrUpdateExtension(
|
||||
{
|
||||
type: 'link',
|
||||
source: actualExtensionDir,
|
||||
},
|
||||
async () => true,
|
||||
tempWorkspaceDir,
|
||||
);
|
||||
|
||||
const extension = loadExtension({
|
||||
extensionDir: new ExtensionStorage(extensionName).getExtensionDir(),
|
||||
workspaceDir: tempWorkspaceDir,
|
||||
});
|
||||
|
||||
const expectedHash = createHash('sha256')
|
||||
.update(actualExtensionDir)
|
||||
.digest('hex');
|
||||
expect(extension?.id).toBe(expectedHash);
|
||||
});
|
||||
|
||||
it('should generate id from name for extension with no install metadata', () => {
|
||||
const extensionDir = createExtension({
|
||||
extensionsDir: userExtensionsDir,
|
||||
name: 'no-meta-name',
|
||||
version: '1.0.0',
|
||||
});
|
||||
|
||||
const extension = loadExtension({
|
||||
extensionDir,
|
||||
workspaceDir: tempWorkspaceDir,
|
||||
});
|
||||
|
||||
const expectedHash = createHash('sha256')
|
||||
.update('no-meta-name')
|
||||
.digest('hex');
|
||||
expect(extension?.id).toBe(expectedHash);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('annotateActiveExtensions', () => {
|
||||
|
||||
Reference in New Issue
Block a user