From a86b7a5e0706cf4617b5f8ac46d57ba160a3095a Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Sun, 17 May 2026 22:22:44 -0400 Subject: [PATCH] =?UTF-8?q?test(coverart):=20DrainsNullSourceOnly=20?= =?UTF-8?q?=E2=80=94=20stamp=20id2=20'none'=20at=20current=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test marked id2 'none' via SetAlbumCover, which (covers.sql:42) does NOT set cover_art_sources_version. ListAlbumsMissingCover treats 'none' AND version != current as eligible, so id2 (version 0, current 1) was wrongly drained → processed=2. The comment's intent ("'none' with current version → not drained") requires SetAlbumCoverWithVersion (albums.sql) stamped with the live GetCurrentSourcesVersion — the same value EnrichBatch compares against. Test-only. Co-Authored-By: Claude Opus 4.7 (1M context) --- internal/coverart/enricher_test.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/internal/coverart/enricher_test.go b/internal/coverart/enricher_test.go index acb93d6e..27032762 100644 --- a/internal/coverart/enricher_test.go +++ b/internal/coverart/enricher_test.go @@ -262,18 +262,27 @@ func TestEnrichBatch_DrainsNullSourceOnly(t *testing.T) { } id2, _ := seedAlbumWithTrack(t, pool, "Drain2", "B", "") - // Pre-mark id2 as 'none' with current version — should NOT be drained by EnrichBatch - // (ListAlbumsMissingCover only returns stale-version 'none'). - src := "none" - if err := dbq.New(pool).SetAlbumCover(context.Background(), dbq.SetAlbumCoverParams{ - ID: id2, Column2: "", CoverArtSource: &src, - }); err != nil { - t.Fatal(err) - } resetRegistryForTests() // deterministic empty registry t.Cleanup(resetRegistryForTests) e := newTestEnricher(t, pool) + + // Pre-mark id2 as 'none' AT the current sources version so + // ListAlbumsMissingCover excludes it (it only returns NULL or + // stale-version 'none'). SetAlbumCover does NOT stamp the version; + // SetAlbumCoverWithVersion does — use the live current version, the + // same value EnrichBatch compares against. + curVer, err := dbq.New(pool).GetCurrentSourcesVersion(context.Background()) + if err != nil { + t.Fatalf("current version: %v", err) + } + src := "none" + if err := dbq.New(pool).SetAlbumCoverWithVersion(context.Background(), dbq.SetAlbumCoverWithVersionParams{ + ID: id2, CoverArtPath: nil, CoverArtSource: &src, CoverArtSourcesVersion: curVer, + }); err != nil { + t.Fatal(err) + } + processed, _, _, err := e.EnrichBatch(context.Background(), 100, nil) if err != nil { t.Fatalf("batch: %v", err)