Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/symlinks/manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { join } from "node:path";
import { tmpdir } from "node:os";
import { ensureSkillsSymlink, verifySymlinks } from "./manager.js";
import { exec } from "../utils/exec.js";

describe("symlinks", () => {
let dir: string;
Expand Down Expand Up @@ -98,6 +99,52 @@ describe("symlinks", () => {
const stat = await lstat(join(targetDir, "skills"));
expect(stat.isSymbolicLink()).toBe(true);
});

it("removes migrated files from git index", async () => {
// Initialize a git repo in the temp dir
await exec("git", ["init"], { cwd: dir });
await exec("git", ["config", "user.email", "test@test.com"], {
cwd: dir,
});
await exec("git", ["config", "user.name", "Test"], { cwd: dir });

// Create a real skills directory with a committed file
const targetDir = join(dir, ".claude");
const realSkillsDir = join(targetDir, "skills");
await mkdir(join(realSkillsDir, "my-skill"), { recursive: true });
await writeFile(
join(realSkillsDir, "my-skill", "SKILL.md"),
"---\nname: test\n---\n",
);

await exec("git", ["add", "."], { cwd: dir });
await exec("git", ["commit", "-m", "initial"], { cwd: dir });

// Verify file is tracked before migration
const { stdout: before } = await exec(
"git",
["ls-files", ".claude/skills/"],
{ cwd: dir },
);
expect(before.trim()).toContain("my-skill/SKILL.md");

// Run the symlink migration
const result = await ensureSkillsSymlink(agentsDir, targetDir);
expect(result.created).toBe(true);
expect(result.migrated).toContain("my-skill");

// Verify file is no longer in git index
const { stdout: after } = await exec(
"git",
["ls-files", ".claude/skills/"],
{ cwd: dir },
);
expect(after.trim()).toBe("");

// Verify the skill was moved to .agents/skills/
const agentsEntries = await readdir(join(agentsDir, "skills"));
expect(agentsEntries).toContain("my-skill");
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Symlink tests now require git installed

Medium Severity

The new test invokes exec("git", ...) directly, so the suite fails in environments where git isn’t available on PATH (or is blocked by sandboxing). This introduces a new external dependency for running vitest that can break CI or downstream consumers running tests in minimal containers.

Fix in Cursor Fix in Web

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

False positive — the test suite already requires git. Four other test files (install.test.ts, update.test.ts, remove.test.ts, resolver.integration.test.ts) call exec("git", ...) directly.

});

describe("verifySymlinks", () => {
Expand Down
17 changes: 17 additions & 0 deletions src/symlinks/manager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { symlink, readlink, unlink, mkdir, lstat, readdir } from "node:fs/promises";
import { join, relative } from "node:path";
import { exec } from "../utils/exec.js";

export class SymlinkError extends Error {
constructor(message: string) {
Expand Down Expand Up @@ -48,6 +49,7 @@ export async function ensureSkillsSymlink(
// Real directory - migrate contents then replace with symlink
if (stat.isDirectory()) {
const migrated = await migrateDirectory(skillsLink, skillsSource);
await removeFromGitIndex(targetDir, "skills");
await rmdir(skillsLink);
await symlink(relativeTarget, skillsLink);
return { created: true, migrated };
Expand Down Expand Up @@ -90,6 +92,21 @@ async function rmdir(dir: string): Promise<void> {
await rm(dir, { recursive: true });
}

/**
* Best-effort removal of tracked files from git's index.
* Prevents "beyond a symbolic link" errors when a tracked directory
* is replaced by a symlink.
*/
async function removeFromGitIndex(cwd: string, path: string): Promise<void> {
try {
await exec("git", ["rm", "-r", "--cached", "--ignore-unmatch", path], {
cwd,
});
} catch {
// Silently ignore: not a git repo, git not installed, etc.
}
}

/**
* Verify all configured symlinks are correct.
* Returns a list of issues found.
Expand Down