(t *testing.T)
| 1594 | } |
| 1595 | |
| 1596 | func TestDiscoverSkillFiles(t *testing.T) { |
| 1597 | tests := []struct { |
| 1598 | name string |
| 1599 | stubs func(*httpmock.Registry) |
| 1600 | wantPaths []string |
| 1601 | wantErr string |
| 1602 | }{ |
| 1603 | { |
| 1604 | name: "returns files with skill path prefix", |
| 1605 | stubs: func(reg *httpmock.Registry) { |
| 1606 | reg.Register( |
| 1607 | httpmock.REST("GET", "repos/monalisa/octocat-skills/git/trees/tree123"), |
| 1608 | httpmock.JSONResponse(map[string]interface{}{ |
| 1609 | "sha": "tree123", "truncated": false, |
| 1610 | "tree": []map[string]interface{}{ |
| 1611 | {"path": "SKILL.md", "type": "blob", "sha": "sha1", "size": 10}, |
| 1612 | {"path": "scripts/setup.sh", "type": "blob", "sha": "sha2", "size": 50}, |
| 1613 | {"path": "scripts", "type": "tree", "sha": "treesub"}, |
| 1614 | }, |
| 1615 | })) |
| 1616 | }, |
| 1617 | wantPaths: []string{"skills/code-review/SKILL.md", "skills/code-review/scripts/setup.sh"}, |
| 1618 | }, |
| 1619 | { |
| 1620 | name: "truncated tree falls back to walkTree", |
| 1621 | stubs: func(reg *httpmock.Registry) { |
| 1622 | reg.Register( |
| 1623 | httpmock.REST("GET", "repos/monalisa/octocat-skills/git/trees/tree123"), |
| 1624 | httpmock.JSONResponse(map[string]interface{}{ |
| 1625 | "sha": "tree123", "truncated": true, "tree": []map[string]interface{}{}, |
| 1626 | })) |
| 1627 | reg.Register( |
| 1628 | httpmock.REST("GET", "repos/monalisa/octocat-skills/git/trees/tree123"), |
| 1629 | httpmock.JSONResponse(map[string]interface{}{ |
| 1630 | "sha": "tree123", |
| 1631 | "tree": []map[string]interface{}{ |
| 1632 | {"path": "SKILL.md", "type": "blob", "sha": "sha1", "size": 10}, |
| 1633 | }, |
| 1634 | })) |
| 1635 | }, |
| 1636 | wantPaths: []string{"skills/code-review/SKILL.md"}, |
| 1637 | }, |
| 1638 | { |
| 1639 | name: "API error", |
| 1640 | stubs: func(reg *httpmock.Registry) { |
| 1641 | reg.Register( |
| 1642 | httpmock.REST("GET", "repos/monalisa/octocat-skills/git/trees/tree123"), |
| 1643 | httpmock.StatusStringResponse(500, "server error")) |
| 1644 | }, |
| 1645 | wantErr: "could not fetch skill tree", |
| 1646 | }, |
| 1647 | } |
| 1648 | for _, tt := range tests { |
| 1649 | t.Run(tt.name, func(t *testing.T) { |
| 1650 | reg := &httpmock.Registry{} |
| 1651 | defer reg.Verify(t) |
| 1652 | tt.stubs(reg) |
| 1653 | client := api.NewClientFromHTTP(&http.Client{Transport: reg}) |
nothing calls this directly
no test coverage detected