test(library): merge repeated cases into tables, drop tests of other code (#8296)
release / web (push) Successful in 1m30s
release / go (push) Successful in 1m57s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 3m26s
release / android (push) Successful in 4m40s
release / Build signed APK (push) Successful in 5m12s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Publish the release image to GHCR (dispatch only) (push) Skipped
release / Build + push container image (push) Successful in 28s
release / Verify release artifacts (tag releases only) (push) Skipped

- Moved-file adoption: 14 tests become one table. uniqueMatch, the row
  converters and pgtype's zero UUID are dropped: the adoption table covers
  the first two, and the third tests pgx.
- Reconcile: marking and its change rows, and restoring and its change rows,
  are one test each; the five "a volume looks absent" refusals are one table.
  Dropped: an error-propagation test.
- Genres: the ID3 reader cases, the normalisers and extractGenres across
  ID3, FLAC, Ogg and MP4 are one table each.
- MusicBrainz tag ids: eleven per-format tests become one table.
- Scan trigger: start / skip / reap is one table. Dropped: a closed-pool test.
- Stage publisher: six tests become three.
- Duplicate resolver: the cross-release cases (rip, renamed, kept as fine,
  two titles) asserted the same outcome once the resolver stopped removing
  files. They become one table that also checks the group's note, which is
  where rip and clean still differ. The auto-resolve-off song-link check
  moves into the existing auto-resolve-off test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 12:32:36 -05:00
co-authored by Claude Opus 5.5
parent 4811ec2ec9
commit ac8792323c
9 changed files with 456 additions and 1238 deletions
+49 -228
View File
@@ -31,215 +31,65 @@ 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",
},
}
ids := ReadTagMBIDs(m)
a, ar := ids.Release, ids.Artist
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",
},
},
}
ids := ReadTagMBIDs(m)
a, ar := ids.Release, ids.Artist
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",
},
}
ids := ReadTagMBIDs(m)
a, ar := ids.Release, ids.Artist
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{}{}}
ids := ReadTagMBIDs(m)
a, ar := ids.Release, ids.Artist
if a != "" || ar != "" {
t.Errorf("got (%q, %q), want empty", a, ar)
}
}
func TestExtractMBIDs_VorbisUppercaseKeysMiss(t *testing.T) {
// Real dhowden never produces uppercase Vorbis keys. Looking up
// "MUSICBRAINZ_ALBUMID" directly would find nothing, and every album
// would be skipped; this test keeps that lookup returning empty.
m := stubMeta{
format: tag.VORBIS,
raw: map[string]interface{}{
"MUSICBRAINZ_ALBUMID": "wrong-case",
"MUSICBRAINZ_ARTISTID": "wrong-case",
},
}
ids := ReadTagMBIDs(m)
a, ar := ids.Release, ids.Artist
if a != "" || ar != "" {
t.Errorf("uppercase Vorbis keys must not match dhowden output; got (%q, %q)", a, ar)
}
}
func TestExtractMBIDs_ID3v2StripsTrailingNUL(t *testing.T) {
// dhowden's readTextWithDescrFrame leaves the ID3v2.4 frame-
// terminator NUL on TXXX values. Postgres rejects NULs in text
// columns (SQLSTATE 22021), so we must strip them.
m := stubMeta{
format: tag.ID3v2_4,
raw: map[string]interface{}{
"TXXX": &tag.Comm{
Description: "MusicBrainz Album Id",
Text: "abc-123\x00",
},
"TXXX_0": &tag.Comm{
Description: "MusicBrainz Artist Id",
Text: "def-456\x00",
},
},
}
ids := ReadTagMBIDs(m)
a, ar := ids.Release, ids.Artist
if a != "abc-123" || ar != "def-456" {
t.Errorf("got (%q, %q), want trailing NUL stripped", a, ar)
}
}
func TestExtractMBIDs_ID3v2MultiValueTakesFirst(t *testing.T) {
// Some Picard configs emit multi-value TXXX:MusicBrainz Artist Id
// for collaborations, NUL-separated. Minstrel uses the primary
// release artist for MBCAA, so first wins.
m := stubMeta{
format: tag.ID3v2_4,
raw: map[string]interface{}{
"TXXX": &tag.Comm{
Description: "MusicBrainz Artist Id",
Text: "primary-mbid\x00collab-mbid",
},
},
}
ar := ReadTagMBIDs(m).Artist
if ar != "primary-mbid" {
t.Errorf("got %q, want %q", ar, "primary-mbid")
}
}
func TestCleanMBID_OnlyNULReturnsEmpty(t *testing.T) {
// Defensive: a TXXX value that is purely NULs (or empty after
// trimming) must round-trip to empty so the caller skips the row
// instead of writing a NUL-only string to Postgres.
if got := cleanMBID("\x00\x00"); got != "" {
t.Errorf("got %q, want empty", got)
}
if got := cleanMBID(""); got != "" {
t.Errorf("got %q, want empty", got)
}
}
// The release-group id is read beside the release id, from each
// format's own key, and the two are never confused.
func TestExtractReleaseGroupMBID(t *testing.T) {
cases := []struct {
// ReadTagMBIDs reads each MusicBrainz id from each format's own Picard key,
// in dhowden/tag's Raw() shape for that format: Vorbis keys lowercased, ID3
// TXXX frames under "TXXX"/"TXXX_N" with the Picard name in the Description,
// MP4 freeform atoms under their bare name. The release and the release
// group, and the recording and the release track, are never confused.
func TestReadTagMBIDs(t *testing.T) {
all := TagMBIDs{Release: "rel-1", Artist: "ar-1", AlbumArtist: "aa-1", ReleaseGroup: "rg-1", Recording: "rec-1"}
txxx := func(name, text string) *tag.Comm { return &tag.Comm{Description: name, Text: text} }
for _, tc := range []struct {
name string
meta stubMeta
want TagMBIDs
}{
{"vorbis", stubMeta{format: tag.VORBIS, raw: map[string]interface{}{
"musicbrainz_albumid": "release-1",
"musicbrainz_releasegroupid": "group-1",
}}},
"musicbrainz_albumid": "rel-1", "musicbrainz_artistid": "ar-1", "musicbrainz_albumartistid": "aa-1",
"musicbrainz_releasegroupid": "rg-1",
// Picard calls the recording MUSICBRAINZ_TRACKID in Vorbis, the
// name mbz gives the release track.
"musicbrainz_trackid": "rec-1", "musicbrainz_releasetrackid": "reltrack-1",
}}, all},
// dhowden leaves ID3v2.4's terminating NUL on TXXX values, and
// Postgres rejects NULs in text (SQLSTATE 22021).
{"id3v2", stubMeta{format: tag.ID3v2_4, raw: map[string]interface{}{
"TXXX": &tag.Comm{Description: "MusicBrainz Album Id", Text: "release-1"},
"TXXX_0": &tag.Comm{Description: "MusicBrainz Release Group Id", Text: "group-1\x00"},
}}},
{"mp4", stubMeta{format: tag.MP4, raw: map[string]interface{}{
"MusicBrainz Album Id": "release-1",
"MusicBrainz Release Group Id": "group-1",
}}},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
if got := ReadTagMBIDs(c.meta).ReleaseGroup; got != "group-1" {
t.Errorf("release group = %q, want group-1", got)
}
if album := ReadTagMBIDs(c.meta).Release; album != "release-1" {
t.Errorf("album (release) = %q, want release-1", album)
}
})
}
none := stubMeta{format: tag.VORBIS, raw: map[string]interface{}{"musicbrainz_albumid": "release-1"}}
if got := ReadTagMBIDs(none).ReleaseGroup; got != "" {
t.Errorf("untagged release group = %q, want empty", got)
}
}
// Each format's recording id lands in Recording, and the release-track
// id never does. Picard calls the recording MUSICBRAINZ_TRACKID in Vorbis
// comments, the name mbz gives the release track.
func TestReadTagMBIDs_Recording(t *testing.T) {
cases := []struct {
name string
meta stubMeta
}{
{"vorbis", stubMeta{format: tag.VORBIS, raw: map[string]interface{}{
"musicbrainz_trackid": "rec-1",
"musicbrainz_releasetrackid": "reltrack-1",
}}},
{"id3v2 ufid", stubMeta{format: tag.ID3v2_4, raw: map[string]interface{}{
"TXXX": txxx("MusicBrainz Album Id", "rel-1\x00"),
"TXXX_0": txxx("MusicBrainz Artist Id", "ar-1"),
"TXXX_1": txxx("MusicBrainz Album Artist Id", "aa-1\x00"),
"TXXX_2": txxx("MusicBrainz Release Group Id", "rg-1\x00"),
"TXXX_3": txxx("MusicBrainz Release Track Id", "reltrack-1\x00"),
"UFID": &tag.UFID{Provider: "http://musicbrainz.org", Identifier: []byte("rec-1")},
"TXXX_0": &tag.Comm{Description: "MusicBrainz Release Track Id", Text: "reltrack-1\x00"},
}}},
}}, all},
{"mp4", stubMeta{format: tag.MP4, raw: map[string]interface{}{
"MusicBrainz Track Id": "rec-1",
"MusicBrainz Release Track Id": "reltrack-1",
}}},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
if got := ReadTagMBIDs(c.meta).Recording; got != "rec-1" {
t.Errorf("recording = %q, want rec-1", got)
"MusicBrainz Album Id": "rel-1", "MusicBrainz Artist Id": "ar-1", "MusicBrainz Album Artist Id": "aa-1",
"MusicBrainz Release Group Id": "rg-1", "MusicBrainz Track Id": "rec-1", "MusicBrainz Release Track Id": "reltrack-1",
}}, all},
{"untagged", stubMeta{format: tag.VORBIS, raw: map[string]interface{}{}}, TagMBIDs{}},
// dhowden never produces uppercase Vorbis keys; a lookup by the
// uppercase name would find nothing in a real file.
{"uppercase vorbis keys", stubMeta{format: tag.VORBIS, raw: map[string]interface{}{
"MUSICBRAINZ_ALBUMID": "wrong-case", "MUSICBRAINZ_ARTISTID": "wrong-case",
}}, TagMBIDs{}},
{"a vorbis release track is not a recording", stubMeta{format: tag.VORBIS, raw: map[string]interface{}{
"musicbrainz_releasetrackid": "reltrack-1",
}}, TagMBIDs{}},
// Some Picard configs write collaborations NUL-separated; Minstrel
// uses the primary artist, so the first value wins.
{"id3 multi-value takes the first", stubMeta{format: tag.ID3v2_4, raw: map[string]interface{}{
"TXXX": txxx("MusicBrainz Artist Id", "primary-mbid\x00collab-mbid"),
}}, TagMBIDs{Artist: "primary-mbid"}},
// A value that is only NULs is absent, not a NUL string for Postgres.
{"id3 value of only NULs", stubMeta{format: tag.ID3v2_4, raw: map[string]interface{}{
"TXXX": txxx("MusicBrainz Album Id", "\x00\x00"),
}}, TagMBIDs{}},
} {
t.Run(tc.name, func(t *testing.T) {
if got := ReadTagMBIDs(tc.meta); got != tc.want {
t.Errorf("got %+v\nwant %+v", got, tc.want)
}
})
}
// A Vorbis file carrying only the release-track id has no recording id.
only := stubMeta{format: tag.VORBIS, raw: map[string]interface{}{"musicbrainz_releasetrackid": "reltrack-1"}}
if got := ReadTagMBIDs(only).Recording; got != "" {
t.Errorf("release track only: recording = %q, want empty", got)
}
}
// A Vorbis TRACKNUMBER of "3/20" is track 3: dhowden/tag reads it as 0.
@@ -259,32 +109,3 @@ func TestReadTrackAndDisc(t *testing.T) {
}
}
}
// The album artist's id is read from each format's Picard name.
func TestReadTagMBIDs_AlbumArtist(t *testing.T) {
cases := []struct {
name string
meta stubMeta
}{
{"vorbis", stubMeta{format: tag.VORBIS, raw: map[string]interface{}{
"musicbrainz_albumartistid": "aa-1",
"musicbrainz_artistid": "ar-1",
}}},
{"id3v2", stubMeta{format: tag.ID3v2_4, raw: map[string]interface{}{
"TXXX": &tag.Comm{Description: "MusicBrainz Album Artist Id", Text: "aa-1\x00"},
"TXXX_0": &tag.Comm{Description: "MusicBrainz Artist Id", Text: "ar-1"},
}}},
{"mp4", stubMeta{format: tag.MP4, raw: map[string]interface{}{
"MusicBrainz Album Artist Id": "aa-1",
"MusicBrainz Artist Id": "ar-1",
}}},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
ids := ReadTagMBIDs(c.meta)
if ids.AlbumArtist != "aa-1" || ids.Artist != "ar-1" {
t.Errorf("album artist = %q, artist = %q; want aa-1 and ar-1", ids.AlbumArtist, ids.Artist)
}
})
}
}