Files
skillshare/tests/integration/gitignore_project_test.go
Willie f95a113fce test: migrate all test metadata to centralized store format
Replace .skillshare-meta.json sidecar writes with centralized
.metadata.json store writes across all test files. Use
install.MetadataFileName constant instead of hardcoded strings.

Updated: audit_test, doctor_test, gitignore_project_test,
install_online_test, list_project_test, sync_symlinked_dir_test,
uninstall_project_test, uninstall_test, uninstall_trash_test,
audit_output_online_test, audit_scan_skill_test, analyzer_metadata_test
2026-04-08 17:43:46 +08:00

90 lines
2.9 KiB
Go

//go:build !online
package integration
import (
"os"
"path/filepath"
"strings"
"testing"
"skillshare/internal/install"
"skillshare/internal/testutil"
)
func TestGitignoreProject_InstallAddsEntry(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
projectRoot := sb.SetupProjectDir("claude")
sourceSkill := filepath.Join(sb.Root, "ext")
os.MkdirAll(sourceSkill, 0755)
os.WriteFile(filepath.Join(sourceSkill, "SKILL.md"), []byte("---\nname: ext\n---\n# E"), 0644)
sb.RunCLIInDir(projectRoot, "install", sourceSkill, "-p").AssertSuccess(t)
gitignore := sb.ReadFile(filepath.Join(projectRoot, ".skillshare", ".gitignore"))
if !strings.Contains(gitignore, "skills/ext/") {
t.Errorf("gitignore should contain skills/ext/, got:\n%s", gitignore)
}
if !strings.Contains(gitignore, "BEGIN SKILLSHARE MANAGED") {
t.Error("gitignore should contain marker block")
}
}
func TestGitignoreProject_UninstallRemovesEntry(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
projectRoot := sb.SetupProjectDir("claude")
// Create remote skill with meta in centralized store
sb.CreateProjectSkill(projectRoot, "removable", map[string]string{
"SKILL.md": "# Removable",
})
skillsDir := filepath.Join(projectRoot, ".skillshare", "skills")
metaStore := `{"version":1,"entries":{"removable":{"source":"org/removable","type":"github"}}}`
os.WriteFile(filepath.Join(skillsDir, install.MetadataFileName), []byte(metaStore), 0644)
// Write gitignore with the entry
sb.WriteFile(filepath.Join(projectRoot, ".skillshare", ".gitignore"),
"# BEGIN SKILLSHARE MANAGED - DO NOT EDIT\nskills/removable/\n# END SKILLSHARE MANAGED\n")
sb.WriteProjectConfig(projectRoot, `targets:
- claude
skills:
- name: removable
source: org/removable
`)
sb.RunCLIInDir(projectRoot, "uninstall", "removable", "--force", "-p").AssertSuccess(t)
gitignore := sb.ReadFile(filepath.Join(projectRoot, ".skillshare", ".gitignore"))
if strings.Contains(gitignore, "skills/removable/") {
t.Errorf("gitignore should not contain removed entry, got:\n%s", gitignore)
}
}
func TestGitignoreProject_PreservesUserEntries(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
projectRoot := sb.SetupProjectDir("claude")
// Write gitignore with user entries
sb.WriteFile(filepath.Join(projectRoot, ".skillshare", ".gitignore"),
"# my custom rule\n*.tmp\n")
sourceSkill := filepath.Join(sb.Root, "ext2")
os.MkdirAll(sourceSkill, 0755)
os.WriteFile(filepath.Join(sourceSkill, "SKILL.md"), []byte("---\nname: ext2\n---\n# E"), 0644)
sb.RunCLIInDir(projectRoot, "install", sourceSkill, "-p").AssertSuccess(t)
gitignore := sb.ReadFile(filepath.Join(projectRoot, ".skillshare", ".gitignore"))
if !strings.Contains(gitignore, "*.tmp") {
t.Error("user entries should be preserved")
}
if !strings.Contains(gitignore, "skills/ext2/") {
t.Error("new entry should be added")
}
}