mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
Implement remaining Issue 46 optimizations and developer experience fixes. Install and update optimization: - optimize install --track for subdirectory sources by attempting sparse checkout first while preserving git metadata - fallback to existing tracked clone strategy on sparse capability or sparse path errors - clean sparse created destination before fallback clone to avoid destination already exists failures - improve tracked install spinner wording for subdir sources - add tracked subdir unit tests for sparse success and sparse to full clone fallback Progress user experience: - normalize git progress lines by stripping volatile transfer rate suffix - dedupe and throttle spinner and tree spinner update frequency to reduce tty flicker - add unit tests for spinner progress normalization and throttling behavior GitHub API messaging: - improve rate limit guidance to suggest setting token env vars or using gh auth login Devcontainer isolation: - make ssenv enter command mode run from isolated environment cwd - fix setup global init detection to use skillshare status global mode - add auto mode hint in devcontainer wrapper when workspace project config takes precedence E2E and tests: - expand Issue 46 runbook with install, install track, update, no token fallback, sparse paths, and isolation checks - update compact warning output test expectations to match current grouped warning rendering Verification: - go test internal install package - go test internal install sparse and tracked subdir tests - go test internal ui package - go test cmd skillshare package - go build skillshare binary and run integration TestInstall_Subdir - run tracked subdir tests inside devcontainer
147 lines
4.5 KiB
Go
147 lines
4.5 KiB
Go
package install
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestInstallTrackedRepo_SubdirSparseCheckout(t *testing.T) {
|
|
if _, err := exec.LookPath("git"); err != nil {
|
|
t.Skip("git not available")
|
|
}
|
|
if !gitSupportsSparseCheckout() {
|
|
t.Skip("git does not support sparse-checkout")
|
|
}
|
|
|
|
tmp := t.TempDir()
|
|
work := filepath.Join(tmp, "work")
|
|
remote := filepath.Join(tmp, "remote.git")
|
|
sourceDir := filepath.Join(tmp, "source")
|
|
|
|
mustRunGit(t, "", "init", work)
|
|
mustRunGit(t, work, "config", "user.email", "test@test.com")
|
|
mustRunGit(t, work, "config", "user.name", "Test")
|
|
|
|
if err := os.MkdirAll(filepath.Join(work, "skills", "one"), 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.MkdirAll(filepath.Join(work, "skills", "two"), 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(work, "skills", "one", "SKILL.md"), []byte("# one"), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(work, "skills", "two", "SKILL.md"), []byte("# two"), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
mustRunGit(t, work, "add", ".")
|
|
mustRunGit(t, work, "commit", "-m", "init")
|
|
mustRunGit(t, "", "clone", "--bare", work, remote)
|
|
|
|
if err := os.MkdirAll(sourceDir, 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
source := &Source{
|
|
Type: SourceTypeGitHTTPS,
|
|
Raw: "file://" + remote + "/skills/one",
|
|
CloneURL: "file://" + remote,
|
|
Subdir: "skills/one",
|
|
Name: "one",
|
|
}
|
|
|
|
result, err := InstallTrackedRepo(source, sourceDir, InstallOptions{Name: "track-subdir", Force: true})
|
|
if err != nil {
|
|
t.Fatalf("InstallTrackedRepo() error = %v", err)
|
|
}
|
|
if result.Action != "cloned" {
|
|
t.Fatalf("Action = %q, want %q", result.Action, "cloned")
|
|
}
|
|
if result.SkillCount != 1 {
|
|
t.Fatalf("SkillCount = %d, want 1", result.SkillCount)
|
|
}
|
|
|
|
repoPath := filepath.Join(sourceDir, "_track-subdir")
|
|
if _, err := os.Stat(filepath.Join(repoPath, ".git")); err != nil {
|
|
t.Fatalf("expected tracked repo to preserve .git: %v", err)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(repoPath, "skills", "one", "SKILL.md")); err != nil {
|
|
t.Fatalf("expected sparse subdir skill to exist: %v", err)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(repoPath, "skills", "two", "SKILL.md")); err == nil {
|
|
t.Fatalf("expected non-sparse path to be absent")
|
|
}
|
|
}
|
|
|
|
func TestInstallTrackedRepo_SubdirSparseFallback(t *testing.T) {
|
|
if _, err := exec.LookPath("git"); err != nil {
|
|
t.Skip("git not available")
|
|
}
|
|
if !gitSupportsSparseCheckout() {
|
|
t.Skip("git does not support sparse-checkout")
|
|
}
|
|
|
|
tmp := t.TempDir()
|
|
work := filepath.Join(tmp, "work")
|
|
remote := filepath.Join(tmp, "remote.git")
|
|
sourceDir := filepath.Join(tmp, "source")
|
|
|
|
mustRunGit(t, "", "init", work)
|
|
mustRunGit(t, work, "config", "user.email", "test@test.com")
|
|
mustRunGit(t, work, "config", "user.name", "Test")
|
|
|
|
if err := os.MkdirAll(filepath.Join(work, "skills", "one"), 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.MkdirAll(filepath.Join(work, "skills", "two"), 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(work, "skills", "one", "SKILL.md"), []byte("# one"), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(work, "skills", "two", "SKILL.md"), []byte("# two"), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
mustRunGit(t, work, "add", ".")
|
|
mustRunGit(t, work, "commit", "-m", "init")
|
|
mustRunGit(t, "", "clone", "--bare", work, remote)
|
|
|
|
if err := os.MkdirAll(sourceDir, 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
source := &Source{
|
|
Type: SourceTypeGitHTTPS,
|
|
Raw: "file://" + remote + "//invalid",
|
|
CloneURL: "file://" + remote,
|
|
Subdir: "/invalid",
|
|
Name: "invalid",
|
|
}
|
|
|
|
result, err := InstallTrackedRepo(source, sourceDir, InstallOptions{Name: "track-subdir-fallback", Force: true})
|
|
if err != nil {
|
|
t.Fatalf("InstallTrackedRepo() fallback error = %v", err)
|
|
}
|
|
if result.Action != "cloned" {
|
|
t.Fatalf("Action = %q, want %q", result.Action, "cloned")
|
|
}
|
|
if result.SkillCount != 2 {
|
|
t.Fatalf("SkillCount = %d, want 2 (full-clone fallback)", result.SkillCount)
|
|
}
|
|
|
|
repoPath := filepath.Join(sourceDir, "_track-subdir-fallback")
|
|
if _, err := os.Stat(filepath.Join(repoPath, ".git")); err != nil {
|
|
t.Fatalf("expected tracked repo to preserve .git: %v", err)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(repoPath, "skills", "one", "SKILL.md")); err != nil {
|
|
t.Fatalf("expected fallback full clone file to exist: %v", err)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(repoPath, "skills", "two", "SKILL.md")); err != nil {
|
|
t.Fatalf("expected fallback full clone file to exist: %v", err)
|
|
}
|
|
}
|