feat(skills): auto-backup skill files before uninstall

Create a local backup under ~/.cc-switch/skill-backups/ before removing
skill directories. The backup includes all skill files and a meta.json
with original skill metadata. Old backups are pruned to keep at most 20.
The backup path is returned to the frontend and shown in the success
toast. Bump version to 3.12.3.
This commit is contained in:
Jason
2026-03-15 23:26:50 +08:00
parent 04254d6ffe
commit 9336001746
20 changed files with 850 additions and 28 deletions
@@ -0,0 +1,94 @@
import { createRef } from "react";
import { render, screen, waitFor, act } from "@testing-library/react";
import { describe, expect, it, vi, beforeEach } from "vitest";
import UnifiedSkillsPanel, {
type UnifiedSkillsPanelHandle,
} from "@/components/skills/UnifiedSkillsPanel";
const scanUnmanagedMock = vi.fn();
const toggleSkillAppMock = vi.fn();
const uninstallSkillMock = vi.fn();
const importSkillsMock = vi.fn();
const installFromZipMock = vi.fn();
vi.mock("sonner", () => ({
toast: {
success: vi.fn(),
error: vi.fn(),
info: vi.fn(),
},
}));
vi.mock("@/hooks/useSkills", () => ({
useInstalledSkills: () => ({
data: [],
isLoading: false,
}),
useToggleSkillApp: () => ({
mutateAsync: toggleSkillAppMock,
}),
useUninstallSkill: () => ({
mutateAsync: uninstallSkillMock,
}),
useScanUnmanagedSkills: () => ({
data: [
{
directory: "shared-skill",
name: "Shared Skill",
description: "Imported from Claude",
foundIn: ["claude"],
path: "/tmp/shared-skill",
},
],
refetch: scanUnmanagedMock,
}),
useImportSkillsFromApps: () => ({
mutateAsync: importSkillsMock,
}),
useInstallSkillsFromZip: () => ({
mutateAsync: installFromZipMock,
}),
}));
describe("UnifiedSkillsPanel", () => {
beforeEach(() => {
scanUnmanagedMock.mockResolvedValue({
data: [
{
directory: "shared-skill",
name: "Shared Skill",
description: "Imported from Claude",
foundIn: ["claude"],
path: "/tmp/shared-skill",
},
],
});
toggleSkillAppMock.mockReset();
uninstallSkillMock.mockReset();
importSkillsMock.mockReset();
installFromZipMock.mockReset();
});
it("opens the import dialog without crashing when app toggles render", async () => {
const ref = createRef<UnifiedSkillsPanelHandle>();
render(
<UnifiedSkillsPanel
ref={ref}
onOpenDiscovery={() => {}}
currentApp="claude"
/>,
);
await act(async () => {
await ref.current?.openImport();
});
await waitFor(() => {
expect(screen.getByText("skills.import")).toBeInTheDocument();
expect(screen.getByText("Shared Skill")).toBeInTheDocument();
expect(screen.getByText("/tmp/shared-skill")).toBeInTheDocument();
});
});
});