From 25c7db71b168cf76b70ffb75193217979310d363 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 2 Dec 2026 12:48:47 -0500 Subject: [PATCH] test(library): the volume-absent refusals are tested apart from the mark cap (#8296) Every case marked every track, so the 25% cap refused before the root checks were reached: run 11272 broke the empty-root check and the test still passed. The walk now marks one track of ten and clears a returned one, which reconcile would do, so only the root and empty-walk checks can refuse it; and the test asserts nothing was cleared either, since those checks run before restores. Co-Authored-By: Claude Opus 5.5 --- internal/library/reconcile_test.go | 34 +++++++++++++++++++----------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/internal/library/reconcile_test.go b/internal/library/reconcile_test.go index e63c7f40..c14a0719 100644 --- a/internal/library/reconcile_test.go +++ b/internal/library/reconcile_test.go @@ -255,34 +255,44 @@ func TestReconcileMissing_ClearsEvenWhenMarkCapTrips(t *testing.T) { } } -// A walk that cannot be trusted marks nothing: one that saw no files, a root -// that is not mounted (absent), a mount point with nothing on it (present but -// empty, which os.Stat alone would pass), one detached root among several, -// or no roots configured at all. +// A walk that cannot be trusted changes nothing, neither marking nor clearing: +// one that saw no files, a root that is not mounted (absent), a mount point +// with nothing on it (present but empty, which os.Stat alone would pass), one +// detached root among several, or no roots configured at all. The walk below +// would otherwise mark one track of ten, under missingMarkMaxFraction, and +// clear a returned one, so only these checks can refuse it. func TestReconcileMissing_RefusesWhenAVolumeLooksAbsent(t *testing.T) { - seenSomething := map[string]struct{}{"/x": {}} + rows := []dbq.ListTrackPathsForReconcileRow{row(99, "/music/back.mp3", true)} + walked := map[string]struct{}{"/music/back.mp3": {}} + for i := 0; i < 10; i++ { + p := fmt.Sprintf("/music/track-%02d.mp3", i) + rows = append(rows, row(byte(i), p, false)) + if i > 0 { + walked[p] = struct{}{} + } + } for _, tc := range []struct { name string roots func(t *testing.T) []string seen map[string]struct{} }{ {"the walk saw no files", func(t *testing.T) []string { return []string{populatedRoot(t)} }, map[string]struct{}{}}, - {"a root is absent", func(t *testing.T) []string { return []string{filepath.Join(t.TempDir(), "not-mounted")} }, seenSomething}, - {"a root is empty", func(t *testing.T) []string { return []string{t.TempDir()} }, seenSomething}, + {"a root is absent", func(t *testing.T) []string { return []string{filepath.Join(t.TempDir(), "not-mounted")} }, walked}, + {"a root is empty", func(t *testing.T) []string { return []string{t.TempDir()} }, walked}, {"one of several roots is absent", func(t *testing.T) []string { return []string{populatedRoot(t), filepath.Join(t.TempDir(), "detached")} - }, seenSomething}, - {"no roots configured", func(*testing.T) []string { return nil }, seenSomething}, + }, walked}, + {"no roots configured", func(*testing.T) []string { return nil }, walked}, } { t.Run(tc.name, func(t *testing.T) { s := testScanner(t, tc.roots(t)...) - q := &fakeReconciler{rows: []dbq.ListTrackPathsForReconcileRow{row(1, "/music/a.mp3", false)}} + q := &fakeReconciler{rows: rows} var stats Stats if err := s.reconcileMissing(context.Background(), q, tc.seen, &stats); err == nil { t.Fatal("reconcile went ahead; want a refusal") } - if len(q.marked) != 0 { - t.Errorf("marked rows: %v", q.marked) + if len(q.marked) != 0 || len(q.cleared) != 0 { + t.Errorf("marked %v, cleared %v; want nothing changed", q.marked, q.cleared) } }) }