fix(library): the duplicate resolver never removes a file on its own (#8252)
release / go (push) Successful in 2m28s
release / web (push) Successful in 1m42s
release / govulncheck (push) Successful in 23s
release / integration (push) Successful in 5m9s
release / android (push) Successful in 5m28s
release / Build signed APK (push) Successful in 5m54s
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 34s
release / Verify release artifacts (tag releases only) (push) Skipped

Other programs file music into the library now, and a startup pass
deleted a whole album a download manager had just filed, keeping older
loose copies of the same songs. The resolver assumed Minstrel was the
only program writing the library; it is not.

An automatic pass now changes only Minstrel's database:
- copies of one song, on one album or across releases, are linked as one
  song, so likes, plays and mixes count it once, and any group an admin
  may want to thin stays pending for review (and is announced);
- distinct versions are still dismissed, and rips still held back;
- a one-album wrong slot gets a note naming the song MusicBrainz or
  AcoustID says the recording is, for the admin who settles it.

Removing a copy is an admin's merge or wrong-slot settle, as before. When
an admin merges, a copy in a folder named for its album ("Album (Year)",
or its "CD nn" folder) now outranks a loose copy of the same audio.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 21:09:11 -05:00
co-authored by Claude Opus 5.5
parent 63af193b13
commit 677a421675
16 changed files with 330 additions and 462 deletions
+15 -15
View File
@@ -80,7 +80,7 @@ func TestCrossReleaseCopiesCountAsOneSong_Integration(t *testing.T) {
q := dbq.New(pool)
f := newSongLinkFixture(t, pool)
res, err := ResolveDuplicates(ctx, pool, nil, "", true)
res, err := ResolveDuplicates(ctx, pool, nil, true)
if err != nil {
t.Fatal(err)
}
@@ -111,7 +111,7 @@ func TestCrossReleaseCopiesCountAsOneSong_Integration(t *testing.T) {
}
// A second pass changes nothing.
if res, err := ResolveDuplicates(ctx, pool, nil, "", true); err != nil || res.SongsLinked != 0 {
if res, err := ResolveDuplicates(ctx, pool, nil, true); err != nil || res.SongsLinked != 0 {
t.Errorf("second pass linked %d (%v), want 0", res.SongsLinked, err)
}
@@ -148,7 +148,7 @@ func TestCrossReleaseLinkNeedsAutoResolve_Integration(t *testing.T) {
ctx := context.Background()
q := dbq.New(pool)
f := newSongLinkFixture(t, pool)
if _, err := ResolveDuplicates(ctx, pool, nil, "", false); err != nil {
if _, err := ResolveDuplicates(ctx, pool, nil, false); err != nil {
t.Fatal(err)
}
keys := songKeys(t, q, f.single.ID, f.albumCut.ID)
@@ -213,10 +213,10 @@ func songKeys(t *testing.T, q *dbq.Queries, ids ...pgtype.UUID) []pgtype.UUID {
}
// A cross-release group whose album holds the song twice (Mammalz: Neptunez
// Barz as a FLAC and a YouTube mp3, beside the single): the album's
// extra copy is merged into its FLAC, the single stays, and the two copies
// left are linked as one song.
func TestResolveDuplicates_FoldsAnAlbumsExtraCopyInACrossReleaseGroup_Integration(t *testing.T) {
// Barz as a FLAC and an mp3, beside the single): every file stays, since
// another program may have filed any of them, and all three count as one
// song. Thinning the album's copies is an admin's merge.
func TestResolveDuplicates_KeepsEveryCopyInACrossReleaseGroup_Integration(t *testing.T) {
pool := dbtest.Pool(t)
ctx := context.Background()
q := dbq.New(pool)
@@ -267,18 +267,18 @@ func TestResolveDuplicates_FoldsAnAlbumsExtraCopyInACrossReleaseGroup_Integratio
t.Fatal(err)
}
res, err := ResolveDuplicates(ctx, pool, nil, "", true)
res, err := ResolveDuplicates(ctx, pool, nil, true)
if err != nil {
t.Fatal(err)
}
if res.Merged != 1 || exists(mp3.FilePath) || !exists(flac.FilePath) || !exists(single.FilePath) {
t.Fatalf("result %+v, mp3 %v flac %v single %v; want only the album's mp3 merged away",
res, exists(mp3.FilePath), exists(flac.FilePath), exists(single.FilePath))
}
if _, err := q.GetTrackByID(ctx, mp3.ID); err == nil {
t.Error("the album's extra copy is still a track")
if !exists(mp3.FilePath) || !exists(flac.FilePath) || !exists(single.FilePath) {
t.Fatalf("mp3 %v flac %v single %v; want every file left in place",
exists(mp3.FilePath), exists(flac.FilePath), exists(single.FilePath))
}
if res.SongsLinked != 1 {
t.Errorf("songs linked = %d, want the FLAC and the single linked as one song", res.SongsLinked)
t.Errorf("songs linked = %d, want the group linked as one song", res.SongsLinked)
}
if keys := songKeys(t, q, flac.ID, mp3.ID, single.ID); keys[0] != keys[1] || keys[1] != keys[2] {
t.Errorf("song keys %v, want all three copies one song", keys)
}
}