fix(extension-uninstallation): Fix uninstalling extensions named differently than their directory name (#12852)

Co-authored-by: Shnatu <snatu@google.com>
This commit is contained in:
Shardul Natu
2025-11-11 10:19:06 -08:00
committed by GitHub
parent ac733d40b3
commit cc2c48d59e
2 changed files with 33 additions and 1 deletions

View File

@@ -390,7 +390,11 @@ export class ExtensionManager extends ExtensionLoader {
throw new Error(`Extension not found.`);
}
await this.unloadExtension(extension);
const storage = new ExtensionStorage(extension.name);
const storage = new ExtensionStorage(
extension.installMetadata?.type === 'link'
? extension.name
: path.basename(extension.path),
);
await fs.promises.rm(storage.getExtensionDir(), {
recursive: true,

View File

@@ -1555,6 +1555,34 @@ This extension will run the following MCP servers:
expect(fs.existsSync(otherExtDir)).toBe(true);
});
it('should uninstall an extension on non-matching extension directory name', async () => {
// Create an extension with a name that differs from the directory name.
const sourceExtDir = createExtension({
extensionsDir: userExtensionsDir,
name: 'My-Local-Extension',
version: '1.0.0',
});
const newSourceExtDir = path.join(
userExtensionsDir,
'my-local-extension',
);
fs.renameSync(sourceExtDir, newSourceExtDir);
const otherExtDir = createExtension({
extensionsDir: userExtensionsDir,
name: 'other-extension',
version: '1.0.0',
});
await extensionManager.loadExtensions();
await extensionManager.uninstallExtension('my-local-extension', false);
expect(fs.existsSync(sourceExtDir)).toBe(false);
expect(fs.existsSync(newSourceExtDir)).toBe(false);
expect(extensionManager.getExtensions()).toHaveLength(1);
expect(fs.existsSync(otherExtDir)).toBe(true);
});
it('should throw an error if the extension does not exist', async () => {
await extensionManager.loadExtensions();
await expect(