fix(coding-agent): avoid duplicate symlinked skills in pi config (#3417)
- dedupe resolved skill entries by canonical path (realpathSync) with raw-path fallback matching loadSkills() - preserve precedence by applying skill dedupe after resource precedence sorting (first winner retained) - add tests to verify expected behavior - closes #3405
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { EventEmitter } from "node:events";
|
||||
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { mkdirSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join, relative } from "node:path";
|
||||
import { PassThrough } from "node:stream";
|
||||
@@ -315,6 +315,35 @@ Content`,
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("should dedupe user skill entries when ~/.pi/agent/skills is a symlink to ~/.agents/skills", async () => {
|
||||
const previousHome = process.env.HOME;
|
||||
process.env.HOME = tempDir;
|
||||
|
||||
try {
|
||||
const agentSkillsDir = join(agentDir, "skills");
|
||||
const agentsSkillsDir = join(tempDir, ".agents", "skills");
|
||||
mkdirSync(agentsSkillsDir, { recursive: true });
|
||||
// Use junction on Windows to avoid EPERM when symlink privileges are unavailable.
|
||||
const directoryLinkType = process.platform === "win32" ? "junction" : "dir";
|
||||
symlinkSync(agentsSkillsDir, agentSkillsDir, directoryLinkType);
|
||||
|
||||
const skillPath = join(agentsSkillsDir, "foo", "SKILL.md");
|
||||
mkdirSync(join(agentsSkillsDir, "foo"), { recursive: true });
|
||||
writeFileSync(skillPath, "---\nname: foo\ndescription: foo\n---\n");
|
||||
|
||||
const result = await packageManager.resolve();
|
||||
const fooSkills = result.skills.filter((r) => pathEndsWith(r.path, "foo/SKILL.md"));
|
||||
|
||||
expect(fooSkills).toHaveLength(1);
|
||||
} finally {
|
||||
if (previousHome === undefined) {
|
||||
delete process.env.HOME;
|
||||
} else {
|
||||
process.env.HOME = previousHome;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("ignore files", () => {
|
||||
|
||||
Reference in New Issue
Block a user