diff --git a/cmd/bd/doctor/agent.go b/cmd/bd/doctor/agent.go index a80058c8f..d9b786ad6 100644 --- a/cmd/bd/doctor/agent.go +++ b/cmd/bd/doctor/agent.go @@ -216,7 +216,7 @@ func enrichLargeDatabase(dc DoctorCheck) agentEnrichment { explanation: fmt.Sprintf("The database has accumulated many closed issues: %s. This may cause performance degradation in list/search operations. Pruning is optional and destructive.", dc.Message), observed: dc.Message, expected: "Closed issue count below configured threshold", - commands: []string{"bd cleanup --older-than 90"}, + commands: []string{"bd prune --older-than 90d"}, sourceFiles: []string{"cmd/bd/doctor/database.go:CheckDatabaseSize"}, } } @@ -521,7 +521,7 @@ func enrichStaleClosedIssues(dc DoctorCheck) agentEnrichment { explanation: fmt.Sprintf("Stale closed issues: %s. Old closed issues can be pruned to reduce database size and improve query performance.", dc.Message), observed: dc.Message + "\n" + dc.Detail, expected: "Closed issues are within acceptable age/count thresholds", - commands: []string{"bd cleanup --older-than 90"}, + commands: []string{"bd prune --older-than 90d"}, sourceFiles: []string{"cmd/bd/doctor/maintenance.go:CheckStaleClosedIssues"}, } } diff --git a/cmd/bd/doctor/agent_test.go b/cmd/bd/doctor/agent_test.go index e706de051..21be11162 100644 --- a/cmd/bd/doctor/agent_test.go +++ b/cmd/bd/doctor/agent_test.go @@ -37,3 +37,29 @@ func TestEnrichFreshClone_WithSyncRemoteMentionsBootstrapAndFallback(t *testing. t.Fatalf("expected sync.remote fallback command, got %#v", enrichment.commands) } } + +// TestPruneEnrichmentsRecommendRealCommand pins the agent-facing pruning +// advice to a command that exists: these enrichments used to suggest +// 'bd cleanup', which is not a root-level command in this build (cleanup +// lives under 'bd admin cleanup'). 'bd prune --older-than 90d' previews by +// default, matching the "optional and destructive" framing. +func TestPruneEnrichmentsRecommendRealCommand(t *testing.T) { + enrichments := map[string]agentEnrichment{ + "Large Database": enrichLargeDatabase(DoctorCheck{Message: "6000 closed issues (threshold: 5000)"}), + "Stale Closed Issues": enrichStaleClosedIssues(DoctorCheck{Message: "5000 stale closed issues"}), + } + for name, enrichment := range enrichments { + if len(enrichment.commands) == 0 { + t.Errorf("%s enrichment has no commands", name) + continue + } + for _, cmd := range enrichment.commands { + if strings.Contains(cmd, "bd cleanup") { + t.Errorf("%s enrichment recommends nonexistent 'bd cleanup': %q", name, cmd) + } + } + if !strings.HasPrefix(enrichment.commands[0], "bd prune") { + t.Errorf("%s enrichment should recommend 'bd prune', got %#v", name, enrichment.commands) + } + } +} diff --git a/cmd/bd/doctor/database.go b/cmd/bd/doctor/database.go index d63919dee..97b0c8f83 100644 --- a/cmd/bd/doctor/database.go +++ b/cmd/bd/doctor/database.go @@ -498,7 +498,7 @@ func isNoDbModeConfigured(beadsDir string) bool { // CheckDatabaseSize warns when the database has accumulated many closed issues. // This is purely informational - pruning is NEVER auto-fixed because it -// permanently deletes data. Users must explicitly run 'bd cleanup' to prune. +// permanently deletes data. Users must explicitly run 'bd prune' to prune. // // Config: doctor.suggest_pruning_issue_count (default: 5000, 0 = disabled) // @@ -577,13 +577,7 @@ func checkDatabaseSizeWithStore(store *dolt.DoltStore) DoctorCheck { } if stats.ClosedIssues > threshold { - return DoctorCheck{ - Name: "Large Database", - Status: StatusWarning, - Message: fmt.Sprintf("%d closed issues (threshold: %d)", stats.ClosedIssues, threshold), - Detail: "Large number of closed issues may impact performance", - Fix: "Consider running 'bd cleanup --older-than 90' to prune old closed issues", - } + return largeDatabaseWarning(stats.ClosedIssues, threshold) } return DoctorCheck{ @@ -592,3 +586,17 @@ func checkDatabaseSizeWithStore(store *dolt.DoltStore) DoctorCheck { Message: fmt.Sprintf("%d closed issues (threshold: %d)", stats.ClosedIssues, threshold), } } + +// largeDatabaseWarning builds the over-threshold Large Database check. Split +// out so tests can pin the recommended remedy to a command that actually +// exists: 'bd prune' is the root-level lifecycle command ('cleanup' only +// exists as 'bd admin cleanup'). +func largeDatabaseWarning(closedIssues, threshold int) DoctorCheck { + return DoctorCheck{ + Name: "Large Database", + Status: StatusWarning, + Message: fmt.Sprintf("%d closed issues (threshold: %d)", closedIssues, threshold), + Detail: "Large number of closed issues may impact performance", + Fix: "Consider running 'bd prune --older-than 90d' to prune old closed issues (preview; add --force to delete)", + } +} diff --git a/cmd/bd/doctor/database_test.go b/cmd/bd/doctor/database_test.go index b6d331bf7..7e3555aa7 100644 --- a/cmd/bd/doctor/database_test.go +++ b/cmd/bd/doctor/database_test.go @@ -210,3 +210,21 @@ func setupDoctorBareParentWorktree(t *testing.T) (string, string) { return bareDir, featureWorktreeDir } + +// TestLargeDatabaseWarningRecommendsRealCommand pins the Large Database +// remedy to a command that exists: the check used to recommend 'bd cleanup', +// which is not a root-level command in this build (cleanup lives under +// 'bd admin cleanup'); the operator-facing lifecycle command is 'bd prune'. +func TestLargeDatabaseWarningRecommendsRealCommand(t *testing.T) { + dc := largeDatabaseWarning(6000, 5000) + + if dc.Status != StatusWarning { + t.Fatalf("expected StatusWarning, got %v", dc.Status) + } + if strings.Contains(dc.Fix, "bd cleanup") { + t.Fatalf("Large Database fix recommends nonexistent 'bd cleanup': %q", dc.Fix) + } + if !strings.Contains(dc.Fix, "bd prune") { + t.Fatalf("Large Database fix should recommend 'bd prune': %q", dc.Fix) + } +} diff --git a/cmd/bd/doctor/perf_dolt.go b/cmd/bd/doctor/perf_dolt.go index 2a473eae8..11aa03623 100644 --- a/cmd/bd/doctor/perf_dolt.go +++ b/cmd/bd/doctor/perf_dolt.go @@ -361,7 +361,7 @@ func assessDoltPerformance(metrics *DoltPerfMetrics) { // Check database size if metrics.TotalIssues > 5000 && metrics.ClosedIssues > 4000 { - recommendations = append(recommendations, "Many closed issues. Consider 'bd cleanup' to prune old issues.") + recommendations = append(recommendations, "Many closed issues. Consider 'bd prune --older-than 90d' to prune old issues.") } if len(warnings) == 0 { diff --git a/cmd/bd/doctor_fix.go b/cmd/bd/doctor_fix.go index 1c0c9ff06..d694b5b24 100644 --- a/cmd/bd/doctor_fix.go +++ b/cmd/bd/doctor_fix.go @@ -363,7 +363,7 @@ func applyFixList(path string, fixes []doctorCheck) { continue case "Large Database": // No auto-fix: pruning deletes data, must be user-controlled - fmt.Printf(" ⚠ Run 'bd cleanup --older-than 90' to prune old closed issues\n") + fmt.Printf(" ⚠ Run 'bd prune --older-than 90d' to preview prunable closed issues (add --force to delete)\n") continue case "Legacy MQ Files": err = doctor.FixStaleMQFiles(path) diff --git a/engdocs/messaging.md b/engdocs/messaging.md index bd0b13f6a..1b2f5a117 100644 --- a/engdocs/messaging.md +++ b/engdocs/messaging.md @@ -74,13 +74,13 @@ Messages marked `ephemeral: true` are transient - they can be bulk-deleted after ```bash # Clean up closed ephemeral messages -bd cleanup --ephemeral --force +bd purge --force # Preview what would be deleted -bd cleanup --ephemeral --dry-run +bd purge --dry-run # Only delete ephemeral messages older than 7 days -bd cleanup --ephemeral --older-than 7 --force +bd purge --older-than 7d --force ``` Ephemeral messages are: