@skills-hub-ai/mcp 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1 -1
- package/dist/index.js +0 -0
- package/package.json +17 -13
- package/src/api.test.ts +0 -211
- package/src/discover.test.ts +0 -163
- package/src/index.test.ts +0 -404
- package/src/installer.test.ts +0 -229
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Team Bearie LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -61,4 +61,4 @@ npx @skills-hub-ai/cli install <skill-name>
|
|
|
61
61
|
- [Browse skills](https://skills-hub.ai/browse)
|
|
62
62
|
- [CLI](https://www.npmjs.com/package/@skills-hub-ai/cli)
|
|
63
63
|
- [Getting Started](https://skills-hub.ai/docs/getting-started)
|
|
64
|
-
- [GitHub](https://github.com/tinh2/skills-hub)
|
|
64
|
+
- [GitHub](https://github.com/tinh2/skills-hub-mcp)
|
package/dist/index.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skills-hub-ai/mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "MCP server for skills-hub.ai — serve installed skills as prompts in any MCP-compatible AI tool",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"mcpName": "io.github.tinh2/skills-hub",
|
|
@@ -26,33 +26,37 @@
|
|
|
26
26
|
],
|
|
27
27
|
"repository": {
|
|
28
28
|
"type": "git",
|
|
29
|
-
"url": "https://github.com/tinh2/skills-hub.git"
|
|
30
|
-
"directory": "apps/mcp"
|
|
29
|
+
"url": "git+https://github.com/tinh2/skills-hub-mcp.git"
|
|
31
30
|
},
|
|
32
31
|
"homepage": "https://skills-hub.ai",
|
|
33
32
|
"files": [
|
|
34
33
|
"dist",
|
|
35
|
-
"src"
|
|
34
|
+
"src",
|
|
35
|
+
"!src/**/*.test.ts"
|
|
36
36
|
],
|
|
37
37
|
"type": "module",
|
|
38
38
|
"bin": {
|
|
39
39
|
"skills-hub-mcp": "dist/index.js"
|
|
40
40
|
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"dev": "tsx src/index.ts",
|
|
43
|
+
"build": "tsc",
|
|
44
|
+
"test": "vitest run --passWithNoTests",
|
|
45
|
+
"lint": "tsc --noEmit",
|
|
46
|
+
"prepublishOnly": "npm run build && npm test"
|
|
47
|
+
},
|
|
41
48
|
"dependencies": {
|
|
42
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
49
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
43
50
|
"@skills-hub-ai/skill-installer": "0.1.0",
|
|
44
51
|
"@skills-hub-ai/skill-parser": "0.2.4"
|
|
45
52
|
},
|
|
46
53
|
"devDependencies": {
|
|
47
54
|
"@types/node": "^25.6.0",
|
|
48
|
-
"tsx": "^4.23.
|
|
55
|
+
"tsx": "^4.23.12",
|
|
49
56
|
"typescript": "^6.0.3",
|
|
50
|
-
"vitest": "^4.1.
|
|
57
|
+
"vitest": "^4.1.11"
|
|
51
58
|
},
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"build": "tsc",
|
|
55
|
-
"test": "vitest run --passWithNoTests",
|
|
56
|
-
"lint": "tsc --noEmit"
|
|
59
|
+
"bugs": {
|
|
60
|
+
"url": "https://github.com/tinh2/skills-hub-mcp/issues"
|
|
57
61
|
}
|
|
58
|
-
}
|
|
62
|
+
}
|
package/src/api.test.ts
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import { searchSkills, getSkillDetail } from "./api.js";
|
|
3
|
-
|
|
4
|
-
const mockFetch = vi.fn();
|
|
5
|
-
vi.stubGlobal("fetch", mockFetch);
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
vi.clearAllMocks();
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
describe("auth header", () => {
|
|
12
|
-
it("omits Authorization header when SKILLS_HUB_API_TOKEN is not set", async () => {
|
|
13
|
-
mockFetch.mockResolvedValue({
|
|
14
|
-
ok: true,
|
|
15
|
-
json: () => Promise.resolve({ data: [] }),
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
await searchSkills("test");
|
|
19
|
-
|
|
20
|
-
const opts = mockFetch.mock.calls[0][1] as RequestInit;
|
|
21
|
-
expect(
|
|
22
|
-
(opts.headers as Record<string, string>)["Authorization"],
|
|
23
|
-
).toBeUndefined();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("omits Authorization header on getSkillDetail when token not set", async () => {
|
|
27
|
-
mockFetch.mockResolvedValue({
|
|
28
|
-
ok: true,
|
|
29
|
-
json: () => Promise.resolve({ slug: "test" }),
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
await getSkillDetail("test-skill");
|
|
33
|
-
|
|
34
|
-
const opts = mockFetch.mock.calls[0][1] as RequestInit;
|
|
35
|
-
expect(
|
|
36
|
-
(opts.headers as Record<string, string>)["Authorization"],
|
|
37
|
-
).toBeUndefined();
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe("searchSkills", () => {
|
|
42
|
-
it("calls search API with query", async () => {
|
|
43
|
-
mockFetch.mockResolvedValue({
|
|
44
|
-
ok: true,
|
|
45
|
-
json: () =>
|
|
46
|
-
Promise.resolve({
|
|
47
|
-
data: [
|
|
48
|
-
{
|
|
49
|
-
slug: "review-code",
|
|
50
|
-
name: "Review Code",
|
|
51
|
-
description: "AI code review",
|
|
52
|
-
qualityScore: 92,
|
|
53
|
-
installCount: 150,
|
|
54
|
-
avgRating: 4.8,
|
|
55
|
-
latestVersion: "1.0.0",
|
|
56
|
-
category: { name: "Review", slug: "review" },
|
|
57
|
-
isComposition: false,
|
|
58
|
-
tags: ["review"],
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
}),
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
const results = await searchSkills("code review");
|
|
65
|
-
|
|
66
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
67
|
-
expect.stringContaining("/api/v1/search?"),
|
|
68
|
-
expect.objectContaining({ signal: expect.any(AbortSignal) }),
|
|
69
|
-
);
|
|
70
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
71
|
-
expect.stringContaining("q=code+review"),
|
|
72
|
-
expect.anything(),
|
|
73
|
-
);
|
|
74
|
-
expect(results).toHaveLength(1);
|
|
75
|
-
expect(results[0].slug).toBe("review-code");
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("passes category filter", async () => {
|
|
79
|
-
mockFetch.mockResolvedValue({
|
|
80
|
-
ok: true,
|
|
81
|
-
json: () => Promise.resolve({ data: [] }),
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
await searchSkills("test", "build");
|
|
85
|
-
|
|
86
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
87
|
-
expect.stringContaining("category=build"),
|
|
88
|
-
expect.anything(),
|
|
89
|
-
);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("passes limit", async () => {
|
|
93
|
-
mockFetch.mockResolvedValue({
|
|
94
|
-
ok: true,
|
|
95
|
-
json: () => Promise.resolve({ data: [] }),
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
await searchSkills("test", undefined, 5);
|
|
99
|
-
|
|
100
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
101
|
-
expect.stringContaining("limit=5"),
|
|
102
|
-
expect.anything(),
|
|
103
|
-
);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("throws on API error", async () => {
|
|
107
|
-
mockFetch.mockResolvedValue({
|
|
108
|
-
ok: false,
|
|
109
|
-
status: 500,
|
|
110
|
-
statusText: "Internal Server Error",
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
await expect(searchSkills("fail")).rejects.toThrow("Search failed: 500");
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("returns empty array when no data", async () => {
|
|
117
|
-
mockFetch.mockResolvedValue({
|
|
118
|
-
ok: true,
|
|
119
|
-
json: () => Promise.resolve({}),
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
const results = await searchSkills("nothing");
|
|
123
|
-
expect(results).toEqual([]);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("passes org query parameter when provided", async () => {
|
|
127
|
-
mockFetch.mockResolvedValue({
|
|
128
|
-
ok: true,
|
|
129
|
-
json: () => Promise.resolve({ data: [] }),
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
await searchSkills("testing", undefined, 10, "my-org");
|
|
133
|
-
|
|
134
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
135
|
-
expect.stringContaining("org=my-org"),
|
|
136
|
-
expect.anything(),
|
|
137
|
-
);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("omits org query parameter when not provided", async () => {
|
|
141
|
-
mockFetch.mockResolvedValue({
|
|
142
|
-
ok: true,
|
|
143
|
-
json: () => Promise.resolve({ data: [] }),
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
await searchSkills("testing");
|
|
147
|
-
|
|
148
|
-
const url = mockFetch.mock.calls[0][0] as string;
|
|
149
|
-
expect(url).not.toContain("org=");
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
describe("getSkillDetail", () => {
|
|
154
|
-
it("fetches skill by slug", async () => {
|
|
155
|
-
const mockSkill = {
|
|
156
|
-
slug: "review-code",
|
|
157
|
-
name: "Review Code",
|
|
158
|
-
description: "AI code review",
|
|
159
|
-
instructions: "Review the code",
|
|
160
|
-
qualityScore: 92,
|
|
161
|
-
installCount: 150,
|
|
162
|
-
avgRating: 4.8,
|
|
163
|
-
latestVersion: "1.0.0",
|
|
164
|
-
category: { name: "Review", slug: "review" },
|
|
165
|
-
platforms: ["CLAUDE_CODE"],
|
|
166
|
-
tags: ["review"],
|
|
167
|
-
isComposition: false,
|
|
168
|
-
composition: null,
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
mockFetch.mockResolvedValue({
|
|
172
|
-
ok: true,
|
|
173
|
-
json: () => Promise.resolve(mockSkill),
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
const result = await getSkillDetail("review-code");
|
|
177
|
-
|
|
178
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
179
|
-
expect.stringContaining("/api/v1/skills/review-code"),
|
|
180
|
-
expect.anything(),
|
|
181
|
-
);
|
|
182
|
-
expect(result.slug).toBe("review-code");
|
|
183
|
-
expect(result.instructions).toBe("Review the code");
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it("throws on not found", async () => {
|
|
187
|
-
mockFetch.mockResolvedValue({
|
|
188
|
-
ok: false,
|
|
189
|
-
status: 404,
|
|
190
|
-
statusText: "Not Found",
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
await expect(getSkillDetail("nonexistent")).rejects.toThrow(
|
|
194
|
-
"Skill not found: nonexistent",
|
|
195
|
-
);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it("URL-encodes the slug", async () => {
|
|
199
|
-
mockFetch.mockResolvedValue({
|
|
200
|
-
ok: true,
|
|
201
|
-
json: () => Promise.resolve({ slug: "my-skill" }),
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
await getSkillDetail("my-skill");
|
|
205
|
-
|
|
206
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
207
|
-
expect.stringContaining("/api/v1/skills/my-skill"),
|
|
208
|
-
expect.anything(),
|
|
209
|
-
);
|
|
210
|
-
});
|
|
211
|
-
});
|
package/src/discover.test.ts
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
3
|
-
|
|
4
|
-
vi.mock("node:fs", () => ({
|
|
5
|
-
existsSync: vi.fn(() => false),
|
|
6
|
-
readdirSync: vi.fn(() => []),
|
|
7
|
-
readFileSync: vi.fn(() => ""),
|
|
8
|
-
}));
|
|
9
|
-
|
|
10
|
-
vi.mock("node:os", () => ({
|
|
11
|
-
homedir: vi.fn(() => "/home/user"),
|
|
12
|
-
}));
|
|
13
|
-
|
|
14
|
-
import { discoverSkills, clearCache } from "./discover.js";
|
|
15
|
-
|
|
16
|
-
const mockExistsSync = vi.mocked(existsSync);
|
|
17
|
-
const mockReaddirSync = vi.mocked(readdirSync);
|
|
18
|
-
const mockReadFileSync = vi.mocked(readFileSync);
|
|
19
|
-
|
|
20
|
-
const validSkillMd = `---
|
|
21
|
-
name: Code Review
|
|
22
|
-
description: Automated code review for quality and best practices
|
|
23
|
-
version: 1.0.0
|
|
24
|
-
---
|
|
25
|
-
|
|
26
|
-
Review the code carefully and suggest improvements.
|
|
27
|
-
`;
|
|
28
|
-
|
|
29
|
-
const anotherSkillMd = `---
|
|
30
|
-
name: Security Scan
|
|
31
|
-
description: Scan code for security vulnerabilities and common exploits
|
|
32
|
-
version: 2.0.0
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
Check for OWASP top 10 vulnerabilities.
|
|
36
|
-
`;
|
|
37
|
-
|
|
38
|
-
function makeDirent(name: string): ReturnType<typeof readdirSync>[0] {
|
|
39
|
-
return {
|
|
40
|
-
name,
|
|
41
|
-
isDirectory: () => true,
|
|
42
|
-
isFile: () => false,
|
|
43
|
-
} as unknown as ReturnType<typeof readdirSync>[0];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
beforeEach(() => {
|
|
47
|
-
vi.clearAllMocks();
|
|
48
|
-
clearCache();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe("discoverSkills", () => {
|
|
52
|
-
it("discovers skills from claude skills directory", () => {
|
|
53
|
-
mockExistsSync.mockImplementation((p) => {
|
|
54
|
-
const s = String(p);
|
|
55
|
-
return s === "/home/user/.claude/skills" || s.endsWith("SKILL.md");
|
|
56
|
-
});
|
|
57
|
-
mockReaddirSync.mockReturnValue([makeDirent("code-review")]);
|
|
58
|
-
mockReadFileSync.mockReturnValue(validSkillMd);
|
|
59
|
-
|
|
60
|
-
const skills = discoverSkills();
|
|
61
|
-
|
|
62
|
-
expect(skills.size).toBe(1);
|
|
63
|
-
expect(skills.has("code-review")).toBe(true);
|
|
64
|
-
expect(skills.get("code-review")!.name).toBe("Code Review");
|
|
65
|
-
expect(skills.get("code-review")!.instructions).toContain(
|
|
66
|
-
"Review the code carefully",
|
|
67
|
-
);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("discovers skills from cursor skills directory", () => {
|
|
71
|
-
mockExistsSync.mockImplementation((p) => {
|
|
72
|
-
const s = String(p);
|
|
73
|
-
return s === "/home/user/.cursor/skills" || s.endsWith("SKILL.md");
|
|
74
|
-
});
|
|
75
|
-
mockReaddirSync.mockReturnValue([makeDirent("security-scan")]);
|
|
76
|
-
mockReadFileSync.mockReturnValue(anotherSkillMd);
|
|
77
|
-
|
|
78
|
-
const skills = discoverSkills();
|
|
79
|
-
|
|
80
|
-
expect(skills.size).toBe(1);
|
|
81
|
-
expect(skills.has("security-scan")).toBe(true);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("scans both directories and deduplicates by slug", () => {
|
|
85
|
-
mockExistsSync.mockReturnValue(true);
|
|
86
|
-
mockReaddirSync.mockImplementation((dir) => {
|
|
87
|
-
const s = String(dir);
|
|
88
|
-
if (s.includes(".claude")) return [makeDirent("code-review")];
|
|
89
|
-
if (s.includes(".cursor"))
|
|
90
|
-
return [makeDirent("code-review"), makeDirent("security-scan")];
|
|
91
|
-
return [];
|
|
92
|
-
});
|
|
93
|
-
mockReadFileSync.mockImplementation((p) => {
|
|
94
|
-
const s = String(p);
|
|
95
|
-
if (s.includes("code-review")) return validSkillMd;
|
|
96
|
-
if (s.includes("security-scan")) return anotherSkillMd;
|
|
97
|
-
return "";
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
const skills = discoverSkills();
|
|
101
|
-
|
|
102
|
-
// code-review from claude wins (first-found), security-scan from cursor
|
|
103
|
-
expect(skills.size).toBe(2);
|
|
104
|
-
expect(skills.has("code-review")).toBe(true);
|
|
105
|
-
expect(skills.has("security-scan")).toBe(true);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("handles missing skills directories", () => {
|
|
109
|
-
mockExistsSync.mockReturnValue(false);
|
|
110
|
-
|
|
111
|
-
const skills = discoverSkills();
|
|
112
|
-
|
|
113
|
-
expect(skills.size).toBe(0);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("skips directories without SKILL.md", () => {
|
|
117
|
-
mockExistsSync.mockImplementation((p) => {
|
|
118
|
-
const s = String(p);
|
|
119
|
-
// Directory exists but SKILL.md does not
|
|
120
|
-
return s === "/home/user/.claude/skills";
|
|
121
|
-
});
|
|
122
|
-
mockReaddirSync.mockReturnValue([makeDirent("orphan-dir")]);
|
|
123
|
-
|
|
124
|
-
const skills = discoverSkills();
|
|
125
|
-
|
|
126
|
-
expect(skills.size).toBe(0);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it("skips malformed SKILL.md files", () => {
|
|
130
|
-
mockExistsSync.mockReturnValue(true);
|
|
131
|
-
mockReaddirSync.mockReturnValue([makeDirent("bad-skill")]);
|
|
132
|
-
mockReadFileSync.mockReturnValue("this is not valid frontmatter");
|
|
133
|
-
|
|
134
|
-
const skills = discoverSkills();
|
|
135
|
-
|
|
136
|
-
expect(skills.size).toBe(0);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it("caches results for subsequent calls", () => {
|
|
140
|
-
mockExistsSync.mockReturnValue(true);
|
|
141
|
-
mockReaddirSync.mockReturnValue([makeDirent("code-review")]);
|
|
142
|
-
mockReadFileSync.mockReturnValue(validSkillMd);
|
|
143
|
-
|
|
144
|
-
discoverSkills();
|
|
145
|
-
discoverSkills();
|
|
146
|
-
|
|
147
|
-
// readdirSync called once per directory on first call, not on second
|
|
148
|
-
expect(mockReaddirSync).toHaveBeenCalledTimes(2); // once for claude, once for cursor
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it("re-scans after cache is cleared", () => {
|
|
152
|
-
mockExistsSync.mockReturnValue(true);
|
|
153
|
-
mockReaddirSync.mockReturnValue([makeDirent("code-review")]);
|
|
154
|
-
mockReadFileSync.mockReturnValue(validSkillMd);
|
|
155
|
-
|
|
156
|
-
discoverSkills();
|
|
157
|
-
clearCache();
|
|
158
|
-
discoverSkills();
|
|
159
|
-
|
|
160
|
-
// 2 dirs × 2 scans = 4 calls
|
|
161
|
-
expect(mockReaddirSync).toHaveBeenCalledTimes(4);
|
|
162
|
-
});
|
|
163
|
-
});
|
package/src/index.test.ts
DELETED
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import type { ParsedSkill } from "@skills-hub-ai/skill-parser";
|
|
3
|
-
|
|
4
|
-
vi.mock("./discover.js", () => ({
|
|
5
|
-
discoverSkills: vi.fn(),
|
|
6
|
-
}));
|
|
7
|
-
|
|
8
|
-
vi.mock("./api.js", () => ({
|
|
9
|
-
searchSkills: vi.fn(),
|
|
10
|
-
getSkillDetail: vi.fn(),
|
|
11
|
-
}));
|
|
12
|
-
|
|
13
|
-
vi.mock("./installer.js", () => ({
|
|
14
|
-
installSkill: vi.fn(),
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
// Mock the MCP SDK — we test the handler logic, not the transport
|
|
18
|
-
vi.mock("@modelcontextprotocol/sdk/server/index.js", () => {
|
|
19
|
-
const handlers = new Map<string, (req: unknown) => Promise<unknown>>();
|
|
20
|
-
return {
|
|
21
|
-
Server: vi.fn().mockImplementation(function () {
|
|
22
|
-
return {
|
|
23
|
-
setRequestHandler: vi.fn(
|
|
24
|
-
function (
|
|
25
|
-
schema: { method: string },
|
|
26
|
-
handler: (req: unknown) => Promise<unknown>,
|
|
27
|
-
) {
|
|
28
|
-
handlers.set(schema.method, handler);
|
|
29
|
-
},
|
|
30
|
-
),
|
|
31
|
-
connect: vi.fn(),
|
|
32
|
-
_handlers: handlers,
|
|
33
|
-
};
|
|
34
|
-
}),
|
|
35
|
-
};
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
vi.mock("@modelcontextprotocol/sdk/server/stdio.js", () => ({
|
|
39
|
-
StdioServerTransport: vi.fn().mockImplementation(function () { return {}; }),
|
|
40
|
-
}));
|
|
41
|
-
|
|
42
|
-
vi.mock("@modelcontextprotocol/sdk/types.js", () => ({
|
|
43
|
-
ListPromptsRequestSchema: { method: "prompts/list" },
|
|
44
|
-
GetPromptRequestSchema: { method: "prompts/get" },
|
|
45
|
-
ListToolsRequestSchema: { method: "tools/list" },
|
|
46
|
-
CallToolRequestSchema: { method: "tools/call" },
|
|
47
|
-
ErrorCode: {
|
|
48
|
-
InvalidRequest: -32600,
|
|
49
|
-
InvalidParams: -32602,
|
|
50
|
-
MethodNotFound: -32601,
|
|
51
|
-
InternalError: -32603,
|
|
52
|
-
},
|
|
53
|
-
McpError: class McpError extends Error {
|
|
54
|
-
code: number;
|
|
55
|
-
constructor(code: number, message: string) {
|
|
56
|
-
super(message);
|
|
57
|
-
this.code = code;
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
}));
|
|
61
|
-
|
|
62
|
-
import { discoverSkills } from "./discover.js";
|
|
63
|
-
import { searchSkills, getSkillDetail } from "./api.js";
|
|
64
|
-
import { installSkill } from "./installer.js";
|
|
65
|
-
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
66
|
-
|
|
67
|
-
const mockDiscoverSkills = vi.mocked(discoverSkills);
|
|
68
|
-
const mockSearchSkills = vi.mocked(searchSkills);
|
|
69
|
-
const mockGetSkillDetail = vi.mocked(getSkillDetail);
|
|
70
|
-
const mockInstallSkill = vi.mocked(installSkill);
|
|
71
|
-
|
|
72
|
-
function makeSkill(
|
|
73
|
-
name: string,
|
|
74
|
-
description: string,
|
|
75
|
-
instructions: string,
|
|
76
|
-
): ParsedSkill {
|
|
77
|
-
return {
|
|
78
|
-
name,
|
|
79
|
-
description,
|
|
80
|
-
version: "1.0.0",
|
|
81
|
-
category: undefined,
|
|
82
|
-
platforms: [],
|
|
83
|
-
permissions: [],
|
|
84
|
-
instructions,
|
|
85
|
-
raw: "",
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
let handlers: Map<string, (req: unknown) => Promise<unknown>>;
|
|
90
|
-
|
|
91
|
-
beforeEach(async () => {
|
|
92
|
-
vi.clearAllMocks();
|
|
93
|
-
|
|
94
|
-
// Re-import to trigger module-level server creation
|
|
95
|
-
vi.resetModules();
|
|
96
|
-
|
|
97
|
-
// Re-mock after resetModules
|
|
98
|
-
vi.doMock("./discover.js", () => ({
|
|
99
|
-
discoverSkills: mockDiscoverSkills,
|
|
100
|
-
}));
|
|
101
|
-
|
|
102
|
-
vi.doMock("./api.js", () => ({
|
|
103
|
-
searchSkills: mockSearchSkills,
|
|
104
|
-
getSkillDetail: mockGetSkillDetail,
|
|
105
|
-
}));
|
|
106
|
-
|
|
107
|
-
vi.doMock("./installer.js", () => ({
|
|
108
|
-
installSkill: mockInstallSkill,
|
|
109
|
-
}));
|
|
110
|
-
|
|
111
|
-
vi.doMock("@modelcontextprotocol/sdk/server/index.js", () => {
|
|
112
|
-
const h = new Map<string, (req: unknown) => Promise<unknown>>();
|
|
113
|
-
handlers = h;
|
|
114
|
-
return {
|
|
115
|
-
Server: vi.fn().mockImplementation(function () {
|
|
116
|
-
return {
|
|
117
|
-
setRequestHandler: vi.fn(
|
|
118
|
-
function (
|
|
119
|
-
schema: { method: string },
|
|
120
|
-
handler: (req: unknown) => Promise<unknown>,
|
|
121
|
-
) {
|
|
122
|
-
h.set(schema.method, handler);
|
|
123
|
-
},
|
|
124
|
-
),
|
|
125
|
-
connect: vi.fn(),
|
|
126
|
-
};
|
|
127
|
-
}),
|
|
128
|
-
};
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
vi.doMock("@modelcontextprotocol/sdk/server/stdio.js", () => ({
|
|
132
|
-
StdioServerTransport: vi.fn().mockImplementation(function () { return {}; }),
|
|
133
|
-
}));
|
|
134
|
-
|
|
135
|
-
vi.doMock("@modelcontextprotocol/sdk/types.js", () => ({
|
|
136
|
-
ListPromptsRequestSchema: { method: "prompts/list" },
|
|
137
|
-
GetPromptRequestSchema: { method: "prompts/get" },
|
|
138
|
-
ListToolsRequestSchema: { method: "tools/list" },
|
|
139
|
-
CallToolRequestSchema: { method: "tools/call" },
|
|
140
|
-
ErrorCode: {
|
|
141
|
-
InvalidRequest: -32600,
|
|
142
|
-
InvalidParams: -32602,
|
|
143
|
-
MethodNotFound: -32601,
|
|
144
|
-
InternalError: -32603,
|
|
145
|
-
},
|
|
146
|
-
McpError: class McpError extends Error {
|
|
147
|
-
code: number;
|
|
148
|
-
constructor(code: number, message: string) {
|
|
149
|
-
super(message);
|
|
150
|
-
this.code = code;
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
}));
|
|
154
|
-
|
|
155
|
-
// Suppress console.error from main()
|
|
156
|
-
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
157
|
-
|
|
158
|
-
await import("./index.js");
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
describe("MCP server", () => {
|
|
162
|
-
it("registers prompts/list and prompts/get handlers", () => {
|
|
163
|
-
expect(handlers.has("prompts/list")).toBe(true);
|
|
164
|
-
expect(handlers.has("prompts/get")).toBe(true);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it("listPrompts returns discovered skills", async () => {
|
|
168
|
-
const skills = new Map<string, ParsedSkill>();
|
|
169
|
-
skills.set(
|
|
170
|
-
"code-review",
|
|
171
|
-
makeSkill("Code Review", "Review code quality", "Review carefully"),
|
|
172
|
-
);
|
|
173
|
-
skills.set(
|
|
174
|
-
"security-scan",
|
|
175
|
-
makeSkill("Security Scan", "Find vulnerabilities", "Check OWASP"),
|
|
176
|
-
);
|
|
177
|
-
mockDiscoverSkills.mockReturnValue(skills);
|
|
178
|
-
|
|
179
|
-
const handler = handlers.get("prompts/list")!;
|
|
180
|
-
const result = (await handler({})) as {
|
|
181
|
-
prompts: Array<{ name: string; description: string }>;
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
expect(result.prompts).toHaveLength(2);
|
|
185
|
-
expect(result.prompts[0].name).toBe("code-review");
|
|
186
|
-
expect(result.prompts[0].description).toBe("Review code quality");
|
|
187
|
-
expect(result.prompts[1].name).toBe("security-scan");
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it("listPrompts returns empty array when no skills installed", async () => {
|
|
191
|
-
mockDiscoverSkills.mockReturnValue(new Map());
|
|
192
|
-
|
|
193
|
-
const handler = handlers.get("prompts/list")!;
|
|
194
|
-
const result = (await handler({})) as { prompts: unknown[] };
|
|
195
|
-
|
|
196
|
-
expect(result.prompts).toEqual([]);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it("getPrompt returns skill instructions", async () => {
|
|
200
|
-
const skills = new Map<string, ParsedSkill>();
|
|
201
|
-
skills.set(
|
|
202
|
-
"code-review",
|
|
203
|
-
makeSkill("Code Review", "Review code quality", "Review carefully"),
|
|
204
|
-
);
|
|
205
|
-
mockDiscoverSkills.mockReturnValue(skills);
|
|
206
|
-
|
|
207
|
-
const handler = handlers.get("prompts/get")!;
|
|
208
|
-
const result = (await handler({
|
|
209
|
-
params: { name: "code-review", arguments: {} },
|
|
210
|
-
})) as {
|
|
211
|
-
description: string;
|
|
212
|
-
messages: Array<{
|
|
213
|
-
role: string;
|
|
214
|
-
content: { type: string; text: string };
|
|
215
|
-
}>;
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
expect(result.description).toBe("Review code quality");
|
|
219
|
-
expect(result.messages).toHaveLength(1);
|
|
220
|
-
expect(result.messages[0].role).toBe("user");
|
|
221
|
-
expect(result.messages[0].content.text).toBe("Review carefully");
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it("getPrompt appends input argument to instructions", async () => {
|
|
225
|
-
const skills = new Map<string, ParsedSkill>();
|
|
226
|
-
skills.set(
|
|
227
|
-
"code-review",
|
|
228
|
-
makeSkill("Code Review", "Review code quality", "Review carefully"),
|
|
229
|
-
);
|
|
230
|
-
mockDiscoverSkills.mockReturnValue(skills);
|
|
231
|
-
|
|
232
|
-
const handler = handlers.get("prompts/get")!;
|
|
233
|
-
const result = (await handler({
|
|
234
|
-
params: {
|
|
235
|
-
name: "code-review",
|
|
236
|
-
arguments: { input: "Focus on error handling" },
|
|
237
|
-
},
|
|
238
|
-
})) as { messages: Array<{ content: { text: string } }> };
|
|
239
|
-
|
|
240
|
-
expect(result.messages[0].content.text).toBe(
|
|
241
|
-
"Review carefully\n\nFocus on error handling",
|
|
242
|
-
);
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
it("getPrompt throws McpError for unknown skill", async () => {
|
|
246
|
-
mockDiscoverSkills.mockReturnValue(new Map());
|
|
247
|
-
|
|
248
|
-
const handler = handlers.get("prompts/get")!;
|
|
249
|
-
|
|
250
|
-
await expect(
|
|
251
|
-
handler({ params: { name: "nonexistent", arguments: {} } }),
|
|
252
|
-
).rejects.toThrow("Unknown skill: nonexistent");
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
it("registers tools/list and tools/call handlers", () => {
|
|
256
|
-
expect(handlers.has("tools/list")).toBe(true);
|
|
257
|
-
expect(handlers.has("tools/call")).toBe(true);
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
it("listTools returns all four tools", async () => {
|
|
261
|
-
const handler = handlers.get("tools/list")!;
|
|
262
|
-
const result = (await handler({})) as { tools: Array<{ name: string }> };
|
|
263
|
-
|
|
264
|
-
const names = result.tools.map((t) => t.name);
|
|
265
|
-
expect(names).toContain("search_skills");
|
|
266
|
-
expect(names).toContain("get_skill_detail");
|
|
267
|
-
expect(names).toContain("install_skill");
|
|
268
|
-
expect(names).toContain("list_installed_skills");
|
|
269
|
-
expect(result.tools).toHaveLength(4);
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
it("search_skills tool calls API and returns results", async () => {
|
|
273
|
-
mockSearchSkills.mockResolvedValue([
|
|
274
|
-
{
|
|
275
|
-
slug: "review-code",
|
|
276
|
-
name: "Review Code",
|
|
277
|
-
description: "AI code review",
|
|
278
|
-
qualityScore: 92,
|
|
279
|
-
installCount: 150,
|
|
280
|
-
avgRating: 4.8,
|
|
281
|
-
latestVersion: "1.0.0",
|
|
282
|
-
category: { name: "Review", slug: "review" },
|
|
283
|
-
isComposition: false,
|
|
284
|
-
tags: ["review"],
|
|
285
|
-
},
|
|
286
|
-
]);
|
|
287
|
-
|
|
288
|
-
const handler = handlers.get("tools/call")!;
|
|
289
|
-
const result = (await handler({
|
|
290
|
-
params: { name: "search_skills", arguments: { query: "code review" } },
|
|
291
|
-
})) as { content: Array<{ text: string }> };
|
|
292
|
-
|
|
293
|
-
expect(mockSearchSkills).toHaveBeenCalledWith(
|
|
294
|
-
"code review",
|
|
295
|
-
undefined,
|
|
296
|
-
10,
|
|
297
|
-
undefined,
|
|
298
|
-
);
|
|
299
|
-
const parsed = JSON.parse(result.content[0].text);
|
|
300
|
-
expect(parsed).toHaveLength(1);
|
|
301
|
-
expect(parsed[0].slug).toBe("review-code");
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
it("search_skills passes organization parameter to searchSkills", async () => {
|
|
305
|
-
mockSearchSkills.mockResolvedValue([]);
|
|
306
|
-
|
|
307
|
-
const handler = handlers.get("tools/call")!;
|
|
308
|
-
await handler({
|
|
309
|
-
params: {
|
|
310
|
-
name: "search_skills",
|
|
311
|
-
arguments: { query: "deploy", organization: "my-org" },
|
|
312
|
-
},
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
expect(mockSearchSkills).toHaveBeenCalledWith(
|
|
316
|
-
"deploy",
|
|
317
|
-
undefined,
|
|
318
|
-
10,
|
|
319
|
-
"my-org",
|
|
320
|
-
);
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
it("search_skills throws when query is missing", async () => {
|
|
324
|
-
const handler = handlers.get("tools/call")!;
|
|
325
|
-
|
|
326
|
-
await expect(
|
|
327
|
-
handler({ params: { name: "search_skills", arguments: {} } }),
|
|
328
|
-
).rejects.toThrow("query is required");
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
it("get_skill_detail tool returns skill info", async () => {
|
|
332
|
-
mockGetSkillDetail.mockResolvedValue({
|
|
333
|
-
slug: "review-code",
|
|
334
|
-
name: "Review Code",
|
|
335
|
-
description: "AI code review",
|
|
336
|
-
instructions: "Review all code changes carefully.",
|
|
337
|
-
qualityScore: 92,
|
|
338
|
-
installCount: 150,
|
|
339
|
-
avgRating: 4.8,
|
|
340
|
-
latestVersion: "1.2.0",
|
|
341
|
-
category: { name: "Review", slug: "review" },
|
|
342
|
-
platforms: ["CLAUDE_CODE"],
|
|
343
|
-
tags: ["review"],
|
|
344
|
-
isComposition: false,
|
|
345
|
-
composition: null,
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
const handler = handlers.get("tools/call")!;
|
|
349
|
-
const result = (await handler({
|
|
350
|
-
params: { name: "get_skill_detail", arguments: { slug: "review-code" } },
|
|
351
|
-
})) as { content: Array<{ text: string }> };
|
|
352
|
-
|
|
353
|
-
expect(mockGetSkillDetail).toHaveBeenCalledWith("review-code");
|
|
354
|
-
const parsed = JSON.parse(result.content[0].text);
|
|
355
|
-
expect(parsed.slug).toBe("review-code");
|
|
356
|
-
expect(parsed.instructionsPreview).toContain("Review all code");
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
it("install_skill tool calls installer and returns result", async () => {
|
|
360
|
-
mockInstallSkill.mockResolvedValue({
|
|
361
|
-
slug: "review-code",
|
|
362
|
-
version: "1.2.0",
|
|
363
|
-
path: "/home/.claude/skills/review-code",
|
|
364
|
-
dependencies: [],
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
const handler = handlers.get("tools/call")!;
|
|
368
|
-
const result = (await handler({
|
|
369
|
-
params: { name: "install_skill", arguments: { slug: "review-code" } },
|
|
370
|
-
})) as { content: Array<{ text: string }> };
|
|
371
|
-
|
|
372
|
-
expect(mockInstallSkill).toHaveBeenCalledWith("review-code", "claude-code");
|
|
373
|
-
const parsed = JSON.parse(result.content[0].text);
|
|
374
|
-
expect(parsed.slug).toBe("review-code");
|
|
375
|
-
expect(parsed.version).toBe("1.2.0");
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
it("list_installed_skills returns discovered skills", async () => {
|
|
379
|
-
const skills = new Map<string, ParsedSkill>();
|
|
380
|
-
skills.set(
|
|
381
|
-
"code-review",
|
|
382
|
-
makeSkill("Code Review", "Review code quality", "Review carefully"),
|
|
383
|
-
);
|
|
384
|
-
mockDiscoverSkills.mockReturnValue(skills);
|
|
385
|
-
|
|
386
|
-
const handler = handlers.get("tools/call")!;
|
|
387
|
-
const result = (await handler({
|
|
388
|
-
params: { name: "list_installed_skills", arguments: {} },
|
|
389
|
-
})) as { content: Array<{ text: string }> };
|
|
390
|
-
|
|
391
|
-
const parsed = JSON.parse(result.content[0].text);
|
|
392
|
-
expect(parsed).toHaveLength(1);
|
|
393
|
-
expect(parsed[0].slug).toBe("code-review");
|
|
394
|
-
expect(parsed[0].name).toBe("Code Review");
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
it("callTool throws for unknown tool", async () => {
|
|
398
|
-
const handler = handlers.get("tools/call")!;
|
|
399
|
-
|
|
400
|
-
await expect(
|
|
401
|
-
handler({ params: { name: "nonexistent_tool", arguments: {} } }),
|
|
402
|
-
).rejects.toThrow("Unknown tool: nonexistent_tool");
|
|
403
|
-
});
|
|
404
|
-
});
|
package/src/installer.test.ts
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { installSkill } from "./installer.js";
|
|
4
|
-
|
|
5
|
-
vi.mock("node:fs", () => ({
|
|
6
|
-
existsSync: vi.fn(() => false),
|
|
7
|
-
mkdirSync: vi.fn(),
|
|
8
|
-
writeFileSync: vi.fn(),
|
|
9
|
-
}));
|
|
10
|
-
|
|
11
|
-
vi.mock("./api.js", () => ({
|
|
12
|
-
getSkillDetail: vi.fn(),
|
|
13
|
-
recordInstall: vi.fn(),
|
|
14
|
-
fetchSkillFileManifest: vi.fn(),
|
|
15
|
-
fetchSkillFile: vi.fn(),
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
import {
|
|
19
|
-
getSkillDetail,
|
|
20
|
-
recordInstall,
|
|
21
|
-
fetchSkillFileManifest,
|
|
22
|
-
fetchSkillFile,
|
|
23
|
-
} from "./api.js";
|
|
24
|
-
|
|
25
|
-
const mockGetSkillDetail = vi.mocked(getSkillDetail);
|
|
26
|
-
const mockRecordInstall = vi.mocked(recordInstall);
|
|
27
|
-
const mockFetchSkillFileManifest = vi.mocked(fetchSkillFileManifest);
|
|
28
|
-
vi.mocked(fetchSkillFile);
|
|
29
|
-
const mockExistsSync = vi.mocked(existsSync);
|
|
30
|
-
const mockMkdirSync = vi.mocked(mkdirSync);
|
|
31
|
-
const mockWriteFileSync = vi.mocked(writeFileSync);
|
|
32
|
-
|
|
33
|
-
const baseSkill = {
|
|
34
|
-
slug: "review-code",
|
|
35
|
-
name: "Review Code",
|
|
36
|
-
description: "AI code review",
|
|
37
|
-
instructions: "Review all code changes carefully.",
|
|
38
|
-
qualityScore: 92,
|
|
39
|
-
installCount: 150,
|
|
40
|
-
avgRating: 4.8,
|
|
41
|
-
latestVersion: "1.2.0",
|
|
42
|
-
category: { name: "Review", slug: "review" },
|
|
43
|
-
platforms: ["CLAUDE_CODE"],
|
|
44
|
-
tags: ["review"],
|
|
45
|
-
isComposition: false,
|
|
46
|
-
composition: null,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
beforeEach(() => {
|
|
50
|
-
vi.clearAllMocks();
|
|
51
|
-
mockExistsSync.mockReturnValue(false);
|
|
52
|
-
// Default: no multi-file manifest, fall back to single SKILL.md path
|
|
53
|
-
mockFetchSkillFileManifest.mockResolvedValue(null);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe("installSkill", () => {
|
|
57
|
-
it("installs a simple skill", async () => {
|
|
58
|
-
mockGetSkillDetail.mockResolvedValue(baseSkill);
|
|
59
|
-
|
|
60
|
-
const result = await installSkill("review-code");
|
|
61
|
-
|
|
62
|
-
expect(mockMkdirSync).toHaveBeenCalledWith(
|
|
63
|
-
expect.stringContaining("review-code"),
|
|
64
|
-
{ recursive: true },
|
|
65
|
-
);
|
|
66
|
-
expect(mockWriteFileSync).toHaveBeenCalledWith(
|
|
67
|
-
expect.stringContaining("SKILL.md"),
|
|
68
|
-
expect.stringContaining("name: Review Code"),
|
|
69
|
-
);
|
|
70
|
-
expect(result.slug).toBe("review-code");
|
|
71
|
-
expect(result.version).toBe("1.2.0");
|
|
72
|
-
expect(result.dependencies).toEqual([]);
|
|
73
|
-
// Records the install so it counts toward installCount + MCP analytics.
|
|
74
|
-
expect(mockRecordInstall).toHaveBeenCalledWith(
|
|
75
|
-
"review-code",
|
|
76
|
-
"claude-code",
|
|
77
|
-
);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("writes SKILL.md and command file", async () => {
|
|
81
|
-
mockGetSkillDetail.mockResolvedValue(baseSkill);
|
|
82
|
-
|
|
83
|
-
await installSkill("review-code");
|
|
84
|
-
|
|
85
|
-
// SKILL.md (with frontmatter fences) + command .md (without fences)
|
|
86
|
-
expect(mockWriteFileSync).toHaveBeenCalledTimes(2);
|
|
87
|
-
|
|
88
|
-
const skillContent = mockWriteFileSync.mock.calls[0][1] as string;
|
|
89
|
-
expect(skillContent).toContain("---");
|
|
90
|
-
expect(skillContent).toContain("name: Review Code");
|
|
91
|
-
expect(skillContent).toContain("Review all code changes carefully.");
|
|
92
|
-
|
|
93
|
-
const commandPath = mockWriteFileSync.mock.calls[1][0] as string;
|
|
94
|
-
const commandContent = mockWriteFileSync.mock.calls[1][1] as string;
|
|
95
|
-
expect(commandPath).toContain("commands/review-code.md");
|
|
96
|
-
expect(commandContent).not.toContain("---");
|
|
97
|
-
expect(commandContent).toContain("name: Review Code");
|
|
98
|
-
expect(commandContent).toContain("Review all code changes carefully.");
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("installs to cursor directory without command file", async () => {
|
|
102
|
-
mockGetSkillDetail.mockResolvedValue(baseSkill);
|
|
103
|
-
|
|
104
|
-
const result = await installSkill("review-code", "cursor");
|
|
105
|
-
|
|
106
|
-
expect(result.path).toContain(".cursor");
|
|
107
|
-
expect(result.path).toContain("skills");
|
|
108
|
-
// Cursor only writes SKILL.md, no command file
|
|
109
|
-
expect(mockWriteFileSync).toHaveBeenCalledTimes(1);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("installs composition dependencies", async () => {
|
|
113
|
-
const parentSkill = {
|
|
114
|
-
...baseSkill,
|
|
115
|
-
slug: "full-review",
|
|
116
|
-
name: "Full Review",
|
|
117
|
-
isComposition: true,
|
|
118
|
-
composition: {
|
|
119
|
-
children: [
|
|
120
|
-
{
|
|
121
|
-
skill: { slug: "lint-check", name: "Lint Check", qualityScore: 85 },
|
|
122
|
-
sortOrder: 0,
|
|
123
|
-
isParallel: false,
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
skill: {
|
|
127
|
-
slug: "test-coverage",
|
|
128
|
-
name: "Test Coverage",
|
|
129
|
-
qualityScore: 80,
|
|
130
|
-
},
|
|
131
|
-
sortOrder: 1,
|
|
132
|
-
isParallel: false,
|
|
133
|
-
},
|
|
134
|
-
],
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const childSkill1 = {
|
|
139
|
-
...baseSkill,
|
|
140
|
-
slug: "lint-check",
|
|
141
|
-
name: "Lint Check",
|
|
142
|
-
instructions: "Run lint",
|
|
143
|
-
};
|
|
144
|
-
const childSkill2 = {
|
|
145
|
-
...baseSkill,
|
|
146
|
-
slug: "test-coverage",
|
|
147
|
-
name: "Test Coverage",
|
|
148
|
-
instructions: "Check coverage",
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
mockGetSkillDetail
|
|
152
|
-
.mockResolvedValueOnce(parentSkill)
|
|
153
|
-
.mockResolvedValueOnce(childSkill1)
|
|
154
|
-
.mockResolvedValueOnce(childSkill2);
|
|
155
|
-
|
|
156
|
-
const result = await installSkill("full-review");
|
|
157
|
-
|
|
158
|
-
expect(result.dependencies).toEqual(["lint-check", "test-coverage"]);
|
|
159
|
-
// Parent + 2 children = 3 SKILL.md + 3 command files = 6 writes
|
|
160
|
-
expect(mockWriteFileSync).toHaveBeenCalledTimes(6);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it("skips already-installed children", async () => {
|
|
164
|
-
const parentSkill = {
|
|
165
|
-
...baseSkill,
|
|
166
|
-
slug: "full-review",
|
|
167
|
-
isComposition: true,
|
|
168
|
-
composition: {
|
|
169
|
-
children: [
|
|
170
|
-
{
|
|
171
|
-
skill: { slug: "lint-check", name: "Lint Check", qualityScore: 85 },
|
|
172
|
-
sortOrder: 0,
|
|
173
|
-
isParallel: false,
|
|
174
|
-
},
|
|
175
|
-
],
|
|
176
|
-
},
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
mockGetSkillDetail.mockResolvedValueOnce(parentSkill);
|
|
180
|
-
|
|
181
|
-
// lint-check already exists
|
|
182
|
-
mockExistsSync.mockReturnValue(true);
|
|
183
|
-
|
|
184
|
-
const result = await installSkill("full-review");
|
|
185
|
-
|
|
186
|
-
// Only parent installed (SKILL.md + command), child skipped
|
|
187
|
-
expect(result.dependencies).toEqual([]);
|
|
188
|
-
expect(mockWriteFileSync).toHaveBeenCalledTimes(2);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it("continues if a child fails", async () => {
|
|
192
|
-
const parentSkill = {
|
|
193
|
-
...baseSkill,
|
|
194
|
-
slug: "full-review",
|
|
195
|
-
isComposition: true,
|
|
196
|
-
composition: {
|
|
197
|
-
children: [
|
|
198
|
-
{
|
|
199
|
-
skill: { slug: "broken-skill", name: "Broken", qualityScore: null },
|
|
200
|
-
sortOrder: 0,
|
|
201
|
-
isParallel: false,
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
skill: { slug: "good-skill", name: "Good", qualityScore: 90 },
|
|
205
|
-
sortOrder: 1,
|
|
206
|
-
isParallel: false,
|
|
207
|
-
},
|
|
208
|
-
],
|
|
209
|
-
},
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
const goodSkill = {
|
|
213
|
-
...baseSkill,
|
|
214
|
-
slug: "good-skill",
|
|
215
|
-
name: "Good",
|
|
216
|
-
instructions: "Do good",
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
mockGetSkillDetail
|
|
220
|
-
.mockResolvedValueOnce(parentSkill)
|
|
221
|
-
.mockRejectedValueOnce(new Error("Not found"))
|
|
222
|
-
.mockResolvedValueOnce(goodSkill);
|
|
223
|
-
|
|
224
|
-
const result = await installSkill("full-review");
|
|
225
|
-
|
|
226
|
-
// broken-skill failed but good-skill still installed
|
|
227
|
-
expect(result.dependencies).toEqual(["good-skill"]);
|
|
228
|
-
});
|
|
229
|
-
});
|