Files
skillshare/tests/integration/pull_test.go
T
Willie a739902ac2 feat!: rename pull <target> to collect, simplify pull for git-only
BREAKING CHANGE: Command restructure for clearer symmetry

- Local sync: sync/collect (Source ↔ Targets)
- Remote sync: push/pull (Source ↔ Git Remote)

Changes:
- Add `collect` command (was `pull <target>`)
- Simplify `pull` to git remote only (was `pull --remote`)
- Add spinner effects to pull and push commands
- Update all documentation and skill references
- Add CHANGELOG.md
- Update help examples with practical workflows

Migration:
  pull claude     → collect claude
  pull --all      → collect --all
  pull --remote   → pull
2026-01-31 20:52:09 +08:00

210 lines
4.8 KiB
Go

package integration
import (
"os/exec"
"path/filepath"
"testing"
"skillshare/internal/testutil"
)
// Tests for pull command (git remote operations)
func TestPull_NoGitRepo_ShowsError(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets: {}
`)
result := sb.RunCLI("pull")
result.AssertSuccess(t)
result.AssertOutputContains(t, "not a git repository")
}
func TestPull_NoRemote_ShowsError(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets: {}
`)
// Initialize git but no remote
cmd := exec.Command("git", "init")
cmd.Dir = sb.SourcePath
if err := cmd.Run(); err != nil {
t.Skip("git not available")
}
result := sb.RunCLI("pull")
result.AssertSuccess(t)
result.AssertOutputContains(t, "No git remote")
}
func TestPull_UncommittedChanges_Refuses(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets: {}
`)
// Create bare repo as "remote"
bareRepo := filepath.Join(sb.Home, "remote.git")
cmd := exec.Command("git", "init", "--bare", bareRepo)
if err := cmd.Run(); err != nil {
t.Skip("git not available")
}
// Initialize git and add remote
cmd = exec.Command("git", "init")
cmd.Dir = sb.SourcePath
cmd.Run()
cmd = exec.Command("git", "remote", "add", "origin", bareRepo)
cmd.Dir = sb.SourcePath
cmd.Run()
configGitForPull(t, sb.SourcePath)
// Initial commit and push
cmd = exec.Command("git", "commit", "--allow-empty", "-m", "initial")
cmd.Dir = sb.SourcePath
cmd.Run()
cmd = exec.Command("git", "push", "-u", "origin", "master")
cmd.Dir = sb.SourcePath
if err := cmd.Run(); err != nil {
cmd = exec.Command("git", "push", "-u", "origin", "main")
cmd.Dir = sb.SourcePath
cmd.Run()
}
// Create uncommitted changes
sb.CreateSkill("uncommitted-skill", map[string]string{"SKILL.md": "# Uncommitted"})
result := sb.RunCLI("pull")
result.AssertSuccess(t)
result.AssertOutputContains(t, "Local changes detected")
}
func TestPull_DryRun_ShowsActions(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets: {}
`)
// Create bare repo as "remote"
bareRepo := filepath.Join(sb.Home, "remote.git")
cmd := exec.Command("git", "init", "--bare", bareRepo)
if err := cmd.Run(); err != nil {
t.Skip("git not available")
}
// Initialize git and add remote
cmd = exec.Command("git", "init")
cmd.Dir = sb.SourcePath
cmd.Run()
cmd = exec.Command("git", "remote", "add", "origin", bareRepo)
cmd.Dir = sb.SourcePath
cmd.Run()
configGitForPull(t, sb.SourcePath)
// Initial commit and push
cmd = exec.Command("git", "commit", "--allow-empty", "-m", "initial")
cmd.Dir = sb.SourcePath
cmd.Run()
cmd = exec.Command("git", "push", "-u", "origin", "master")
cmd.Dir = sb.SourcePath
if err := cmd.Run(); err != nil {
cmd = exec.Command("git", "push", "-u", "origin", "main")
cmd.Dir = sb.SourcePath
cmd.Run()
}
result := sb.RunCLI("pull", "--dry-run")
result.AssertSuccess(t)
result.AssertOutputContains(t, "dry-run")
}
func TestPull_ActualPull_AndSyncs(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
targetPath := sb.CreateTarget("claude")
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets:
claude:
path: ` + targetPath + `
`)
// Create bare repo as "remote"
bareRepo := filepath.Join(sb.Home, "remote.git")
cmd := exec.Command("git", "init", "--bare", bareRepo)
if err := cmd.Run(); err != nil {
t.Skip("git not available")
}
// Initialize git and add remote
cmd = exec.Command("git", "init")
cmd.Dir = sb.SourcePath
cmd.Run()
cmd = exec.Command("git", "remote", "add", "origin", bareRepo)
cmd.Dir = sb.SourcePath
cmd.Run()
configGitForPull(t, sb.SourcePath)
// Create skill, commit, and push
sb.CreateSkill("remote-skill", map[string]string{"SKILL.md": "# Remote Skill"})
cmd = exec.Command("git", "add", "-A")
cmd.Dir = sb.SourcePath
cmd.Run()
cmd = exec.Command("git", "commit", "-m", "add skill")
cmd.Dir = sb.SourcePath
cmd.Run()
cmd = exec.Command("git", "push", "-u", "origin", "master")
cmd.Dir = sb.SourcePath
if err := cmd.Run(); err != nil {
cmd = exec.Command("git", "push", "-u", "origin", "main")
cmd.Dir = sb.SourcePath
cmd.Run()
}
// Now run pull (already up to date, but should sync)
result := sb.RunCLI("pull")
result.AssertSuccess(t)
// Should sync to target
if !sb.FileExists(filepath.Join(targetPath, "remote-skill", "SKILL.md")) {
t.Error("skill should be synced to target after pull")
}
}
// Helper function for pull tests
func configGitForPull(t *testing.T, dir string) {
cmd := exec.Command("git", "config", "user.email", "test@test.com")
cmd.Dir = dir
cmd.Run()
cmd = exec.Command("git", "config", "user.name", "Test")
cmd.Dir = dir
cmd.Run()
}