From 5e91efe695a191c2a3a16e035497000747b2d080 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Sun, 17 May 2026 21:05:36 -0400 Subject: [PATCH] test(coverart): fix registry-wipe + stale provider signature Two distinct pre-existing test bugs in the last failing cluster: 1. newTestEnricher() called resetRegistryForTests() itself, wiping the fake providers callers Register() right before calling it (its own doc says callers register first and reconcile() picks them up). The ~8 TestEnrichArtist_* failures (source stayed NULL, no thumb written) all stem from reconcile() seeing an empty registry. Remove the internal reset; make every caller that lacked one own the registry lifecycle explicitly (resetRegistryForTests + t.Cleanup): SidecarFound, NoSidecarNoMBID, AlreadySidecar_NoOp, DrainsNullSourceOnly. 2. apiTestAlbumProvider.FetchAlbumCover had a stale signature (context, string) predating the AlbumRef refactor; it no longer satisfied coverart.AlbumCoverProvider, so the p.(AlbumCoverProvider) capability assertion failed and TestAdminListCoverSources got supports=[]. Fix the param to coverart.AlbumRef. Test-only. (A1/A2 were correct; they unmasked these. Any residual album-enricher semantics failures will be root-caused from the next clean run, not bundled speculatively.) Co-Authored-By: Claude Opus 4.7 (1M context) --- internal/api/admin_cover_sources_test.go | 2 +- internal/coverart/enricher_test.go | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/internal/api/admin_cover_sources_test.go b/internal/api/admin_cover_sources_test.go index 029ace76..3a0de4e7 100644 --- a/internal/api/admin_cover_sources_test.go +++ b/internal/api/admin_cover_sources_test.go @@ -27,7 +27,7 @@ func (p *apiTestAlbumProvider) DisplayName() string { re func (p *apiTestAlbumProvider) RequiresAPIKey() bool { return false } func (p *apiTestAlbumProvider) DefaultEnabled() bool { return true } func (p *apiTestAlbumProvider) Configure(_ coverart.ProviderSettings) error { return nil } -func (p *apiTestAlbumProvider) FetchAlbumCover(_ context.Context, _ string) ([]byte, error) { +func (p *apiTestAlbumProvider) FetchAlbumCover(_ context.Context, _ coverart.AlbumRef) ([]byte, error) { return []byte("img"), nil } diff --git a/internal/coverart/enricher_test.go b/internal/coverart/enricher_test.go index 09848647..acb93d6e 100644 --- a/internal/coverart/enricher_test.go +++ b/internal/coverart/enricher_test.go @@ -49,8 +49,11 @@ func discardLogger() *slog.Logger { // pick them up. func newTestEnricher(t *testing.T, pool *pgxpool.Pool) *Enricher { t.Helper() - resetRegistryForTests() - t.Cleanup(resetRegistryForTests) + // Do NOT reset the registry here: callers register their fakes + // before calling this (see doc above) and resetting would wipe them + // so reconcile() sees zero providers — every art source then stays + // NULL. Registry lifecycle is the caller's (each test does + // resetRegistryForTests + t.Cleanup before Register()). s, err := NewSettingsService(context.Background(), pool, discardLogger()) if err != nil { t.Fatalf("NewSettingsService: %v", err) @@ -100,6 +103,8 @@ func TestEnrichAlbum_SidecarFound(t *testing.T) { t.Fatal(err) } + resetRegistryForTests() // deterministic empty registry (sidecar-only path) + t.Cleanup(resetRegistryForTests) e := newTestEnricher(t, pool) if err := e.EnrichAlbum(context.Background(), id); err != nil { t.Fatalf("enrich: %v", err) @@ -119,6 +124,8 @@ func TestEnrichAlbum_SidecarFound(t *testing.T) { func TestEnrichAlbum_NoSidecarNoMBID_LeavesNull(t *testing.T) { pool := newPool(t) id, _ := seedAlbumWithTrack(t, pool, "NoMbid", "Artist", "") + resetRegistryForTests() // deterministic empty registry (no provider can supply) + t.Cleanup(resetRegistryForTests) e := newTestEnricher(t, pool) if err := e.EnrichAlbum(context.Background(), id); err != nil { t.Fatalf("enrich: %v", err) @@ -227,6 +234,8 @@ func TestEnrichAlbum_AlreadySidecar_NoOp(t *testing.T) { t.Fatal(err) } + resetRegistryForTests() // deterministic empty registry (sidecar-only path) + t.Cleanup(resetRegistryForTests) e := newTestEnricher(t, pool) if err := e.EnrichAlbum(context.Background(), id); err != nil { t.Fatalf("first enrich: %v", err) @@ -262,6 +271,8 @@ func TestEnrichBatch_DrainsNullSourceOnly(t *testing.T) { t.Fatal(err) } + resetRegistryForTests() // deterministic empty registry + t.Cleanup(resetRegistryForTests) e := newTestEnricher(t, pool) processed, _, _, err := e.EnrichBatch(context.Background(), 100, nil) if err != nil {