Files
skm/internal/manifest/manifest_test.go
T
johannesandClaude Sonnet 5.5 df8d11d8cb feat: pin agent definitions next to skills
A source can install agents (agents/<name>.md files with a frontmatter
name) alongside or instead of skills.

- manifest: optional "agents" selection; lock: "agents" map
- add --agent / --all-agents, remove --agent, list shows the kind
- check/update diff agents like skills (files, not directories)
- dashboard lists and removes agents
- home-manager module: agentTargets (default .claude/agents) links <name>.md

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-28 13:42:45 +01:00

74 lines
2.0 KiB
Go

package manifest
import (
"encoding/json"
"reflect"
"testing"
)
func TestSelectionJSON(t *testing.T) {
cases := []struct {
json string
sel Selection
}{
{`"*"`, Selection{All: true}},
{`[]`, Selection{}},
{`["tdd",{"name":"grilling","as":"grilling-mp"}]`, Selection{Items: []Skill{
{Name: "tdd"},
{Name: "grilling", As: "grilling-mp"},
}}},
}
for _, c := range cases {
var got Selection
if err := json.Unmarshal([]byte(c.json), &got); err != nil {
t.Fatalf("unmarshal %s: %v", c.json, err)
}
if c.sel.Items == nil && got.Items != nil && len(got.Items) == 0 {
got.Items = nil
}
if !reflect.DeepEqual(got, c.sel) {
t.Errorf("unmarshal %s = %+v, want %+v", c.json, got, c.sel)
}
out, err := json.Marshal(c.sel)
if err != nil {
t.Fatal(err)
}
if string(out) != c.json {
t.Errorf("marshal %+v = %s, want %s", c.sel, out, c.json)
}
}
}
func TestSourceAgentsOmittedWhenEmpty(t *testing.T) {
// A manifest without agents must stay byte-identical when skm rewrites it.
skillsOnly := `{"url":"github:mp/skills","skills":["tdd"]}`
var src Source
if err := json.Unmarshal([]byte(skillsOnly), &src); err != nil {
t.Fatal(err)
}
out, err := json.Marshal(src)
if err != nil || string(out) != skillsOnly {
t.Errorf("marshal = %s, err %v; want %s", out, err, skillsOnly)
}
withAgents := `{"url":"github:cursor/plugins","skills":[],"agents":["comment-sicko",{"name":"poteto","as":"p"}]}`
if err := json.Unmarshal([]byte(withAgents), &src); err != nil {
t.Fatal(err)
}
if got := src.Agents.Items; len(got) != 2 || got[0].Name != "comment-sicko" || got[1].Installed() != "p" {
t.Errorf("agents = %+v", got)
}
src.Skills = Selection{}
out, err = json.Marshal(src)
if err != nil || string(out) != withAgents {
t.Errorf("marshal = %s, err %v; want %s", out, err, withAgents)
}
}
func TestSelectionRejectsOtherStrings(t *testing.T) {
var s Selection
if err := json.Unmarshal([]byte(`"tdd"`), &s); err == nil {
t.Error("want error for a bare skill name")
}
}