Files
skillshare/tests/integration/pull_test.go
T
Willie f55e056fa4 feat: add comprehensive sandbox integration tests
Add complete integration test coverage for all CLI commands with
isolated sandbox environments that run on every change.

Changes:
- Add testutil package for sandbox test infrastructure
- Add 77 integration tests covering all commands (init, sync, status,
  diff, backup, restore, pull, doctor, target, version, help)
- Update CI workflow to run integration tests on Ubuntu and macOS
- Add SKILLSHARE_CONFIG env var support for test isolation
- Add mise.toml for task management
- Move scripts to scripts/ directory
2026-01-14 22:35:33 +08:00

211 lines
5.5 KiB
Go

package integration
import (
"os"
"path/filepath"
"testing"
"skillshare/internal/testutil"
)
func TestPull_FindsLocalSkills(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
targetPath := sb.CreateTarget("claude")
// Create local skill in target (not a symlink)
localSkillPath := filepath.Join(targetPath, "local-skill")
os.MkdirAll(localSkillPath, 0755)
os.WriteFile(filepath.Join(localSkillPath, "SKILL.md"), []byte("# Local Skill"), 0644)
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets:
claude:
path: ` + targetPath + `
`)
// Run with --dry-run to just see what would be pulled
result := sb.RunCLI("pull", "--dry-run")
result.AssertSuccess(t)
result.AssertOutputContains(t, "local-skill")
}
func TestPull_SpecificTarget_OnlyThat(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
claudePath := sb.CreateTarget("claude")
codexPath := sb.CreateTarget("codex")
// Create local skills in both targets
os.MkdirAll(filepath.Join(claudePath, "claude-skill"), 0755)
os.WriteFile(filepath.Join(claudePath, "claude-skill", "SKILL.md"), []byte("# Claude"), 0644)
os.MkdirAll(filepath.Join(codexPath, "codex-skill"), 0755)
os.WriteFile(filepath.Join(codexPath, "codex-skill", "SKILL.md"), []byte("# Codex"), 0644)
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets:
claude:
path: ` + claudePath + `
codex:
path: ` + codexPath + `
`)
result := sb.RunCLI("pull", "claude", "--dry-run")
result.AssertSuccess(t)
result.AssertOutputContains(t, "claude-skill")
result.AssertOutputNotContains(t, "codex-skill")
}
func TestPull_All_FromAllTargets(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
claudePath := sb.CreateTarget("claude")
codexPath := sb.CreateTarget("codex")
// Create local skills in both targets
os.MkdirAll(filepath.Join(claudePath, "claude-skill"), 0755)
os.WriteFile(filepath.Join(claudePath, "claude-skill", "SKILL.md"), []byte("# Claude"), 0644)
os.MkdirAll(filepath.Join(codexPath, "codex-skill"), 0755)
os.WriteFile(filepath.Join(codexPath, "codex-skill", "SKILL.md"), []byte("# Codex"), 0644)
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets:
claude:
path: ` + claudePath + `
codex:
path: ` + codexPath + `
`)
result := sb.RunCLI("pull", "--all", "--dry-run")
result.AssertSuccess(t)
result.AssertOutputContains(t, "claude-skill")
result.AssertOutputContains(t, "codex-skill")
}
func TestPull_NoLocalSkills_ShowsMessage(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("shared-skill", map[string]string{"SKILL.md": "# Shared"})
targetPath := sb.CreateTarget("claude")
// Create only symlinked skill (not local)
os.Symlink(filepath.Join(sb.SourcePath, "shared-skill"), filepath.Join(targetPath, "shared-skill"))
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets:
claude:
path: ` + targetPath + `
`)
result := sb.RunCLI("pull")
result.AssertSuccess(t)
result.AssertOutputContains(t, "No local skills")
}
func TestPull_TargetNotFound_ReturnsError(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets: {}
`)
result := sb.RunCLI("pull", "nonexistent")
result.AssertFailure(t)
result.AssertAnyOutputContains(t, "not found")
}
func TestPull_CopiesToSource(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
targetPath := sb.CreateTarget("claude")
// Create local skill
localSkillPath := filepath.Join(targetPath, "new-skill")
os.MkdirAll(localSkillPath, 0755)
os.WriteFile(filepath.Join(localSkillPath, "SKILL.md"), []byte("# New Skill Content"), 0644)
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets:
claude:
path: ` + targetPath + `
`)
// Run with force to skip confirmation
result := sb.RunCLIWithInput("y\n", "pull", "--force")
result.AssertSuccess(t)
result.AssertOutputContains(t, "copied to source")
// Verify skill was copied to source
copiedSkillPath := filepath.Join(sb.SourcePath, "new-skill", "SKILL.md")
if !sb.FileExists(copiedSkillPath) {
t.Error("skill should be copied to source")
}
}
func TestPull_ExistsInSource_Skips(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
// Create skill in source first
sb.CreateSkill("existing-skill", map[string]string{"SKILL.md": "# Source Version"})
targetPath := sb.CreateTarget("claude")
// Create same skill in target (local copy)
localSkillPath := filepath.Join(targetPath, "existing-skill")
os.MkdirAll(localSkillPath, 0755)
os.WriteFile(filepath.Join(localSkillPath, "SKILL.md"), []byte("# Target Version"), 0644)
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets:
claude:
path: ` + targetPath + `
`)
result := sb.RunCLIWithInput("y\n", "pull")
result.AssertSuccess(t)
result.AssertOutputContains(t, "skipped")
}
func TestPull_MultipleTargets_RequiresAllOrName(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
claudePath := sb.CreateTarget("claude")
codexPath := sb.CreateTarget("codex")
// Create local skills in both targets
os.MkdirAll(filepath.Join(claudePath, "skill1"), 0755)
os.WriteFile(filepath.Join(claudePath, "skill1", "SKILL.md"), []byte("# 1"), 0644)
os.MkdirAll(filepath.Join(codexPath, "skill2"), 0755)
os.WriteFile(filepath.Join(codexPath, "skill2", "SKILL.md"), []byte("# 2"), 0644)
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets:
claude:
path: ` + claudePath + `
codex:
path: ` + codexPath + `
`)
// Without specifying target or --all
result := sb.RunCLI("pull")
// Should ask to specify target
result.AssertSuccess(t)
result.AssertOutputContains(t, "Specify a target")
}