doctor: dedupe mirror tests into a table, trim comments · Entire
doctor: dedupe mirror tests into a table, trim comments
248c522→main·
computermode·1mo ago·6 files·+123 added/-147 removed
Collapse the seven checkCommittedMetadataMirror tests into one table-driven test (setup returns the expected final mirror state) and cut comment prose throughout the mirror check, diagnosis, and bundle report to the essentials.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
Sessions
2e1b1751fbc2View transcript
[?
Identify Commands Needing Checkpoints v1.1 SupportClaude Code·Opus 4.8[1m]·2 steps](/content/gh/entireio/cli/session/bedfc466-2682-40f4-b92b-9f07eaafcc9f#timeline-2e1b1751fbc2/index.html)
Changes
6
cmd/entire/cli
Mdoctor.go+7/-9
Mdoctor_bundle.go+5/-10
Mdoctor_bundle_test.go+2/-3
Mdoctor_test.go+104/-115
strategy
Mv1_custom_ref_mirror.go+3/-8
Mv1_custom_ref_mirror_test.go+2/-2
95 unmodified lines
96
97
98
99
100
99
100
101
102
103
282 unmodified lines
386
387
388
389
390
391
392
389
390
391
392
393
394
61 unmodified lines
456
457
458
460
461
462
459
460
461
462
463
95 unmodified lines
finalErr = NewSilentError(fmt.Errorf("metadata check failed: %w", metadataErr))
}
// Check 2: v1.1 committed-read mirror drift (runs after check 1 because
// reconciliation rewrites v1 and re-mirrors; this catches residual drift).
// Check 2: v1.1 read-mirror drift (after check 1: reconciliation rewrites
// v1 and re-mirrors).
if mirrorErr := checkCommittedMetadataMirror(cmd, force); mirrorErr != nil {
fmt.Fprintf(cmd.ErrOrStderr(), "Error: checkpoint read mirror check failed: %v\n", mirrorErr)
if finalErr == nil {
282 unmodified lines
return nil
}
// checkCommittedMetadataMirror detects and optionally repairs a v1.1
// committed-read mirror that drifted from the v1 metadata branch. Read paths
// use the mirror as-is (no read-time self-repair), so doctor is the repair
// tool. Silent when checkpoints_version doesn't configure a mirror.
// checkCommittedMetadataMirror detects and optionally repairs v1.1 read-mirror
// drift. Read paths use the mirror as-is, so doctor is the repair tool.
// Silent when the topology has no mirror.
func checkCommittedMetadataMirror(cmd *cobra.Command, force bool) error {
ctx := cmd.Context()
repo, err := openRepository(ctx)
61 unmodified lines
return nil
}
// confirmDoctorFix asks a yes/no fix confirmation shared by doctor checks.
// Returns false with no error when the user declines (prints "-> Skipped")
// or aborts the prompt.
// 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) {
var confirmed bool
form := NewAccessibleForm
Mcmd/entire/cli/doctor.go+7/-9
147 unmodified lines
148
149
150
151
152
153
154
151
152
153
154
155
158
159
160
161
156
157
158
159
160
14 unmodified lines
175
176
177
182
183
178
179
180
181
147 unmodified lines
return nil
}
// entireRefsReport captures entire-related git refs (v1 metadata branch,
// v1.1 read mirror, shadow branches, origin tracking) plus the mirror
diagnosis. Best-effort: failures are recorded in the report instead of
// failing the bundle.
// entireRefsReport captures entire-related git refs plus the mirror diagnosis.
// Best-effort: failures are recorded in the report, not returned.
func entireRefsReport(ctx context.Context, repoRoot string) string {
var sb strings.Builder
// Deliberately broad namespace globs rather than the resolved topology
// refs: refs/heads/entire covers the metadata branch (paths.
// MetadataBranchName) plus shadow/trails branches, and refs/entire covers
// the v1.1 mirror (paths.MetadataRefName) and any future custom refs.
// Broad globs on purpose: refs/heads/entire also catches shadow/trails
// branches, refs/entire catches the v1.1 mirror and future custom refs.
cmd := exec.CommandContext(ctx, "git", "for-each-ref", "--format=%(refname) %(objectname)",
"refs/heads/entire", "refs/entire", "refs/remotes/origin/entire")
cmd.Dir = repoRoot
14 unmodified lines
if err != nil {
return fmt.Sprintf("mirror status: [error: %v]\n", err)
}
// The bundle may run with a CWD outside repoRoot; scope settings
// resolution to this repo before consulting the topology.
// Scope settings to repoRoot; the bundle's CWD may be elsewhere.
diag, err := strategy.DiagnoseCommittedMetadataMirror(settings.WithWorktreeRoot(ctx, repoRoot), repo)
if err != nil {
return fmt.Sprintf("mirror status: [error: %v]\n", err)
Mcmd/entire/cli/doctor_bundle.go+5/-10
75 unmodified lines
76
77
78
79
80
81
79
80
81
82
83
75 unmodified lines
}
// TestWriteDoctorBundle_CapturesEntireRefs — the bundle must record entire's
// git refs (v1 branch, v1.1 mirror, shadow branches) plus the mirror
diagnosis so support can debug v1.1 read issues from a bundle alone.
// The bundle must record entire's git refs and the mirror diagnosis so
// support can debug v1.1 read issues from a bundle alone.
func TestWriteDoctorBundle_CapturesEntireRefs(t *testing.T) {
t.Parallel()
Mcmd/entire/cli/doctor_bundle_test.go+2/-3
399 unmodified lines
400
401
402
403
404
405
403
404
405
406
35 unmodified lines
442
443
444
446
447
445
446
447
448
6 unmodified lines
455
456
457
460
461
462
463
464
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
466
467
468
469
545
546
547
471
472
473
474
548
549
550
551
552
553
554
476
477
478
479
480
481
482
555
556
557
558
559
560
561
562
563
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
564
565
566
567
399 unmodified lines
}
// setupMirrorCheckRepo creates a repo with one commit and v1.1 settings,
// chdirs in (cannot t.Parallel), and returns the opened repository.
// setupMirrorCheckRepo is setupHeadFlagsRepo plus the v1.1 settings opt-in.
func setupMirrorCheckRepo(t *testing.T) *git.Repository {
t.Helper()
repo := setupHeadFlagsRepo(t)
35 unmodified lines
return ref.Hash(), true
}
// secondCommitInCwd creates a second commit in the current test repo and
// returns its hash.
// secondCommitInCwd creates a second commit in the test repo and returns its hash.
func secondCommitInCwd(t *testing.T, repo *git.Repository) plumbing.Hash {
t.Helper()
cwd, err := os.Getwd()
6 unmodified lines
return head.Hash()
}
// TestCheckCommittedMetadataMirror_SilentWhenNotConfigured — v1-mode repos
// (no checkpoints_version opt-in) must see no mirror output at all.
func TestCheckCommittedMetadataMirror_SilentWhenNotConfigured(t *testing.T) {
repo := setupHeadFlagsRepo(t) // no v1.1 settings
setMetadataV1Branch(t, repo)
Mcmd/entire/cli/doctor_test.go+104/-115
32 unmodified lines
33
34
35
36
37
36
37
38
39
15 unmodified lines
55
56
57
59
60
58
59
60
61
2 unmodified lines
64
65
66
69
70
71
72
67
68
69
70
32 unmodified lines
MirrorPrimaryMissing // mirror exists but the primary ref it mirrors is gone
// String returns the status name; doctor and bundle output derive their
// labels from here so the two surfaces cannot drift.
// String returns the status label shared by doctor and bundle output.
func (s MirrorStatus) String() string {
switch s {
case MirrorNotConfigured:
15 unmodified lines
}
// MirrorDiagnosis reports the mirror's state plus the resolved topology so
// callers can repair with MirrorCommittedMetadataRef.
// MirrorDiagnosis is the mirror's state plus the resolved topology for repair.
type MirrorDiagnosis struct {
Status MirrorStatus
Refs checkpoint.CommittedRefs
2 unmodified lines
}
// DiagnoseCommittedMetadataMirror classifies the mirror ref against the local
// primary metadata ref. Read-only: it never creates, advances, or deletes
// refs — repair is the caller's decision (e.g. `entire doctor`). Diagnosis is
// against the local primary only; a remote-tracking ref ahead of the local
// primary is an entire-managed fetch concern, not a mirror one.
// primary metadata ref. Read-only; repair is the caller's decision.
func DiagnoseCommittedMetadataMirror(ctx context.Context, repo *git.Repository) (MirrorDiagnosis, error) {
refs := checkpoint.ResolveCommittedRefs(ctx)
diag := MirrorDiagnosis{Status: MirrorNotConfigured, Refs: refs}
Mcmd/entire/cli/strategy/v1_custom_ref_mirror.go+3/-8
385 unmodified lines
386
387
388
389
389
390
391
392
71 unmodified lines
464
465
466
467
467
468
469
470
385 unmodified lines
assert.Equal(t, v1Hash, got, "custom ref must track v1 after combined-attribution write")
// Not parallel: uses t.Chdir().
// Not parallel: uses t.Chdir(). Setup returns the expected diagnosis fields.
func TestDiagnoseCommittedMetadataMirror(t *testing.T) {
setMirror := func(t *testing.T, repo *git.Repository, hash plumbing.Hash) {
t.Helper()
71 unmodified lines
assert.Equal(t, expected.primary, diag.Primary)
assert.Equal(t, expected.mirror, diag.Mirror)
assert.Equal(t, expected.status != MirrorNotConfigured, diag.Refs.HasMirror(),
"Refs must carry the resolved topology so callers can repair with MirrorCommittedMetadataRef")
"Refs must carry the topology for repair"
mirrorAfter, mirrorExistsAfter := v1CustomRefHash(t, repo)
require.Equal(t, mirrorExistedBefore, mirrorExistsAfter, "diagnosis must not create or delete the mirror ref")