diff --git a/cmd/skillshare/doctor.go b/cmd/skillshare/doctor.go index 6b69315d8..414bf51ed 100644 --- a/cmd/skillshare/doctor.go +++ b/cmd/skillshare/doctor.go @@ -13,6 +13,7 @@ import ( "skillshare/internal/backup" "skillshare/internal/config" "skillshare/internal/install" + "skillshare/internal/skillignore" "skillshare/internal/sync" "skillshare/internal/trash" "skillshare/internal/ui" @@ -41,6 +42,10 @@ func (r *doctorResult) addCheck(name, status, message string, details []string) }) } +func (r *doctorResult) addInfo(name, message string) { + r.addCheck(name, checkInfo, message, nil) +} + func cmdDoctor(args []string) error { mode, rest, err := parseModeArgs(args) if err != nil { @@ -200,15 +205,16 @@ func cmdDoctorProject(root string, jsonMode bool) error { } func runDoctorChecks(cfg *config.Config, result *doctorResult, isProject bool) { - // Single discovery pass for all checks + // Single discovery pass for all checks (with .skillignore stats) sp := ui.StartSpinner("Discovering skills...") - discovered, discoverErr := sync.DiscoverSourceSkills(cfg.Source) + discovered, stats, discoverErr := sync.DiscoverSourceSkillsWithStats(cfg.Source) if discoverErr != nil { discovered = nil } sp.Stop() checkSource(cfg, result, discovered, discoverErr) + checkSkillignore(result, stats) checkSymlinkSupport(result) if !isProject { @@ -237,6 +243,23 @@ func printDoctorSummary(result *doctorResult) { } +// checkSkillignore reports .skillignore status as an info or pass check. +func checkSkillignore(result *doctorResult, stats *skillignore.IgnoreStats) { + if stats == nil || !stats.Active() { + result.addInfo("skillignore", "No .skillignore found — you can create one to hide skills from discovery") + return + } + + msg := fmt.Sprintf(".skillignore: %d patterns, %d skills ignored", stats.PatternCount(), stats.IgnoredCount()) + var details []string + details = append(details, stats.Patterns...) + if len(stats.IgnoredSkills) > 0 { + details = append(details, "---") + details = append(details, stats.IgnoredSkills...) + } + result.addCheck("skillignore", checkPass, msg, details) +} + func checkSource(cfg *config.Config, result *doctorResult, discovered []sync.DiscoveredSkill, discoverErr error) { info, err := os.Stat(cfg.Source) if err != nil { diff --git a/cmd/skillshare/doctor_json.go b/cmd/skillshare/doctor_json.go index 94b389caf..dda3351e4 100644 --- a/cmd/skillshare/doctor_json.go +++ b/cmd/skillshare/doctor_json.go @@ -11,6 +11,7 @@ const ( checkPass = "pass" checkWarning = "warning" checkError = "error" + checkInfo = "info" ) // doctorCheck represents a single health check result for JSON output. @@ -32,6 +33,7 @@ type doctorSummary struct { Pass int `json:"pass"` Warnings int `json:"warnings"` Errors int `json:"errors"` + Info int `json:"info"` } type doctorVersion struct { @@ -45,7 +47,7 @@ type doctorVersion struct { // because check-level counts may differ from the text-mode counters when a // single check function calls addError/addWarning multiple times. func buildDoctorOutput(result *doctorResult) doctorOutput { - var pass, warnings, errors int + var pass, warnings, errors, info int for _, c := range result.checks { switch c.Status { case checkPass: @@ -54,6 +56,8 @@ func buildDoctorOutput(result *doctorResult) doctorOutput { warnings++ case checkError: errors++ + case checkInfo: + info++ } } return doctorOutput{ @@ -63,6 +67,7 @@ func buildDoctorOutput(result *doctorResult) doctorOutput { Pass: pass, Warnings: warnings, Errors: errors, + Info: info, }, } } diff --git a/tests/integration/doctor_test.go b/tests/integration/doctor_test.go index babff8b1c..42c2326f9 100644 --- a/tests/integration/doctor_test.go +++ b/tests/integration/doctor_test.go @@ -7,6 +7,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "testing" "skillshare/internal/testutil" @@ -527,6 +528,7 @@ type doctorJSONSummary struct { Pass int `json:"pass"` Warnings int `json:"warnings"` Errors int `json:"errors"` + Info int `json:"info"` } type doctorJSONVersion struct { @@ -728,3 +730,81 @@ targets: t.Error("expected checks to contain an entry with name \"trash\"") } } + +func TestDoctor_JSON_SkillignorePresent(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + sb.CreateSkill("visible-skill", map[string]string{"SKILL.md": "# Visible"}) + sb.CreateSkill("hidden-skill", map[string]string{"SKILL.md": "# Hidden"}) + + // Create .skillignore that hides one skill + os.WriteFile(filepath.Join(sb.SourcePath, ".skillignore"), []byte("hidden-skill\n"), 0644) + + sb.WriteConfig(`source: ` + sb.SourcePath + ` +targets: {} +`) + + result := sb.RunCLI("doctor", "--json") + + result.AssertSuccess(t) + out := parseDoctorJSON(t, result.Stdout) + + found := false + for _, c := range out.Checks { + if c.Name == "skillignore" { + found = true + if c.Status != "pass" { + t.Errorf("expected skillignore status \"pass\", got %q", c.Status) + } + if c.Message == "" { + t.Error("expected non-empty message for skillignore check") + } + // Message should mention patterns and ignored count + if !strings.Contains(c.Message, "1 patterns") || !strings.Contains(c.Message, "1 skills ignored") { + t.Errorf("expected message to mention pattern/ignored counts, got: %s", c.Message) + } + break + } + } + if !found { + t.Error("expected checks to contain an entry with name \"skillignore\"") + } +} + +func TestDoctor_JSON_SkillignoreAbsent(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + sb.CreateSkill("skill1", map[string]string{"SKILL.md": "# Skill 1"}) + + sb.WriteConfig(`source: ` + sb.SourcePath + ` +targets: {} +`) + + result := sb.RunCLI("doctor", "--json") + + result.AssertSuccess(t) + out := parseDoctorJSON(t, result.Stdout) + + found := false + for _, c := range out.Checks { + if c.Name == "skillignore" { + found = true + if c.Status != "info" { + t.Errorf("expected skillignore status \"info\", got %q", c.Status) + } + if c.Message == "" { + t.Error("expected non-empty message for skillignore check") + } + // Info count should be reflected in summary + break + } + } + if !found { + t.Error("expected checks to contain an entry with name \"skillignore\"") + } + if out.Summary.Info == 0 { + t.Error("expected summary.info > 0 when .skillignore is absent") + } +}