doctor: address review feedback on mirror check · Entire
doctor: address review feedback on mirror check
78e9893→main·
computermode·1mo ago·3 files·+28 added/-7 removed
- confirmDoctorFix now runs via RunWithContext and treats a cancelled command context as a clean skip (guards before huh opens the TTY), honoring interrupts instead of surfacing a wrapped error.
- Fix the STALE headline: "advance the mirror to the
tip" instead of the contradictory "to its tip". - Close the go-git repo opened in mirrorStatusReportLine.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
Sessions
82c0ad9a1407View transcript
Changes
3
cmd/entire/cli
Mdoctor.go+13/-7
Mdoctor_bundle.go+1
Mdoctor_test.go+14
368 unmodified lines
369
370
371
372
372
373
374
375
53 unmodified lines
429
430
431
432
432
433
434
435
4 unmodified lines
440
441
442
443
443
444
445
446
10 unmodified lines
457
458
459
460
461
460
461
462
463
464
465
466
467
468
469
470
2 unmodified lines
473
474
475
470
471
476
477
478
479
480
368 unmodified lines
fmt.Fprintln(w, " Fix: cherry-pick local checkpoints onto remote tip (preserves all data).")
if !force {
proceed, promptErr := confirmDoctorFix(w, "Fix disconnected metadata branches?")
proceed, promptErr := confirmDoctorFix(ctx, w, "Fix disconnected metadata branches?")
if promptErr != nil {
return promptErr
}
53 unmodified lines
fmt.Fprintf(w, "Checkpoint read mirror: %s\n", diag.Status)
fmt.Fprintf(w, " Mirror is at %s, behind %s at %s; reads miss newer checkpoints.\n",
shortMirrorHash(diag.Mirror), primary, shortMirrorHash(diag.Primary))
fmt.Fprintln(w, " Fix: advance the mirror to its tip.")
fmt.Fprintf(w, " Fix: advance the mirror to the %s tip.\n", primary)
case strategy.MirrorDiverged:
fmt.Fprintf(w, "Checkpoint read mirror: %s\n", diag.Status)
fmt.Fprintf(w, " Mirror at %s has commits not on %s (at %s). Writes never target the\n",
4 unmodified lines
}
if !force {
proceed, promptErr := confirmDoctorFix(w, "Repair checkpoint read mirror?")
proceed, promptErr := confirmDoctorFix(ctx, w, "Repair checkpoint read mirror?")
if promptErr != nil {
return promptErr
}
10 unmodified lines
}
// confirmDoctorFix prompts to apply a doctor fix. Declining (which prints
// "-> Skipped") and aborting both return false with no error.
func confirmDoctorFix(w io.Writer, title string) (bool, error) {
// "-> Skipped"), aborting (Ctrl+C), and context cancellation all return false
// with no error.
func confirmDoctorFix(ctx context.Context, w io.Writer, title string) (bool, error) {
// huh opens the TTY during form startup regardless of context state, so
// guard explicitly to honor an already-cancelled command context.
if ctx.Err() != nil {
return false, nil //nolint:nilerr // cancelled context is a clean skip, not an error
}
var confirmed bool
form := NewAccessibleForm(
huh.NewGroup(
2 unmodified lines
Value(&confirmed),
),
)
if err := form.Run(); err != nil {
if errors.Is(err, huh.ErrUserAborted) {
if err := form.RunWithContext(ctx); err != nil {
if errors.Is(err, huh.ErrUserAborted) || errors.Is(err, context.Canceled) {
return false, nil
}
return false, fmt.Errorf("prompt failed: %w", err)
}
Mcmd/entire/cli/doctor.go+13/-7
174 unmodified lines
175 176 177 178 179 180 181
174 unmodified lines
if err != nil { return fmt.Sprintf("mirror status: [error: %v]\n", err) } defer repo.Close() // Scope settings to repoRoot; the bundle's CWD may be elsewhere. diag, err := strategy.DiagnoseCommittedMetadataMirror(settings.WithWorktreeRoot(ctx, repoRoot), repo) if err != nil {
Mcmd/entire/cli/doctor_bundle.go+1
727 unmodified lines
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
727 unmodified lines
require.Contains(t, out, "entire enable") require.NotContains(t, out, "Codex hook trust: REVIEW NEEDED") }
// TestConfirmDoctorFix_CancelledContext verifies that a cancelled command // context makes the confirm prompt return (false, nil) rather than surfacing a // wrapped error — doctor fixes are skipped cleanly on interrupt. func TestConfirmDoctorFix_CancelledContext(t *testing.T) { t.Parallel() ctx, cancel := context.WithCancel(context.Background()) cancel() // cancel before prompting
var out bytes.Buffer proceed, err := confirmDoctorFix(ctx, &out, "Apply fix?") require.NoError(t, err) assert.False(t, proceed) }
Mcmd/entire/cli/doctor_test.go+14