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) <noreply@anthropic.com>
This commit is contained in:
2026-05-17 21:05:36 -04:00
parent 47572b2e95
commit 5e91efe695
2 changed files with 14 additions and 3 deletions
+1 -1
View File
@@ -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
}
+13 -2
View File
@@ -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 {