Files
skillshare/tests/integration/push_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

200 lines
4.4 KiB
Go

package integration
import (
"os"
"os/exec"
"path/filepath"
"testing"
"skillshare/internal/testutil"
)
func TestPush_NoConfig_ReturnsError(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
os.Remove(sb.ConfigPath)
result := sb.RunCLI("push")
result.AssertFailure(t)
result.AssertAnyOutputContains(t, "config not found")
}
func TestPush_NoGitRepo_ShowsError(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets: {}
`)
result := sb.RunCLI("push")
result.AssertSuccess(t) // Command succeeds but shows error message
result.AssertOutputContains(t, "not a git repository")
}
func TestPush_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("push")
result.AssertSuccess(t)
result.AssertOutputContains(t, "No git remote")
}
func TestPush_DryRun_ShowsWhatWouldBePushed(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets: {}
`)
// Initialize git with remote
initGitWithRemote(t, sb)
// Create a skill (uncommitted)
sb.CreateSkill("new-skill", map[string]string{"SKILL.md": "# New"})
result := sb.RunCLI("push", "--dry-run")
result.AssertSuccess(t)
result.AssertOutputContains(t, "dry-run")
result.AssertOutputContains(t, "Would stage")
}
func TestPush_NoChanges_ShowsNoChanges(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets: {}
`)
// Initialize git with remote and commit everything
initGitWithRemote(t, sb)
commitAll(t, sb.SourcePath, "initial")
result := sb.RunCLI("push", "--dry-run")
result.AssertSuccess(t)
result.AssertOutputContains(t, "No changes")
}
func TestPush_CustomMessage(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets: {}
`)
initGitWithRemote(t, sb)
sb.CreateSkill("test-skill", map[string]string{"SKILL.md": "# Test"})
result := sb.RunCLI("push", "-m", "Custom commit message", "--dry-run")
result.AssertSuccess(t)
result.AssertOutputContains(t, "Custom commit message")
}
func TestPush_ActualPush_ToLocalBareRepo(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()
configGit(t, sb.SourcePath)
// Initial commit and push to set up tracking
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 {
// Try main branch
cmd = exec.Command("git", "push", "-u", "origin", "main")
cmd.Dir = sb.SourcePath
cmd.Run()
}
// Create a skill
sb.CreateSkill("pushed-skill", map[string]string{"SKILL.md": "# Pushed"})
result := sb.RunCLI("push", "-m", "Test push")
result.AssertSuccess(t)
result.AssertOutputContains(t, "Push complete")
}
// Helper functions
func initGitWithRemote(t *testing.T, sb *testutil.Sandbox) {
cmd := exec.Command("git", "init")
cmd.Dir = sb.SourcePath
if err := cmd.Run(); err != nil {
t.Skip("git not available")
}
// Add a fake remote (won't actually push but passes remote check)
cmd = exec.Command("git", "remote", "add", "origin", "git@github.com:test/test.git")
cmd.Dir = sb.SourcePath
cmd.Run()
configGit(t, sb.SourcePath)
}
func configGit(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()
}
func commitAll(t *testing.T, dir, message string) {
cmd := exec.Command("git", "add", "-A")
cmd.Dir = dir
cmd.Run()
cmd = exec.Command("git", "commit", "-m", message, "--allow-empty")
cmd.Dir = dir
cmd.Run()
}