mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
Prevent test-docker and test-docker-online from running the same 36 offline integration tests. Each offline test file now has `//go:build !online` so the two sets are mutually exclusive: - default (no tag): 36 offline tests only - -tags online: online tests only
212 lines
4.8 KiB
Go
212 lines
4.8 KiB
Go
//go:build !online
|
|
|
|
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()
|
|
}
|