CLI (add, remove, list, outdated, update, import) over a skills.json manifest and a skills.lock.json pinned with nix flake prefetch, plus a home-manager module that links each locked skill via builtins.fetchTree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package skills
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func write(t *testing.T, root, rel, content string) {
|
|
t.Helper()
|
|
path := filepath.Join(root, rel)
|
|
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestDiscover(t *testing.T) {
|
|
root := t.TempDir()
|
|
write(t, root, "skills/tdd/SKILL.md", "# no frontmatter\n")
|
|
write(t, root, "skills/grill/SKILL.md", "---\nname: \"grilling\"\ndescription: x\n---\n")
|
|
// Skills don't nest: this one belongs to tdd.
|
|
write(t, root, "skills/tdd/examples/inner/SKILL.md", "")
|
|
write(t, root, ".git/hooks/SKILL.md", "")
|
|
write(t, root, "README.md", "")
|
|
|
|
got, err := Discover(root)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := []Skill{{Name: "grilling", Path: "skills/grill"}, {Name: "tdd", Path: "skills/tdd"}}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Errorf("got %v, want %v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestDiscoverRootSkill(t *testing.T) {
|
|
root := t.TempDir()
|
|
write(t, root, "SKILL.md", "---\nname: ponytail\n---\n")
|
|
got, err := Discover(root)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if want := []Skill{{Name: "ponytail", Path: "."}}; !reflect.DeepEqual(got, want) {
|
|
t.Errorf("got %v, want %v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestDiscoverDuplicateNames(t *testing.T) {
|
|
root := t.TempDir()
|
|
write(t, root, "a/tdd/SKILL.md", "")
|
|
write(t, root, "b/tdd/SKILL.md", "")
|
|
got, err := Discover(root)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if want := []Skill{{Name: "tdd", Path: "a/tdd"}, {Name: "tdd", Path: "b/tdd"}}; !reflect.DeepEqual(got, want) {
|
|
t.Errorf("got %v, want %v", got, want)
|
|
}
|
|
}
|