-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathpath-resolution.test.ts
More file actions
94 lines (81 loc) · 3.69 KB
/
path-resolution.test.ts
File metadata and controls
94 lines (81 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { describe, test, before, after } from "node:test";
import * as assert from "node:assert";
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import { discoverAgents } from "./agents.ts";
import { resolveSkillPath, clearSkillCache } from "./skills.ts";
const tmpDir = path.join(os.tmpdir(), "pi-path-resolution-test");
const cwdDir = path.join(tmpDir, "cwd");
const realHomeDir = os.homedir();
const realUserAgentsDir = path.join(realHomeDir, ".agents");
const userAgentsDirBackup = path.join(tmpDir, ".agents_backup");
before(() => {
fs.mkdirSync(cwdDir, { recursive: true });
if (fs.existsSync(realUserAgentsDir)) {
fs.cpSync(realUserAgentsDir, userAgentsDirBackup, { recursive: true });
}
});
after(() => {
if (fs.existsSync(userAgentsDirBackup)) {
fs.rmSync(realUserAgentsDir, { recursive: true, force: true });
fs.cpSync(userAgentsDirBackup, realUserAgentsDir, { recursive: true });
} else {
fs.rmSync(realUserAgentsDir, { recursive: true, force: true });
}
fs.rmSync(tmpDir, { recursive: true, force: true });
});
describe("Path resolution for .agents and ~/.agents", () => {
test("should resolve skills in .agents/skills", () => {
const skillsDir = path.join(cwdDir, ".agents", "skills");
fs.mkdirSync(skillsDir, { recursive: true });
fs.writeFileSync(path.join(skillsDir, "test-skill-1.md"), "---\nname: test-skill-1\ndescription: test desc\n---\nSkill content");
clearSkillCache();
const resolved = resolveSkillPath("test-skill-1", cwdDir);
assert.ok(resolved);
assert.strictEqual(resolved?.path, path.join(skillsDir, "test-skill-1.md"));
});
test("should resolve skills in ~/.agents/skills", () => {
const userSkillsDir = path.join(realHomeDir, ".agents", "skills");
fs.mkdirSync(userSkillsDir, { recursive: true });
fs.writeFileSync(path.join(userSkillsDir, "test-skill-2.md"), "---\nname: test-skill-2\ndescription: test desc\n---\nSkill content");
clearSkillCache();
const resolved = resolveSkillPath("test-skill-2", cwdDir);
assert.ok(resolved);
assert.strictEqual(resolved?.path, path.join(userSkillsDir, "test-skill-2.md"));
});
test("should resolve project agents from both .agents and .pi/agents", () => {
const legacyDir = path.join(cwdDir, ".agents");
const agentsDir = path.join(cwdDir, ".pi", "agents");
fs.mkdirSync(path.join(cwdDir, ".agents", "skills"), { recursive: true });
fs.mkdirSync(legacyDir, { recursive: true });
fs.mkdirSync(agentsDir, { recursive: true });
fs.writeFileSync(
path.join(legacyDir, "test-agent-legacy.md"),
"---\nname: test-agent-legacy\ndescription: Legacy agent\n---\nLegacy content"
);
fs.writeFileSync(
path.join(agentsDir, "test-agent-1.md"),
"---\nname: test-agent-1\ndescription: Test agent\n---\nAgent content"
);
const result = discoverAgents(cwdDir, "project");
const legacyAgent = result.agents.find((a) => a.name === "test-agent-legacy");
const agent = result.agents.find((a) => a.name === "test-agent-1");
assert.ok(legacyAgent);
assert.strictEqual(legacyAgent?.filePath, path.join(legacyDir, "test-agent-legacy.md"));
assert.ok(agent);
assert.strictEqual(agent?.filePath, path.join(agentsDir, "test-agent-1.md"));
});
test("should resolve agents in ~/.agents", () => {
const userAgentsDir = path.join(realHomeDir, ".agents");
fs.mkdirSync(userAgentsDir, { recursive: true });
fs.writeFileSync(
path.join(userAgentsDir, "test-agent-2.md"),
"---\nname: test-agent-2\ndescription: Test agent\n---\nAgent content"
);
const result = discoverAgents(cwdDir, "user");
const agent = result.agents.find((a) => a.name === "test-agent-2");
assert.ok(agent);
assert.strictEqual(agent?.filePath, path.join(userAgentsDir, "test-agent-2.md"));
});
});