947f944fe9
The hand-rolled extractor in internal/library/mbids.go looked up keys that
dhowden/tag never produces, for every supported audio format:
Vorbis (FLAC/OGG): dhowden lowercases keys at parse time (vorbis.go:59),
we looked up MUSICBRAINZ_ALBUMID. Always missed.
ID3v2 (MP3): dhowden stores TXXX frames under bare TXXX/TXXX_N keys
with *tag.Comm values; the Picard tag name is on the value's
Description field, not part of the key. We looked up
TXXX:MusicBrainz Album Id. Always missed.
MP4 (M4A): dhowden stores freeform iTunes atoms under their bare
sub-name. We looked up ----:com.apple.iTunes:MusicBrainz Album Id.
Always missed.
Net effect: every album in the m7-380 boot backfill reported
processed=N, healed=0, skipped=N. The m7-379 enricher gate then
short-circuited NULL on every album, so MBCAA was never queried.
Symptom: "all albums skipped" during cover enrichment.
The pre-existing unit tests passed because they hand-built Raw() maps
with the intended-but-incorrect keys, never round-tripping through
dhowden's parser.
Replace the hand-rolled extractor with dhowden's own mbz sub-package,
which knows the per-format Raw() conventions and uses lowercase
canonical keys (mbz.Album, mbz.Artist). Update both call sites to pass
the full tag.Metadata instead of just Raw(). Rewrite the test with a
stubMeta implementing tag.Metadata, asserting against the actual
per-format Raw() shape, plus a regression guard that pins "uppercase
Vorbis keys must not match" so the v0 bug can't sneak back.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
112 lines
3.6 KiB
Go
112 lines
3.6 KiB
Go
package library
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/dhowden/tag"
|
|
)
|
|
|
|
// stubMeta is a minimal tag.Metadata used to feed the dhowden mbz extractor
|
|
// the same Raw()/Format() shape its real parsers produce. The other interface
|
|
// methods return zero values — the extractor only branches on Format and
|
|
// iterates Raw().
|
|
type stubMeta struct {
|
|
format tag.Format
|
|
raw map[string]interface{}
|
|
}
|
|
|
|
func (s stubMeta) Format() tag.Format { return s.format }
|
|
func (s stubMeta) FileType() tag.FileType { return tag.UnknownFileType }
|
|
func (s stubMeta) Title() string { return "" }
|
|
func (s stubMeta) Album() string { return "" }
|
|
func (s stubMeta) Artist() string { return "" }
|
|
func (s stubMeta) AlbumArtist() string { return "" }
|
|
func (s stubMeta) Composer() string { return "" }
|
|
func (s stubMeta) Year() int { return 0 }
|
|
func (s stubMeta) Genre() string { return "" }
|
|
func (s stubMeta) Track() (int, int) { return 0, 0 }
|
|
func (s stubMeta) Disc() (int, int) { return 0, 0 }
|
|
func (s stubMeta) Picture() *tag.Picture { return nil }
|
|
func (s stubMeta) Lyrics() string { return "" }
|
|
func (s stubMeta) Comment() string { return "" }
|
|
func (s stubMeta) Raw() map[string]interface{} { return s.raw }
|
|
|
|
func TestExtractMBIDs_Vorbis(t *testing.T) {
|
|
// dhowden lowercases all Vorbis comment keys at parse time.
|
|
m := stubMeta{
|
|
format: tag.VORBIS,
|
|
raw: map[string]interface{}{
|
|
"musicbrainz_albumid": "abc",
|
|
"musicbrainz_artistid": "def",
|
|
},
|
|
}
|
|
a, ar := extractMBIDs(m)
|
|
if a != "abc" || ar != "def" {
|
|
t.Errorf("got (%q, %q), want (\"abc\", \"def\")", a, ar)
|
|
}
|
|
}
|
|
|
|
func TestExtractMBIDs_ID3v2(t *testing.T) {
|
|
// dhowden stores TXXX frames under bare "TXXX"/"TXXX_N" keys with
|
|
// *tag.Comm values whose Description holds the Picard tag name.
|
|
m := stubMeta{
|
|
format: tag.ID3v2_4,
|
|
raw: map[string]interface{}{
|
|
"TXXX": &tag.Comm{
|
|
Description: "MusicBrainz Album Id",
|
|
Text: "abc-123",
|
|
},
|
|
"TXXX_0": &tag.Comm{
|
|
Description: "MusicBrainz Artist Id",
|
|
Text: "def-456",
|
|
},
|
|
},
|
|
}
|
|
a, ar := extractMBIDs(m)
|
|
if a != "abc-123" || ar != "def-456" {
|
|
t.Errorf("got (%q, %q), want (\"abc-123\", \"def-456\")", a, ar)
|
|
}
|
|
}
|
|
|
|
func TestExtractMBIDs_MP4(t *testing.T) {
|
|
// dhowden stores freeform iTunes atoms under their bare sub-name.
|
|
// mbz.Extract maps the human-readable form back to its lowercase key.
|
|
m := stubMeta{
|
|
format: tag.MP4,
|
|
raw: map[string]interface{}{
|
|
"MusicBrainz Album Id": "abc",
|
|
"MusicBrainz Artist Id": "def",
|
|
},
|
|
}
|
|
a, ar := extractMBIDs(m)
|
|
if a != "abc" || ar != "def" {
|
|
t.Errorf("got (%q, %q), want (\"abc\", \"def\")", a, ar)
|
|
}
|
|
}
|
|
|
|
func TestExtractMBIDs_MissingTagsReturnEmpty(t *testing.T) {
|
|
m := stubMeta{format: tag.VORBIS, raw: map[string]interface{}{}}
|
|
a, ar := extractMBIDs(m)
|
|
if a != "" || ar != "" {
|
|
t.Errorf("got (%q, %q), want empty", a, ar)
|
|
}
|
|
}
|
|
|
|
func TestExtractMBIDs_VorbisUppercaseKeysMiss(t *testing.T) {
|
|
// Regression guard: real dhowden never produces uppercase Vorbis
|
|
// keys. If a future change starts looking up "MUSICBRAINZ_ALBUMID"
|
|
// directly, this test must keep returning empty so we don't
|
|
// silently re-introduce the v0 bug where every album skipped.
|
|
m := stubMeta{
|
|
format: tag.VORBIS,
|
|
raw: map[string]interface{}{
|
|
"MUSICBRAINZ_ALBUMID": "wrong-case",
|
|
"MUSICBRAINZ_ARTISTID": "wrong-case",
|
|
},
|
|
}
|
|
a, ar := extractMBIDs(m)
|
|
if a != "" || ar != "" {
|
|
t.Errorf("uppercase Vorbis keys must not match dhowden output; got (%q, %q)", a, ar)
|
|
}
|
|
}
|