Validate and import agent skills into versioned server storage
Adds a SKILL.md bundle validator, immutable per-skill versions with content digests and deduplication, protocol requests to import, list and show skills, and the pipelines skills import/list/show commands. Imports are serialised so concurrent imports never share a version number.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package skills
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidateDigestStable(t *testing.T) {
|
||||
for _, order := range [][]string{{"b.txt", "a.txt"}, {"a.txt", "b.txt"}} {
|
||||
d := t.TempDir()
|
||||
os.WriteFile(filepath.Join(d, "SKILL.md"), []byte("---\nname: demo-skill\ndescription: Demo\n---\n"), 0600)
|
||||
os.Mkdir(filepath.Join(d, "references"), 0700)
|
||||
for _, n := range order {
|
||||
os.WriteFile(filepath.Join(d, "references", n), []byte(n), 0600)
|
||||
}
|
||||
b, e := Validate(d)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if order[0] == "b.txt" {
|
||||
t.Setenv("DIGEST", b.Digest)
|
||||
} else if os.Getenv("DIGEST") != b.Digest {
|
||||
t.Fatalf("digest changed")
|
||||
}
|
||||
}
|
||||
}
|
||||
func TestValidateRejectsNested(t *testing.T) {
|
||||
d := t.TempDir()
|
||||
os.WriteFile(filepath.Join(d, "SKILL.md"), []byte("---\nname: x\ndescription: y\n---"), 0600)
|
||||
os.Mkdir(filepath.Join(d, "references"), 0700)
|
||||
os.WriteFile(filepath.Join(d, "references", "SKILL.md"), []byte("x"), 0600)
|
||||
if _, e := Validate(d); e == nil {
|
||||
t.Fatal("expected nested rejection")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateNameRejectsTraversal(t *testing.T) {
|
||||
for _, name := range []string{"../outside", "../../outside", "Upper", "has space", ""} {
|
||||
if err := ValidateName(name); err == nil {
|
||||
t.Errorf("ValidateName(%q) accepted unsafe name", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateRejectsSymlinkRoot(t *testing.T) {
|
||||
target := t.TempDir()
|
||||
os.WriteFile(filepath.Join(target, "SKILL.md"), []byte("---\nname: demo\ndescription: Demo\n---\n"), 0600)
|
||||
link := filepath.Join(t.TempDir(), "skill-link")
|
||||
if err := os.Symlink(target, link); err != nil {
|
||||
t.Skipf("symlinks unavailable: %v", err)
|
||||
}
|
||||
if _, err := Validate(link); err == nil {
|
||||
t.Fatal("expected symlink root rejection")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user