Throw error for invalid extension names (#9538)

This commit is contained in:
christine betts
2025-09-25 14:05:49 -04:00
committed by GitHub
parent defda3a97d
commit 2d76cdf2c6
3 changed files with 44 additions and 1 deletions
+34
View File
@@ -462,6 +462,28 @@ describe('extension tests', () => {
const loadedConfig = extensions[0].config;
expect(loadedConfig.mcpServers?.['test-server'].trust).toBeUndefined();
});
it('should throw an error for invalid extension names', () => {
const consoleSpy = vi
.spyOn(console, 'error')
.mockImplementation(() => {});
const badExtDir = createExtension({
extensionsDir: userExtensionsDir,
name: 'bad_name',
version: '1.0.0',
});
const extension = loadExtension({
extensionDir: badExtDir,
workspaceDir: tempWorkspaceDir,
});
expect(extension).toBeNull();
expect(consoleSpy).toHaveBeenCalledWith(
expect.stringContaining('Invalid extension name: "bad_name"'),
);
consoleSpy.mockRestore();
});
});
describe('annotateActiveExtensions', () => {
@@ -951,6 +973,18 @@ This extension will run the following MCP servers:
expect(mockRequestConsent).not.toHaveBeenCalled();
});
it('should throw an error for invalid extension names', async () => {
const sourceExtDir = createExtension({
extensionsDir: tempHomeDir,
name: 'bad_name',
version: '1.0.0',
});
await expect(
installExtension({ source: sourceExtDir, type: 'local' }),
).rejects.toThrow('Invalid extension name: "bad_name"');
});
});
describe('uninstallExtension', () => {