mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
fix(uninstall): fix stale summary, skip message, and pluralization UX
After pre-flight filters out dirty tracked repos, recalculate summary
so spinner and confirm prompt use correct noun type. Print skip count
when repos are skipped. Replace all "(s)" patterns with pluralS() for
natural English output ("2 groups" not "2 group(s)"). Add isMixed()
method to avoid magic string comparison on noun().
This commit is contained in:
+35
-14
@@ -306,26 +306,40 @@ func (s uninstallTypeSummary) noun() string {
|
||||
total := s.skills + s.groups + s.trackedRepos
|
||||
switch {
|
||||
case s.groups == total:
|
||||
return "group(s)"
|
||||
return fmt.Sprintf("group%s", pluralS(total))
|
||||
case s.skills == total:
|
||||
return "skill(s)"
|
||||
return fmt.Sprintf("skill%s", pluralS(total))
|
||||
case s.trackedRepos == total:
|
||||
return "tracked repo(s)"
|
||||
return fmt.Sprintf("tracked repo%s", pluralS(total))
|
||||
default:
|
||||
return "target(s)"
|
||||
return fmt.Sprintf("target%s", pluralS(total))
|
||||
}
|
||||
}
|
||||
|
||||
func (s uninstallTypeSummary) isMixed() bool {
|
||||
types := 0
|
||||
if s.skills > 0 {
|
||||
types++
|
||||
}
|
||||
if s.groups > 0 {
|
||||
types++
|
||||
}
|
||||
if s.trackedRepos > 0 {
|
||||
types++
|
||||
}
|
||||
return types > 1
|
||||
}
|
||||
|
||||
func (s uninstallTypeSummary) details() string {
|
||||
var parts []string
|
||||
if s.skills > 0 {
|
||||
parts = append(parts, fmt.Sprintf("%d skill(s)", s.skills))
|
||||
parts = append(parts, fmt.Sprintf("%d skill%s", s.skills, pluralS(s.skills)))
|
||||
}
|
||||
if s.groups > 0 {
|
||||
parts = append(parts, fmt.Sprintf("%d group(s)", s.groups))
|
||||
parts = append(parts, fmt.Sprintf("%d group%s", s.groups, pluralS(s.groups)))
|
||||
}
|
||||
if s.trackedRepos > 0 {
|
||||
parts = append(parts, fmt.Sprintf("%d tracked repo(s)", s.trackedRepos))
|
||||
parts = append(parts, fmt.Sprintf("%d tracked repo%s", s.trackedRepos, pluralS(s.trackedRepos)))
|
||||
}
|
||||
return strings.Join(parts, ", ")
|
||||
}
|
||||
@@ -423,7 +437,7 @@ func performUninstallQuiet(target *uninstallTarget, cfg *config.Config) (typeLab
|
||||
return "tracked repo", nil
|
||||
}
|
||||
if groupSkillCount > 0 {
|
||||
return fmt.Sprintf("group, %d skills", groupSkillCount), nil
|
||||
return fmt.Sprintf("group, %d skill%s", groupSkillCount, pluralS(groupSkillCount)), nil
|
||||
}
|
||||
return "skill", nil
|
||||
}
|
||||
@@ -467,7 +481,7 @@ func performUninstall(target *uninstallTarget, cfg *config.Config) error {
|
||||
|
||||
// Opportunistic cleanup of expired trash items
|
||||
if n, _ := trash.Cleanup(trash.TrashDir(), 0); n > 0 {
|
||||
ui.Info("Cleaned up %d expired trash item(s)", n)
|
||||
ui.Info("Cleaned up %d expired trash item%s", n, pluralS(n))
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -608,14 +622,14 @@ func cmdUninstall(args []string) error {
|
||||
if t.isTrackedRepo {
|
||||
fmt.Printf(" - %s (tracked repository)\n", t.name)
|
||||
} else if c := summary.groupSkillCount[t.path]; c > 0 {
|
||||
fmt.Printf(" - %s (group, %d skills)\n", t.name, c)
|
||||
fmt.Printf(" - %s (group, %d skill%s)\n", t.name, c, pluralS(c))
|
||||
}
|
||||
}
|
||||
if summary.skills > 0 {
|
||||
fmt.Printf(" ... and %d skill(s)\n", summary.skills)
|
||||
fmt.Printf(" ... and %d skill%s\n", summary.skills, pluralS(summary.skills))
|
||||
}
|
||||
} else {
|
||||
if summary.noun() == "target(s)" {
|
||||
if summary.isMixed() {
|
||||
ui.Info("Includes: %s", summary.details())
|
||||
}
|
||||
for _, t := range targets {
|
||||
@@ -623,7 +637,7 @@ func cmdUninstall(args []string) error {
|
||||
if t.isTrackedRepo {
|
||||
label += " (tracked repository)"
|
||||
} else if c := summary.groupSkillCount[t.path]; c > 0 {
|
||||
label += fmt.Sprintf(" (group, %d skills)", c)
|
||||
label += fmt.Sprintf(" (group, %d skill%s)", c, pluralS(c))
|
||||
} else {
|
||||
label += " (skill)"
|
||||
}
|
||||
@@ -702,7 +716,14 @@ func cmdUninstall(args []string) error {
|
||||
ui.Warning("Repository %s has uncommitted changes (proceeding with --force)", t.name)
|
||||
preflight = append(preflight, t)
|
||||
}
|
||||
skippedCount := len(targets) - len(preflight)
|
||||
targets = preflight
|
||||
summary = summarizeUninstallTargets(targets)
|
||||
|
||||
if skippedCount > 0 {
|
||||
ui.Info("%d tracked repo%s skipped, %d remaining", skippedCount, pluralS(skippedCount), len(targets))
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
if len(targets) == 0 {
|
||||
return fmt.Errorf("no skills to uninstall after pre-flight checks")
|
||||
@@ -833,7 +854,7 @@ func cmdUninstall(args []string) error {
|
||||
|
||||
// Opportunistic cleanup of expired trash items
|
||||
if n, _ := trash.Cleanup(trash.TrashDir(), 0); n > 0 {
|
||||
ui.Info("Cleaned up %d expired trash item(s)", n)
|
||||
ui.Info("Cleaned up %d expired trash item%s", n, pluralS(n))
|
||||
}
|
||||
} else {
|
||||
for _, t := range targets {
|
||||
|
||||
@@ -67,7 +67,7 @@ func performProjectUninstallQuiet(target *uninstallTarget, root, trashDir string
|
||||
return "tracked repo", nil
|
||||
}
|
||||
if groupSkillCount > 0 {
|
||||
return fmt.Sprintf("group, %d skills", groupSkillCount), nil
|
||||
return fmt.Sprintf("group, %d skill%s", groupSkillCount, pluralS(groupSkillCount)), nil
|
||||
}
|
||||
return "skill", nil
|
||||
}
|
||||
@@ -181,14 +181,14 @@ func cmdUninstallProject(args []string, root string) error {
|
||||
if t.isTrackedRepo {
|
||||
fmt.Printf(" - %s (tracked repository)\n", t.name)
|
||||
} else if c := summary.groupSkillCount[t.path]; c > 0 {
|
||||
fmt.Printf(" - %s (group, %d skills)\n", t.name, c)
|
||||
fmt.Printf(" - %s (group, %d skill%s)\n", t.name, c, pluralS(c))
|
||||
}
|
||||
}
|
||||
if summary.skills > 0 {
|
||||
fmt.Printf(" ... and %d skill(s)\n", summary.skills)
|
||||
fmt.Printf(" ... and %d skill%s\n", summary.skills, pluralS(summary.skills))
|
||||
}
|
||||
} else {
|
||||
if summary.noun() == "target(s)" {
|
||||
if summary.isMixed() {
|
||||
ui.Info("Includes: %s", summary.details())
|
||||
}
|
||||
for _, t := range targets {
|
||||
@@ -196,7 +196,7 @@ func cmdUninstallProject(args []string, root string) error {
|
||||
if t.isTrackedRepo {
|
||||
label += " (tracked repository)"
|
||||
} else if c := summary.groupSkillCount[t.path]; c > 0 {
|
||||
label += fmt.Sprintf(" (group, %d skills)", c)
|
||||
label += fmt.Sprintf(" (group, %d skill%s)", c, pluralS(c))
|
||||
} else {
|
||||
label += " (skill)"
|
||||
}
|
||||
@@ -219,7 +219,14 @@ func cmdUninstallProject(args []string, root string) error {
|
||||
}
|
||||
preflight = append(preflight, t)
|
||||
}
|
||||
skippedCount := len(targets) - len(preflight)
|
||||
targets = preflight
|
||||
summary = summarizeUninstallTargets(targets)
|
||||
|
||||
if skippedCount > 0 {
|
||||
ui.Info("%d tracked repo%s skipped, %d remaining", skippedCount, pluralS(skippedCount), len(targets))
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
if len(targets) == 0 {
|
||||
return fmt.Errorf("no skills to uninstall after pre-flight checks")
|
||||
@@ -348,7 +355,7 @@ func cmdUninstallProject(args []string, root string) error {
|
||||
|
||||
// Opportunistic cleanup of expired trash items
|
||||
if n, _ := trash.Cleanup(trashDir, 0); n > 0 {
|
||||
ui.Info("Cleaned up %d expired trash item(s)", n)
|
||||
ui.Info("Cleaned up %d expired trash item%s", n, pluralS(n))
|
||||
}
|
||||
} else {
|
||||
for _, t := range targets {
|
||||
@@ -430,7 +437,7 @@ func cmdUninstallProject(args []string, root string) error {
|
||||
|
||||
// Opportunistic cleanup of expired trash items
|
||||
if n, _ := trash.Cleanup(trashDir, 0); n > 0 {
|
||||
ui.Info("Cleaned up %d expired trash item(s)", n)
|
||||
ui.Info("Cleaned up %d expired trash item%s", n, pluralS(n))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -461,8 +462,8 @@ targets: {}
|
||||
|
||||
result := sb.RunCLI("uninstall", "fix-review", "security/", "--force")
|
||||
result.AssertSuccess(t)
|
||||
result.AssertOutputContains(t, "Uninstalling 2 group(s)")
|
||||
result.AssertAnyOutputContains(t, "Uninstalled 2 group(s)")
|
||||
result.AssertOutputContains(t, "Uninstalling 2 groups")
|
||||
result.AssertAnyOutputContains(t, "Uninstalled 2 groups")
|
||||
result.AssertAnyOutputContains(t, "fix-review")
|
||||
result.AssertAnyOutputContains(t, "security")
|
||||
|
||||
@@ -637,3 +638,46 @@ targets: {}
|
||||
result.AssertFailure(t)
|
||||
result.AssertAnyOutputContains(t, "--all")
|
||||
}
|
||||
|
||||
// TestUninstall_BatchSkipsDirtyTrackedRepo verifies that --all skips dirty
|
||||
// tracked repos, prints a skip summary, and still removes clean skills.
|
||||
func TestUninstall_BatchSkipsDirtyTrackedRepo(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
// Create a tracked repo with uncommitted changes (dirty)
|
||||
dirtyRepoPath := filepath.Join(sb.SourcePath, "_dirty-repo")
|
||||
os.MkdirAll(dirtyRepoPath, 0755)
|
||||
os.WriteFile(filepath.Join(dirtyRepoPath, "SKILL.md"), []byte("# Dirty"), 0644)
|
||||
initGitRepo(t, dirtyRepoPath)
|
||||
// Add an untracked file to make it dirty
|
||||
os.WriteFile(filepath.Join(dirtyRepoPath, "uncommitted.txt"), []byte("dirty"), 0644)
|
||||
|
||||
// Create 2 normal skills
|
||||
sb.CreateSkill("clean-a", map[string]string{"SKILL.md": "# A"})
|
||||
sb.CreateSkill("clean-b", map[string]string{"SKILL.md": "# B"})
|
||||
|
||||
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
||||
targets: {}
|
||||
`)
|
||||
|
||||
result := sb.RunCLIWithInput("y\n", "uninstall", "--all")
|
||||
result.AssertSuccess(t)
|
||||
|
||||
// Dirty repo should still exist
|
||||
if !sb.FileExists(dirtyRepoPath) {
|
||||
t.Error("dirty tracked repo should NOT be removed")
|
||||
}
|
||||
|
||||
// Clean skills should be removed
|
||||
if sb.FileExists(filepath.Join(sb.SourcePath, "clean-a")) {
|
||||
t.Error("clean-a should be removed")
|
||||
}
|
||||
if sb.FileExists(filepath.Join(sb.SourcePath, "clean-b")) {
|
||||
t.Error("clean-b should be removed")
|
||||
}
|
||||
|
||||
// Skip summary should appear
|
||||
result.AssertAnyOutputContains(t, "skipped")
|
||||
result.AssertAnyOutputContains(t, "remaining")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user