mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
The --into flag information was previously encoded only in the name field (e.g. name: frontend/pdf), causing config-based install to fail because validate.SkillName() rejects slashes. Add an explicit group field to separate placement from identity, with automatic migration of legacy slash-in-name entries. - Add Group field, FullName(), and EffectiveParts() to SkillEntry - Update reconcilers to write new format and migrate legacy entries - Fix installFromGlobalConfig/installFromProjectConfig to use EffectiveParts() for validation and FullName() for path construction - Fix uninstall config cleanup to match via FullName() - Add unit tests for SkillEntry helpers and reconciler group behavior - Add 5 integration tests for group field end-to-end flows - Document group field in declarative-manifest.md
162 lines
5.2 KiB
Go
162 lines
5.2 KiB
Go
//go:build !online
|
|
|
|
package integration
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"skillshare/internal/testutil"
|
|
)
|
|
|
|
func TestInstall_Into_RecordsGroupField(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
|
targets: {}
|
|
`)
|
|
|
|
// Create a local skill
|
|
localSkill := filepath.Join(sb.Root, "pdf-skill")
|
|
os.MkdirAll(localSkill, 0755)
|
|
os.WriteFile(filepath.Join(localSkill, "SKILL.md"), []byte("# PDF Skill"), 0644)
|
|
|
|
// Install with --into frontend
|
|
result := sb.RunCLI("install", localSkill, "--into", "frontend")
|
|
result.AssertSuccess(t)
|
|
|
|
// Verify skill was installed into subdirectory
|
|
if !sb.FileExists(filepath.Join(sb.SourcePath, "frontend", "pdf-skill", "SKILL.md")) {
|
|
t.Error("skill should be installed to source/frontend/pdf-skill/")
|
|
}
|
|
|
|
// Read config and verify group field
|
|
configContent := sb.ReadFile(sb.ConfigPath)
|
|
if !strings.Contains(configContent, "group: frontend") {
|
|
t.Errorf("config should contain 'group: frontend', got:\n%s", configContent)
|
|
}
|
|
// Name should be the bare name, not "frontend/pdf-skill"
|
|
if strings.Contains(configContent, "name: frontend/pdf-skill") {
|
|
t.Errorf("config should NOT contain legacy slash name 'frontend/pdf-skill', got:\n%s", configContent)
|
|
}
|
|
if !strings.Contains(configContent, "name: pdf-skill") {
|
|
t.Errorf("config should contain bare 'name: pdf-skill', got:\n%s", configContent)
|
|
}
|
|
}
|
|
|
|
func TestInstall_Into_MultiLevel_RecordsGroupField(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
|
targets: {}
|
|
`)
|
|
|
|
localSkill := filepath.Join(sb.Root, "ui-skill")
|
|
os.MkdirAll(localSkill, 0755)
|
|
os.WriteFile(filepath.Join(localSkill, "SKILL.md"), []byte("# UI Skill"), 0644)
|
|
|
|
// Install with multi-level --into
|
|
result := sb.RunCLI("install", localSkill, "--into", "frontend/vue")
|
|
result.AssertSuccess(t)
|
|
|
|
// Read config and verify group field
|
|
configContent := sb.ReadFile(sb.ConfigPath)
|
|
if !strings.Contains(configContent, "group: frontend/vue") {
|
|
t.Errorf("config should contain 'group: frontend/vue', got:\n%s", configContent)
|
|
}
|
|
if !strings.Contains(configContent, "name: ui-skill") {
|
|
t.Errorf("config should contain bare 'name: ui-skill', got:\n%s", configContent)
|
|
}
|
|
}
|
|
|
|
func TestInstall_ConfigBased_WithGroup(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
// Create a local skill to use as source
|
|
sourceSkill := filepath.Join(sb.Root, "source-pdf")
|
|
os.MkdirAll(sourceSkill, 0755)
|
|
os.WriteFile(filepath.Join(sourceSkill, "SKILL.md"), []byte("# PDF Skill"), 0644)
|
|
|
|
// First install normally with --into to populate config
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
|
targets: {}
|
|
`)
|
|
result := sb.RunCLI("install", sourceSkill, "--into", "frontend")
|
|
result.AssertSuccess(t)
|
|
|
|
// Verify skill exists
|
|
skillPath := filepath.Join(sb.SourcePath, "frontend", "source-pdf", "SKILL.md")
|
|
if !sb.FileExists(skillPath) {
|
|
t.Fatal("skill should exist after initial install")
|
|
}
|
|
|
|
// Remove the installed skill (simulate fresh machine)
|
|
os.RemoveAll(filepath.Join(sb.SourcePath, "frontend"))
|
|
|
|
// Now run config-based install — this is the bug fix test
|
|
result = sb.RunCLI("install")
|
|
result.AssertSuccess(t)
|
|
|
|
// Verify skill was recreated in the correct group directory
|
|
if !sb.FileExists(skillPath) {
|
|
t.Error("config-based install should recreate skill at frontend/source-pdf/")
|
|
}
|
|
}
|
|
|
|
func TestInstall_LegacySlashName_BackwardCompat(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
// Write config with legacy format (name contains slash, no group field)
|
|
// This is the format that existed before the group field was added
|
|
sourceSkill := filepath.Join(sb.Root, "source-pdf")
|
|
os.MkdirAll(sourceSkill, 0755)
|
|
os.WriteFile(filepath.Join(sourceSkill, "SKILL.md"), []byte("# PDF"), 0644)
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
|
targets: {}
|
|
skills:
|
|
- name: frontend/pdf
|
|
source: ` + sourceSkill + `
|
|
`)
|
|
|
|
// Config-based install with legacy slash name should still work
|
|
result := sb.RunCLI("install")
|
|
result.AssertSuccess(t)
|
|
|
|
// Verify skill was installed correctly
|
|
if !sb.FileExists(filepath.Join(sb.SourcePath, "frontend", "pdf", "SKILL.md")) {
|
|
t.Error("legacy slash-name install should place skill at frontend/pdf/")
|
|
}
|
|
}
|
|
|
|
func TestInstallProject_Into_RecordsGroupField(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
projectRoot := sb.SetupProjectDir("claude")
|
|
|
|
// Create a source skill
|
|
sourceSkill := filepath.Join(sb.Root, "my-skill")
|
|
os.MkdirAll(sourceSkill, 0755)
|
|
os.WriteFile(filepath.Join(sourceSkill, "SKILL.md"), []byte("---\nname: my-skill\n---\n# My Skill"), 0644)
|
|
|
|
// Install with --into in project mode
|
|
result := sb.RunCLIInDir(projectRoot, "install", sourceSkill, "--into", "tools", "-p")
|
|
result.AssertSuccess(t)
|
|
|
|
// Read project config and verify group field
|
|
configPath := filepath.Join(projectRoot, ".skillshare", "config.yaml")
|
|
configContent := sb.ReadFile(configPath)
|
|
if !strings.Contains(configContent, "group: tools") {
|
|
t.Errorf("project config should contain 'group: tools', got:\n%s", configContent)
|
|
}
|
|
if !strings.Contains(configContent, "name: my-skill") {
|
|
t.Errorf("project config should contain bare 'name: my-skill', got:\n%s", configContent)
|
|
}
|
|
}
|