Files
skillshare/internal/utils/frontmatter_list_test.go
T
Willie a29e198725 feat: add target filter CLI, skill-level targets field, and Web UI support
- CLI: `target <name> --add-include/--add-exclude/--remove-include/--remove-exclude`
- SKILL.md `targets` frontmatter restricts sync to specified targets
- Cross-mode matching (e.g. "claude" matches "claude-code" project target)
- Web UI: inline filter editor on Targets page, target badges on Skills pages
- API: PATCH /api/targets/{name} for filter updates
- Fix drift detection in doctor/status/handler to account for skill-level targets
- `check` warns about unknown target names in skill-level targets field
- Docs: update skill-format, target command, configuration, creating-skills
2026-02-15 23:29:30 +08:00

70 lines
1.9 KiB
Go

package utils
import (
"os"
"path/filepath"
"testing"
)
func TestParseFrontmatterList_InlineFormat(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "SKILL.md")
os.WriteFile(path, []byte("---\nname: my-skill\ntargets: [claude, cursor]\n---\n# Content"), 0644)
result := ParseFrontmatterList(path, "targets")
if len(result) != 2 || result[0] != "claude" || result[1] != "cursor" {
t.Errorf("got %v, want [claude cursor]", result)
}
}
func TestParseFrontmatterList_BlockFormat(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "SKILL.md")
os.WriteFile(path, []byte("---\nname: my-skill\ntargets:\n - claude\n - cursor\n---\n# Content"), 0644)
result := ParseFrontmatterList(path, "targets")
if len(result) != 2 || result[0] != "claude" || result[1] != "cursor" {
t.Errorf("got %v, want [claude cursor]", result)
}
}
func TestParseFrontmatterList_FieldAbsent(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "SKILL.md")
os.WriteFile(path, []byte("---\nname: my-skill\n---\n# Content"), 0644)
result := ParseFrontmatterList(path, "targets")
if result != nil {
t.Errorf("got %v, want nil", result)
}
}
func TestParseFrontmatterList_EmptyList(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "SKILL.md")
os.WriteFile(path, []byte("---\nname: my-skill\ntargets: []\n---\n# Content"), 0644)
result := ParseFrontmatterList(path, "targets")
if result != nil {
t.Errorf("got %v, want nil", result)
}
}
func TestParseFrontmatterList_FileNotFound(t *testing.T) {
result := ParseFrontmatterList("/nonexistent/SKILL.md", "targets")
if result != nil {
t.Errorf("got %v, want nil", result)
}
}
func TestParseFrontmatterList_NoFrontmatter(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "SKILL.md")
os.WriteFile(path, []byte("# Just content, no frontmatter"), 0644)
result := ParseFrontmatterList(path, "targets")
if result != nil {
t.Errorf("got %v, want nil", result)
}
}