From 3e142f8c35f6ce06b8d9f1f0ff97f4380b33bfcb Mon Sep 17 00:00:00 2001 From: Caleb Allen Date: Mon, 17 Aug 2026 22:11:10 -0400 Subject: [PATCH] test(downloads): guard the service fixture on something the fake sets `newServiceFixture` stops auto-pick from starting a grab, because none of its tests is about the download and a detached `go m.grab(...)` racing `t.TempDir()`'s cleanup is how they fail. It did that with `MaxSizeMB: 1` -- and the size gates read `Candidate.TotalSize`, which real providers fill and the fake leaves at zero. Zero is under every ceiling, so the guard never fired and the race it was written to prevent kept happening, roughly one run in fifteen: TempDir RemoveAll cleanup: unlinkat ... : directory not empty The guard is a format the fake never produces. Thirty consecutive whole-package runs, none. `TestManualDownloadSatisfiesRequestOnSuccess` was relying on the guard being broken -- it is the one test here that wants the download -- so it now clears the preferences itself rather than depending on a bug. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01MeQt5hgXg5YGoNZQ9ozG7L --- backend/download/service_test.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/backend/download/service_test.go b/backend/download/service_test.go index c497047..fccdd8e 100644 --- a/backend/download/service_test.go +++ b/backend/download/service_test.go @@ -36,13 +36,24 @@ func newServiceFixture(t *testing.T) serviceFixture { // assertion read it; the second is that same goroutine still writing // into `t.TempDir()` after the test returned. One cause, two shapes. // - // Putting the candidate outside the auto-pick size window stops the + // Putting the candidate outside the auto-pick guardrails stops the // grab from ever starting, which is better than waiting for it: there // is no goroutine to be slow, so the tests state what they mean // ("the request exists, in this state") without a timing assumption // underneath. A test that does want the download has `managerFixture` // and sets its own preferences. - mf.manager.SetPreferences(AutoDownloadPrefs{MaxSizeMB: 1}) + // + // The guard is a *format* the fake never produces, and it used to be + // `MaxSizeMB: 1`, which never fired: the size gates read + // `Candidate.TotalSize`, which real providers fill and the fake + // leaves at zero, and zero is under every ceiling. So the grab went + // ahead anyway and the second failure shape above — the TempDir + // cleanup race — kept happening, reproducibly, roughly one run in + // fifteen. A guard has to be keyed on something the fixture + // actually sets. + mf.manager.SetPreferences(AutoDownloadPrefs{ + AllowedFormats: []Format{FormatWMA}, + }) return serviceFixture{managerFixture: mf, svc: svc} } @@ -182,6 +193,11 @@ func TestManualDownloadSatisfiesRequestOnSuccess(t *testing.T) { f := newServiceFixture(t) ctx := context.Background() + // This is the one test here that is *about* the download, so it + // undoes the fixture's guard rather than relying on it — which is + // what it was doing implicitly while the guard did not work. + f.manager.SetPreferences(AutoDownloadPrefs{}) + provider := fakeWithAlbum(1, "source", ".flac") f.manager.installProvider(Config{ID: 1, Priority: 50}, provider)