Skip to content

The agent that grows with you

fix(desktop): a refused forced reinstall keeps the installed desktop plugin

Teknium3dbd91639a4b
diff --git a/apps/desktop/electron/desktop-plugin-install.test.ts b/apps/desktop/electron/desktop-plugin-install.test.ts
index 892fd306c67..f529f4e6b78 100644
--- a/apps/desktop/electron/desktop-plugin-install.test.ts
+++ b/apps/desktop/electron/desktop-plugin-install.test.ts
@@ -317,6 +317,35 @@ describe('installDesktopPluginFromGit', () => {
expect(fs.readdirSync(appRoot)).toEqual([])
})
+ it('keeps the installed plugin when a forced reinstall refuses the new tree', async () => {
+ const repo = pluginRepo(null, { 'panel.js': 'working\n' })
+ const git = (...args: string[]) => execFileSync('git', args, { cwd: repo, stdio: 'pipe' })
+ const appRoot = mkdtemp('hermes-plugin-root-')
+ roots.push(appRoot)
+ const installed = await installDesktopPluginFromGit('git', pathToFileURL(repo).href, appRoot)
+ expect(installed).toMatchObject({ ok: true })
+ fs.symlinkSync('/etc/hostname', path.join(repo, 'desktop', 'leak.txt'))
+ git('add', '-A')
+ git('-c', '[email protected]', '-c', 'user.name=F', 'commit', '-qm', 'link')
+
+ const refused = await installDesktopPluginFromGit('git', pathToFileURL(repo).href, appRoot, true)
+
+ expect(refused.ok).toBe(false)
+ expect(refused.error).toContain('symbolic link')
+ expect(fs.readdirSync(appRoot)).toEqual([installed.pluginName])
+ expect(fs.readFileSync(path.join(appRoot, installed.pluginName!, 'panel.js'), 'utf8')).toBe('working\n')
+ expect(fs.existsSync(path.join(appRoot, installed.pluginName!, 'plugin.js'))).toBe(true)
+
+ // A plain replacement tree still replaces it.
+ fs.rmSync(path.join(repo, 'desktop', 'leak.txt'))
+ fs.writeFileSync(path.join(repo, 'desktop', 'panel.js'), 'replaced\n')
+ git('add', '-A')
+ git('-c', '[email protected]', '-c', 'user.name=F', 'commit', '-qm', 'plain')
+ expect(await installDesktopPluginFromGit('git', pathToFileURL(repo).href, appRoot, true)).toMatchObject({ ok: true })
+ expect(fs.readdirSync(appRoot)).toEqual([installed.pluginName])
+ expect(fs.readFileSync(path.join(appRoot, installed.pluginName!, 'panel.js'), 'utf8')).toBe('replaced\n')
+ })
+
it('stamps the package marker on a unified package half and names the folder after the agent package', async () => {
// Without the marker the Plugins page has no evidence that this copy is the
// agent row's desktop half: the row sits on "copying…" while the copy shows
diff --git a/apps/desktop/electron/desktop-plugin-install.ts b/apps/desktop/electron/desktop-plugin-install.ts
index d4e0113fe6a..940f39327fd 100644
--- a/apps/desktop/electron/desktop-plugin-install.ts
+++ b/apps/desktop/electron/desktop-plugin-install.ts
@@ -553,15 +553,13 @@ export async function installDesktopPluginFromGit(
// Under the root's writer lock: the exists check and the publish must not
// interleave with a reconcile pass copying the same package folder.
return await withDesktopPluginsRoot<DesktopPluginInstallResult>(desktopPluginsRoot, async () => {
- if ((await pathIsDirectory(targetDir)) || (await pathIsFile(targetPlugin))) {
- if (!force) {
- return {
- ok: false,
- error: `Desktop plugin '${pluginName}' already exists. Enable force reinstall to replace it.`
- }
+ // Force replaces the folder only once the new tree has passed its checks and been staged
+ // (publishDesktopTree): a refused reinstall keeps the working copy.
+ if (!force && ((await pathIsDirectory(targetDir)) || (await pathIsFile(targetPlugin)))) {
+ return {
+ ok: false,
+ error: `Desktop plugin '${pluginName}' already exists. Enable force reinstall to replace it.`
}
-
- await fsp.rm(targetDir, { recursive: true, force: true })
}
// Staged copy + rename: a failed copy must not leave an empty `targetDir`