MCPcopy
hub / github.com/cli/cli / TestListSkillFiles

Function TestListSkillFiles

internal/skills/discovery/discovery_test.go:1671–1754  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1669}
1670
1671func TestListSkillFiles(t *testing.T) {
1672 tests := []struct {
1673 name string
1674 stubs func(*httpmock.Registry)
1675 wantPaths []string
1676 wantErr string
1677 }{
1678 {
1679 name: "returns relative paths",
1680 stubs: func(reg *httpmock.Registry) {
1681 reg.Register(
1682 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/trees/tree123"),
1683 httpmock.JSONResponse(map[string]interface{}{
1684 "sha": "tree123", "truncated": false,
1685 "tree": []map[string]interface{}{
1686 {"path": "SKILL.md", "type": "blob", "sha": "sha1", "size": 10},
1687 {"path": "prompt.txt", "type": "blob", "sha": "sha2", "size": 20},
1688 },
1689 }))
1690 },
1691 wantPaths: []string{"SKILL.md", "prompt.txt"},
1692 },
1693 {
1694 name: "truncated tree falls back to walkTree with nested subtree",
1695 stubs: func(reg *httpmock.Registry) {
1696 reg.Register(
1697 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/trees/tree123"),
1698 httpmock.JSONResponse(map[string]interface{}{
1699 "sha": "tree123", "truncated": true, "tree": []map[string]interface{}{},
1700 }))
1701 // walkTree fetches the top-level tree non-recursively
1702 reg.Register(
1703 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/trees/tree123"),
1704 httpmock.JSONResponse(map[string]interface{}{
1705 "sha": "tree123",
1706 "tree": []map[string]interface{}{
1707 {"path": "SKILL.md", "type": "blob", "sha": "sha1", "size": 10},
1708 {"path": "scripts", "type": "tree", "sha": "subtree1"},
1709 },
1710 }))
1711 // walkTree recurses into the "scripts" subtree
1712 reg.Register(
1713 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/trees/subtree1"),
1714 httpmock.JSONResponse(map[string]interface{}{
1715 "sha": "subtree1",
1716 "tree": []map[string]interface{}{
1717 {"path": "setup.sh", "type": "blob", "sha": "sha2", "size": 50},
1718 },
1719 }))
1720 },
1721 wantPaths: []string{"SKILL.md", "scripts/setup.sh"},
1722 },
1723 {
1724 name: "API error",
1725 stubs: func(reg *httpmock.Registry) {
1726 reg.Register(
1727 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/trees/tree123"),
1728 httpmock.StatusStringResponse(500, "server error"))

Callers

nothing calls this directly

Calls 11

RegisterMethod · 0.95
VerifyMethod · 0.95
RESTFunction · 0.92
JSONResponseFunction · 0.92
StatusStringResponseFunction · 0.92
NewClientFromHTTPFunction · 0.92
ListSkillFilesFunction · 0.85
ContainsMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected