Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(skillhub): lock imported discovery entries during uninstall

xd-bobo8e63d24e7b12
diff --git a/apps/desktop/src/main/skillhub/__tests__/installService.test.ts b/apps/desktop/src/main/skillhub/__tests__/installService.test.ts
index 68d22e99d3..ef07494de2 100644
--- a/apps/desktop/src/main/skillhub/__tests__/installService.test.ts
+++ b/apps/desktop/src/main/skillhub/__tests__/installService.test.ts
@@ -2079,6 +2079,48 @@ describe('skillhub/installService', () => {
expect(vi.mocked(registryService.addInstall)).not.toHaveBeenCalled();
});
+ it.each(['install-first', 'uninstall-first'])('locks differently named import entries against install (%s)', async (order) => {
+ const source = path.join(TEST_ROOT, 'checkout', 'source');
+ const alias = path.join(TEST_ROOT, '.agents', 'skills', 'alias');
+ fs.mkdirSync(source, { recursive: true });
+ fs.writeFileSync(path.join(source, 'SKILL.md'), 'external content');
+ makeDirectoryLink(alias, source);
+ const { inspectLocalSkillTarget } = await import('../localSkillTarget');
+ const { tryAcquireSkillInstallLock, getSkillInstallLockOwner } = await import('../installLock');
+ const { uninstall, install } = await import('../installService');
+ const { getCurrentUserId } = await import('../../authManager');
+ const { shell } = await import('electron');
+ vi.mocked(getCurrentUserId).mockReturnValue('user-1');
+ const { registryService } = await import('../registry');
+ vi.mocked(registryService.getInstall).mockResolvedValue(null);
+ vi.mocked(registryService.readManifest).mockResolvedValue(null);
+ const target = inspectLocalSkillTarget(source, [alias])!;
+ if (order === 'install-first') {
+ const releaseInstall = tryAcquireSkillInstallLock('alias', 'market-install')!;
+ try {
+ expect((await uninstall(source, target)).success).toBe(false);
+ expect(shell.trashItem).not.toHaveBeenCalled();
+ expect(getSkillInstallLockOwner('source')).toBeNull();
+ } finally { releaseInstall(); }
+ } else {
+ let finishTrash: (() => void) | undefined;
+ vi.mocked(shell.trashItem).mockImplementationOnce(async (entry) => {
+ await new Promise<void>((resolve) => { finishTrash = resolve; });
+ await fs.promises.rename(entry, path.join(TEST_ROOT, 'trashed-alias'));
+ });
+ const removing = uninstall(source, target);
+ await vi.waitFor(() => expect(finishTrash).toBeDefined());
+ try {
+ expect((await install({ name: 'alias', installPath: alias, version: '1' }, () => {})).success).toBe(false);
+ expect(getSkillInstallLockOwner('alias')).toBe('market-uninstall');
+ } finally { finishTrash!(); }
+ expect(await removing).toEqual({ success: true });
+ }
+ expect(fs.readFileSync(path.join(source, 'SKILL.md'), 'utf8')).toBe('external content');
+ expect(getSkillInstallLockOwner('alias')).toBeNull();
+ expect(getSkillInstallLockOwner('source')).toBeNull();
+ });
+
it('rejects uninstall while a learn apply holds the shared lock', async () => {
const dir = path.join(TEST_ROOT, '.agents', 'skills', 'locked-skill');
fs.mkdirSync(dir, { recursive: true });
diff --git a/apps/desktop/src/main/skillhub/installService.ts b/apps/desktop/src/main/skillhub/installService.ts
index a1d0c858ed..7fd9481b89 100644
--- a/apps/desktop/src/main/skillhub/installService.ts
+++ b/apps/desktop/src/main/skillhub/installService.ts
@@ -951,9 +951,16 @@ export async function uninstall(
// 共享安装锁:同名 install / learn apply 的 final-switch 进行中时拒绝删除,
// 避免 rm 掉对方刚切入的目录、registry 写入交错。
- const releaseLock = tryAcquireSkillInstallLock(skillName, 'market-uninstall');
- if (!releaseLock) {
- return { success: false, errorCode: 'INTERNAL', message: skillLockBusyMessage(skillName) };
+ const releaseLocks: Array<() => void> = [];
+ // An imported discovery link can have a different name from its source. Install
+ // replaces that entry under its discovery name, so hold both locks through trash.
+ for (const lockName of new Set([skillName, path.basename(target?.operationPath ?? absolutePath)])) {
+ const release = tryAcquireSkillInstallLock(lockName, 'market-uninstall');
+ if (!release) {
+ for (const unlock of releaseLocks) unlock();
+ return { success: false, errorCode: 'INTERNAL', message: skillLockBusyMessage(lockName) };
+ }
+ releaseLocks.push(release);
}
try {
// Keep the exact registry identity for metadata cleanup after trash succeeds.
@@ -976,7 +983,7 @@ export async function uninstall(
canMutate,
);
} finally {
- releaseLock();
+ for (const unlock of releaseLocks) unlock();
}
}