MCPcopy
hub / github.com/cli/cli / TestInstallSkill

Function TestInstallSkill

internal/skills/installer/installer_test.go:185–314  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

183}
184
185func TestInstallSkill(t *testing.T) {
186 tests := []struct {
187 name string
188 skill discovery.Skill
189 stubs func(*httpmock.Registry)
190 verify func(t *testing.T, destDir string)
191 }{
192 {
193 name: "installs files from remote",
194 skill: discovery.Skill{Name: "code-review", Path: "skills/code-review", TreeSHA: "tree123"},
195 stubs: func(reg *httpmock.Registry) {
196 reg.Register(
197 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/trees/tree123"),
198 httpmock.JSONResponse(map[string]interface{}{
199 "sha": "tree123", "truncated": false,
200 "tree": []map[string]interface{}{
201 {"path": "SKILL.md", "type": "blob", "sha": "skill-sha", "size": 10},
202 {"path": "prompt.txt", "type": "blob", "sha": "prompt-sha", "size": 5},
203 },
204 }))
205 reg.Register(
206 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/blobs/skill-sha"),
207 httpmock.JSONResponse(map[string]interface{}{
208 "sha": "skill-sha", "encoding": "base64",
209 "content": base64.StdEncoding.EncodeToString([]byte("# Code Review")),
210 }))
211 reg.Register(
212 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/blobs/prompt-sha"),
213 httpmock.JSONResponse(map[string]interface{}{
214 "sha": "prompt-sha", "encoding": "base64",
215 "content": base64.StdEncoding.EncodeToString([]byte("review this PR")),
216 }))
217 },
218 verify: func(t *testing.T, destDir string) {
219 t.Helper()
220 content, err := os.ReadFile(filepath.Join(destDir, "code-review", "prompt.txt"))
221 require.NoError(t, err)
222 assert.Equal(t, "review this PR", string(content))
223
224 _, err = os.Stat(filepath.Join(destDir, "code-review", "SKILL.md"))
225 assert.NoError(t, err)
226 },
227 },
228 {
229 name: "injects metadata into SKILL.md",
230 skill: discovery.Skill{Name: "pr-summary", Path: "skills/pr-summary", TreeSHA: "tree456"},
231 stubs: func(reg *httpmock.Registry) {
232 reg.Register(
233 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/trees/tree456"),
234 httpmock.JSONResponse(map[string]interface{}{
235 "sha": "tree456", "truncated": false,
236 "tree": []map[string]interface{}{
237 {"path": "SKILL.md", "type": "blob", "sha": "md-sha", "size": 20},
238 },
239 }))
240 reg.Register(
241 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/blobs/md-sha"),
242 httpmock.JSONResponse(map[string]interface{}{

Callers

nothing calls this directly

Calls 13

RegisterMethod · 0.95
VerifyMethod · 0.95
RESTFunction · 0.92
JSONResponseFunction · 0.92
NewClientFromHTTPFunction · 0.92
installSkillFunction · 0.85
JoinMethod · 0.80
EqualMethod · 0.80
ContainsMethod · 0.80
verifyMethod · 0.80
HelperMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected