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
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:
@@ -6,6 +6,7 @@ import (
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
@@ -95,39 +96,39 @@ func autoMergeAudit(t *testing.T, pool *pgxpool.Pool, groupID pgtype.UUID) (n in
|
||||
return n, reason
|
||||
}
|
||||
|
||||
// One album holding a song twice: the extra copy goes, the copy whose name and
|
||||
// tags fit the album stays, and the merge is recorded as the resolver's:
|
||||
// Minstrel is the only program writing the library.
|
||||
func TestResolveDuplicates_MergesASameReleaseCopy_Integration(t *testing.T) {
|
||||
// One album holding a song twice: the pass removes neither file, since
|
||||
// another program may have filed either. It links the copies as one song and
|
||||
// leaves the group for an admin to merge.
|
||||
func TestResolveDuplicates_LinksASameReleaseCopyAndRemovesNothing_Integration(t *testing.T) {
|
||||
f := newResolveFixture(t)
|
||||
res, err := ResolveDuplicates(context.Background(), f.pool, nil, "", true)
|
||||
res, err := ResolveDuplicates(context.Background(), f.pool, nil, true)
|
||||
if err != nil {
|
||||
t.Fatalf("resolve: %v", err)
|
||||
}
|
||||
if res.Merged != 1 || res.Classes[ClassSameRelease] != 1 {
|
||||
t.Fatalf("result = %+v, want the same-release group merged", res)
|
||||
if res.Classes[ClassSameRelease] != 1 || res.SongsLinked != 1 {
|
||||
t.Fatalf("result = %+v, want the same-release group linked as one song", res)
|
||||
}
|
||||
if exists(f.ripPath) || !exists(f.cleanPath) {
|
||||
t.Errorf("rip exists=%v clean exists=%v; want only the clean copy left", exists(f.ripPath), exists(f.cleanPath))
|
||||
if !exists(f.ripPath) || !exists(f.cleanPath) {
|
||||
t.Errorf("rip exists=%v clean exists=%v; want both files left in place", exists(f.ripPath), exists(f.cleanPath))
|
||||
}
|
||||
status, class, _, auto := f.group(t)
|
||||
if status != "merged" || class == nil || *class != string(ClassSameRelease) || !auto {
|
||||
t.Errorf("group = (%s, %v, auto=%v), want merged same_release by the resolver", status, class, auto)
|
||||
status, class, note, auto := f.group(t)
|
||||
if status != "pending" || class == nil || *class != string(ClassSameRelease) || auto || note == nil {
|
||||
t.Errorf("group = (%s, %v, note %v, auto=%v), want a pending same_release group with a note", status, class, note, auto)
|
||||
}
|
||||
if n, _ := autoMergeAudit(t, f.pool, f.groupID); n != 1 {
|
||||
t.Errorf("automatic merge audit rows = %d, want 1", n)
|
||||
if n, _ := autoMergeAudit(t, f.pool, f.groupID); n != 0 {
|
||||
t.Errorf("automatic merge audit rows = %d, want none", n)
|
||||
}
|
||||
}
|
||||
|
||||
// With auto-resolve off, the pass classifies and removes nothing.
|
||||
func TestResolveDuplicates_ClassifiesOnlyWithoutPermission_Integration(t *testing.T) {
|
||||
f := newResolveFixture(t)
|
||||
res, err := ResolveDuplicates(context.Background(), f.pool, nil, "", false)
|
||||
res, err := ResolveDuplicates(context.Background(), f.pool, nil, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if res.Merged != 0 || !exists(f.ripPath) {
|
||||
t.Errorf("merged %d", res.Merged)
|
||||
if res.SongsLinked != 0 || !exists(f.ripPath) || !exists(f.cleanPath) {
|
||||
t.Errorf("result %+v; want nothing linked or removed", res)
|
||||
}
|
||||
status, class, _, _ := f.group(t)
|
||||
if status != "pending" || class == nil || *class != string(ClassSameRelease) {
|
||||
@@ -193,22 +194,26 @@ func newCrossReleaseRipFixture(t *testing.T) crossReleaseRipFixture {
|
||||
return f
|
||||
}
|
||||
|
||||
// A video rip on one release with the clean copy on another: the rip is no
|
||||
// release's copy, so it goes and the album cut stays.
|
||||
func TestResolveDuplicates_MergesARipAcrossReleases_Integration(t *testing.T) {
|
||||
// A video rip on one release with the clean copy on another: both files stay,
|
||||
// the copies count as one song, and the group waits for an admin to remove
|
||||
// the rip.
|
||||
func TestResolveDuplicates_LinksARipAcrossReleasesAndRemovesNothing_Integration(t *testing.T) {
|
||||
f := newCrossReleaseRipFixture(t)
|
||||
res, err := ResolveDuplicates(context.Background(), f.pool, nil, "", true)
|
||||
res, err := ResolveDuplicates(context.Background(), f.pool, nil, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if res.Classes[ClassCrossRelease] != 1 || res.Merged != 1 {
|
||||
t.Fatalf("classes %v, merged %d; want the cross-release group merged", res.Classes, res.Merged)
|
||||
if res.Classes[ClassCrossRelease] != 1 || res.SongsLinked != 1 {
|
||||
t.Fatalf("result %+v; want the cross-release group linked as one song", res)
|
||||
}
|
||||
if exists(f.ripPath) || !exists(f.cleanPath) {
|
||||
t.Errorf("rip exists %v, clean exists %v; want only the clean copy", exists(f.ripPath), exists(f.cleanPath))
|
||||
if !exists(f.ripPath) || !exists(f.cleanPath) {
|
||||
t.Errorf("rip exists %v, clean exists %v; want both files left in place", exists(f.ripPath), exists(f.cleanPath))
|
||||
}
|
||||
if _, reason := autoMergeAudit(t, f.pool, f.groupID); reason != "the copy that is not a video rip" {
|
||||
t.Errorf("survivor reason %q, want the rip rule", reason)
|
||||
if status, _, _, _ := (resolveFixture{pool: f.pool, groupID: f.groupID}).group(t); status != "pending" {
|
||||
t.Errorf("group = %s, want pending for an admin", status)
|
||||
}
|
||||
if n, _ := autoMergeAudit(t, f.pool, f.groupID); n != 0 {
|
||||
t.Errorf("automatic merge audit rows = %d, want none", n)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,12 +236,12 @@ func TestResolveDuplicates_KeepsCleanCopiesOnTwoReleases_Integration(t *testing.
|
||||
if _, err := f.pool.Exec(context.Background(), sql, args...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
res, err := ResolveDuplicates(context.Background(), f.pool, nil, "", true)
|
||||
res, err := ResolveDuplicates(context.Background(), f.pool, nil, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if res.Merged != 0 || !exists(f.ripPath) {
|
||||
t.Errorf("merged %d; want both copies kept", res.Merged)
|
||||
if !exists(f.ripPath) || !exists(f.cleanPath) {
|
||||
t.Errorf("result %+v; want both copies kept", res)
|
||||
}
|
||||
if res.SongsLinked != 1 {
|
||||
t.Errorf("linked %d, want the pair linked as one song", res.SongsLinked)
|
||||
@@ -258,12 +263,12 @@ func TestResolveDuplicates_LinksOneRecordingUnderTwoTitles_Integration(t *testin
|
||||
f.rip.ID, filepath.Join(filepath.Dir(f.ripPath), "01 - DARE.mp3")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
res, err := ResolveDuplicates(ctx, f.pool, nil, "", true)
|
||||
res, err := ResolveDuplicates(ctx, f.pool, nil, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if res.Classes[ClassCrossRelease] != 1 || res.Merged != 0 || res.SongsLinked != 1 {
|
||||
t.Fatalf("classes %v, merged %d, linked %d; want the pair linked and kept", res.Classes, res.Merged, res.SongsLinked)
|
||||
if res.Classes[ClassCrossRelease] != 1 || res.SongsLinked != 1 || !exists(f.ripPath) || !exists(f.cleanPath) {
|
||||
t.Fatalf("result %+v; want the pair linked and kept", res)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,11 +338,11 @@ func auditCount(t *testing.T, pool *pgxpool.Pool, action string, groupID pgtype.
|
||||
// the group is dismissed and both files stay.
|
||||
func TestResolveDuplicates_DismissesTwoVersionsOfASong_Integration(t *testing.T) {
|
||||
f := newOneAlbumFixture(t, "acoustic", "Homesick", "Homesick (Instrumental)")
|
||||
res, err := ResolveDuplicates(context.Background(), f.pool, nil, "", true)
|
||||
res, err := ResolveDuplicates(context.Background(), f.pool, nil, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if res.Dismissed != 1 || res.Merged != 0 || !exists(f.aPath) || !exists(f.bPath) {
|
||||
if res.Dismissed != 1 || !exists(f.aPath) || !exists(f.bPath) {
|
||||
t.Fatalf("result %+v; want the group dismissed and both files kept", res)
|
||||
}
|
||||
if status, _, _, auto := (resolveFixture{pool: f.pool, groupID: f.groupID}).group(t); status != "dismissed" || !auto {
|
||||
@@ -378,10 +383,32 @@ func seedTrackList(t *testing.T, pool *pgxpool.Pool, album dbq.Album, songs map[
|
||||
}
|
||||
}
|
||||
|
||||
// noteOf is a group's resolve note, or "" when it has none.
|
||||
func noteOf(t *testing.T, pool *pgxpool.Pool, groupID pgtype.UUID) string {
|
||||
t.Helper()
|
||||
_, _, note, _ := (resolveFixture{pool: pool, groupID: groupID}).group(t)
|
||||
if note == nil {
|
||||
return ""
|
||||
}
|
||||
return *note
|
||||
}
|
||||
|
||||
// settleKeeping settles a wrong slot as an admin would, keeping the copy at
|
||||
// keep.
|
||||
func settleKeeping(t *testing.T, f oneAlbumFixture, keep pgtype.UUID) WrongSlotResult {
|
||||
t.Helper()
|
||||
res, err := SettleWrongSlot(context.Background(), f.pool, nil, f.groupID, keep, pgtype.UUID{})
|
||||
if err != nil {
|
||||
t.Fatalf("settle: %v", err)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// One recording in two slots of an album: MusicBrainz says Void is as long as
|
||||
// the file and Reach is a minute longer, so the copy in Reach's slot goes. Its
|
||||
// track stays, marked missing, until a good copy arrives.
|
||||
func TestResolveDuplicates_RemovesACopyFromAnotherSongsSlot_Integration(t *testing.T) {
|
||||
// the file and Reach is a minute longer. The pass removes nothing; it names
|
||||
// Void in the group's note. Settled with that copy, the copy in Reach's slot
|
||||
// goes, and its track stays, marked missing, until a good copy arrives.
|
||||
func TestResolveDuplicates_NamesTheSongOfACopyInAnotherSongsSlot_Integration(t *testing.T) {
|
||||
f := newOneAlbumFixture(t, "acoustic", "Void", "Reach")
|
||||
seedTrackList(t, f.pool, f.album, map[string]int{"Void": 220500, "Reach": 281000})
|
||||
// The wrong file is Void's recording, so it carries Void's MBID.
|
||||
@@ -389,18 +416,25 @@ func TestResolveDuplicates_RemovesACopyFromAnotherSongsSlot_Integration(t *testi
|
||||
`UPDATE tracks SET mbid = 'rec-void', mbid_source = 'tag' WHERE id = ANY($1)`, []pgtype.UUID{f.a.ID, f.b.ID}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
res, err := ResolveDuplicates(context.Background(), f.pool, nil, "", true)
|
||||
res, err := ResolveDuplicates(context.Background(), f.pool, nil, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if res.SlotsNamed != 1 || !exists(f.aPath) || !exists(f.bPath) {
|
||||
t.Fatalf("result %+v, void exists %v, reach exists %v; want Void named and both files kept",
|
||||
res, exists(f.aPath), exists(f.bPath))
|
||||
}
|
||||
if note := noteOf(t, f.pool, f.groupID); !strings.Contains(note, "\u201cVoid\u201d") {
|
||||
t.Errorf("note %q, want it to name Void", note)
|
||||
}
|
||||
settleKeeping(t, f, f.a.ID)
|
||||
// Folded by that MBID into the copy kept, the slot would never be wanted
|
||||
// back.
|
||||
if pairs, err := PairMissingTracks(context.Background(), f.pool, nil); err != nil || pairs.Folded() != 0 {
|
||||
t.Fatalf("missing-pair pass = %+v, %v; want the emptied slot left alone", pairs, err)
|
||||
}
|
||||
if res.WrongFiles != 1 || !exists(f.aPath) || exists(f.bPath) {
|
||||
t.Fatalf("result %+v, void exists %v, reach exists %v; want only Reach's copy removed",
|
||||
res, exists(f.aPath), exists(f.bPath))
|
||||
if !exists(f.aPath) || exists(f.bPath) {
|
||||
t.Fatalf("void exists %v, reach exists %v; want only Reach's copy removed", exists(f.aPath), exists(f.bPath))
|
||||
}
|
||||
var missing bool
|
||||
if err := f.pool.QueryRow(context.Background(),
|
||||
@@ -410,8 +444,8 @@ func TestResolveDuplicates_RemovesACopyFromAnotherSongsSlot_Integration(t *testi
|
||||
if !missing {
|
||||
t.Error("Reach's track is not marked missing, so nothing will fetch it again")
|
||||
}
|
||||
if status, _, _, auto := (resolveFixture{pool: f.pool, groupID: f.groupID}).group(t); status != "merged" || !auto {
|
||||
t.Errorf("group = (%s, auto=%v), want settled by the resolver", status, auto)
|
||||
if status, _, _, _ := (resolveFixture{pool: f.pool, groupID: f.groupID}).group(t); status != "merged" {
|
||||
t.Errorf("group = %s, want settled", status)
|
||||
}
|
||||
if n := auditCount(t, f.pool, "duplicate_wrong_file", f.groupID); n != 1 {
|
||||
t.Errorf("wrong-file audit rows = %d, want 1", n)
|
||||
@@ -446,9 +480,8 @@ func TestResolveDuplicates_EmptiedSlotFoldsOnlyIntoItsOwnSong_Integration(t *tes
|
||||
}
|
||||
}
|
||||
held("17 - Reach (other edition).m4a", tc.heldMs)
|
||||
res, err := ResolveDuplicates(ctx, f.pool, nil, "", true)
|
||||
if err != nil || res.WrongFiles != 1 {
|
||||
t.Fatalf("resolve = %+v, %v; want Reach's slot emptied", res, err)
|
||||
if res := settleKeeping(t, f, f.a.ID); len(res.Removed) != 1 {
|
||||
t.Fatalf("settle = %+v; want Reach's slot emptied", res)
|
||||
}
|
||||
pairs, err := PairMissingTracks(ctx, f.pool, nil)
|
||||
if err != nil || pairs.Folded() != tc.foldsFirst {
|
||||
@@ -466,23 +499,24 @@ func TestResolveDuplicates_EmptiedSlotFoldsOnlyIntoItsOwnSong_Integration(t *tes
|
||||
}
|
||||
|
||||
// One recording filling two slots whose songs are both clearly something else
|
||||
// (Shnorkelbub's whole album in one file): both copies go, nothing is kept.
|
||||
func TestResolveDuplicates_RemovesEveryCopyWhenNoSlotIsTheirs_Integration(t *testing.T) {
|
||||
// (Shnorkelbub's whole album in one file): the note says it is neither song,
|
||||
// and both files stay until an admin settles it.
|
||||
func TestResolveDuplicates_SaysWhenNoSlotIsTheRecordings_Integration(t *testing.T) {
|
||||
f := newOneAlbumFixture(t, "acoustic", "Void", "Reach")
|
||||
seedTrackList(t, f.pool, f.album, map[string]int{"Void": 282000, "Reach": 421000})
|
||||
res, err := ResolveDuplicates(context.Background(), f.pool, nil, "", true)
|
||||
res, err := ResolveDuplicates(context.Background(), f.pool, nil, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if res.WrongFiles != 2 || exists(f.aPath) || exists(f.bPath) {
|
||||
t.Fatalf("result %+v, void exists %v, reach exists %v; want both copies removed",
|
||||
if res.SlotsNamed != 1 || !exists(f.aPath) || !exists(f.bPath) {
|
||||
t.Fatalf("result %+v, void exists %v, reach exists %v; want it named and both files kept",
|
||||
res, exists(f.aPath), exists(f.bPath))
|
||||
}
|
||||
if status, _, _, auto := (resolveFixture{pool: f.pool, groupID: f.groupID}).group(t); status != "merged" || !auto {
|
||||
t.Errorf("group = (%s, auto=%v), want settled by the resolver", status, auto)
|
||||
if note := noteOf(t, f.pool, f.groupID); !strings.Contains(note, "none of these songs") {
|
||||
t.Errorf("note %q, want it to say the recording is neither song", note)
|
||||
}
|
||||
if n := auditCount(t, f.pool, "duplicate_wrong_file", f.groupID); n != 1 {
|
||||
t.Errorf("wrong-file audit rows = %d, want 1", n)
|
||||
if status, _, _, _ := (resolveFixture{pool: f.pool, groupID: f.groupID}).group(t); status != "pending" {
|
||||
t.Errorf("group = %s, want pending for an admin", status)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -502,9 +536,9 @@ func seedTrimmedAlbum(t *testing.T) oneAlbumFixture {
|
||||
return f
|
||||
}
|
||||
|
||||
// AcoustID matched one copy to Tormentor's recording: that copy stays and
|
||||
// Record Shop's goes.
|
||||
func TestResolveDuplicates_KeepsTheCopyAcoustIDNames_Integration(t *testing.T) {
|
||||
// AcoustID matched one copy to Tormentor's recording: the note names
|
||||
// Tormentor, and both files stay.
|
||||
func TestResolveDuplicates_NamesTheCopyAcoustIDNames_Integration(t *testing.T) {
|
||||
f := seedTrimmedAlbum(t)
|
||||
if _, err := f.pool.Exec(context.Background(),
|
||||
`INSERT INTO track_acoustid_lookups (track_id, state, candidates, recording_mbid) VALUES ($1, 'matched', 1, 'rec-tormentor')`,
|
||||
@@ -512,7 +546,7 @@ func TestResolveDuplicates_KeepsTheCopyAcoustIDNames_Integration(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
asked := 0
|
||||
res, err := ResolveDuplicatesWith(context.Background(), f.pool, nil, "", true, ResolveSources{
|
||||
res, err := ResolveDuplicatesWith(context.Background(), f.pool, nil, true, ResolveSources{
|
||||
Identify: func(context.Context, string) ([]string, error) { asked++; return nil, nil },
|
||||
})
|
||||
if err != nil {
|
||||
@@ -521,10 +555,13 @@ func TestResolveDuplicates_KeepsTheCopyAcoustIDNames_Integration(t *testing.T) {
|
||||
if asked != 0 {
|
||||
t.Errorf("AcoustID asked %d times; the copy's own lookup already answered", asked)
|
||||
}
|
||||
if res.WrongFiles != 1 || !exists(f.aPath) || exists(f.bPath) {
|
||||
t.Fatalf("result %+v, tormentor exists %v, record shop exists %v; want only Record Shop's copy removed",
|
||||
if res.SlotsNamed != 1 || !exists(f.aPath) || !exists(f.bPath) {
|
||||
t.Fatalf("result %+v, tormentor exists %v, record shop exists %v; want Tormentor named and both kept",
|
||||
res, exists(f.aPath), exists(f.bPath))
|
||||
}
|
||||
if note := noteOf(t, f.pool, f.groupID); !strings.Contains(note, "AcoustID says") || !strings.Contains(note, "Tormentor") {
|
||||
t.Errorf("note %q, want AcoustID's answer naming Tormentor", note)
|
||||
}
|
||||
}
|
||||
|
||||
// Copies whose own lookups all name Record Shop's recording are that
|
||||
@@ -552,39 +589,43 @@ func TestResolveDuplicates_AgreeingLookupsDecideAnAcousticGroup_Integration(t *t
|
||||
f.a.ID, f.b.ID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
res, err := ResolveDuplicates(context.Background(), f.pool, nil, "", true)
|
||||
res, err := ResolveDuplicates(context.Background(), f.pool, nil, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if res.WrongFiles != 1 || exists(f.aPath) || !exists(f.bPath) {
|
||||
t.Fatalf("result %+v, tormentor exists %v, record shop exists %v; want only Tormentor's copy removed",
|
||||
if res.SlotsNamed != 1 || !exists(f.aPath) || !exists(f.bPath) {
|
||||
t.Fatalf("result %+v, tormentor exists %v, record shop exists %v; want Record Shop named and both kept",
|
||||
res, exists(f.aPath), exists(f.bPath))
|
||||
}
|
||||
if note := noteOf(t, f.pool, f.groupID); !strings.Contains(note, "Record Shop") {
|
||||
t.Errorf("note %q, want it to name Record Shop", note)
|
||||
}
|
||||
})
|
||||
t.Run("unknown", func(t *testing.T) {
|
||||
f := setup(t)
|
||||
asked := 0
|
||||
res, err := ResolveDuplicatesWith(context.Background(), f.pool, nil, "", true, ResolveSources{
|
||||
res, err := ResolveDuplicatesWith(context.Background(), f.pool, nil, true, ResolveSources{
|
||||
Identify: func(context.Context, string) ([]string, error) { asked++; return nil, nil },
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if asked != 0 || res.WrongFiles != 0 || !exists(f.aPath) || !exists(f.bPath) {
|
||||
t.Fatalf("asked %d, result %+v; want nothing asked or removed for copies that may be two takes", asked, res)
|
||||
if asked != 0 || res.SlotsNamed != 0 || !exists(f.aPath) || !exists(f.bPath) {
|
||||
t.Fatalf("asked %d, result %+v; want nothing asked or named for copies that may be two takes", asked, res)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// A pass while a scan is walking the library waits for it: a copy removed
|
||||
// under the walk is marked present again when the scan reconciles. A run
|
||||
// stuck past StuckScanThreshold does not hold the resolver up. Files being
|
||||
// A pass while a scan is walking the library waits for it: a pass deciding
|
||||
// from tracks the scan is still rewriting would decide from a library
|
||||
// half-read. A run stuck past StuckScanThreshold does not hold the resolver
|
||||
// up. Files being
|
||||
// read with no run recorded (a scan whose run row hasn't landed yet, a
|
||||
// watcher batch) hold it up as well.
|
||||
func TestDuplicateResolveWorker_WaitsForARunningScan_Integration(t *testing.T) {
|
||||
f := seedTrimmedAlbum(t)
|
||||
ctx := context.Background()
|
||||
w := NewDuplicateResolveWorker(f.pool, slog.New(slog.NewTextHandler(io.Discard, nil)), "", nil, ResolveSources{})
|
||||
w := NewDuplicateResolveWorker(f.pool, slog.New(slog.NewTextHandler(io.Discard, nil)), nil, ResolveSources{})
|
||||
if _, err := f.pool.Exec(ctx, `INSERT INTO scan_runs DEFAULT VALUES`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -617,13 +658,13 @@ func TestDuplicateResolveWorker_WaitsForARunningScan_Integration(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// AcoustID knows the recording as no song of the album: every copy goes. With
|
||||
// AcoustID unreachable, nothing is decided and the group waits.
|
||||
// AcoustID knows the recording as no song of the album: the note says so. With
|
||||
// AcoustID unreachable, nothing is decided. Either way the group waits.
|
||||
func TestResolveDuplicates_TrimmedCopiesAcoustIDCannotName_Integration(t *testing.T) {
|
||||
t.Run("no match", func(t *testing.T) {
|
||||
f := seedTrimmedAlbum(t)
|
||||
asked := 0
|
||||
res, err := ResolveDuplicatesWith(context.Background(), f.pool, nil, "", true, ResolveSources{
|
||||
res, err := ResolveDuplicatesWith(context.Background(), f.pool, nil, true, ResolveSources{
|
||||
Identify: func(context.Context, string) ([]string, error) {
|
||||
asked++
|
||||
return []string{"rec-elsewhere"}, nil
|
||||
@@ -632,23 +673,26 @@ func TestResolveDuplicates_TrimmedCopiesAcoustIDCannotName_Integration(t *testin
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if asked != 1 || res.WrongFiles != 2 || exists(f.aPath) || exists(f.bPath) {
|
||||
t.Fatalf("asked %d, result %+v; want one lookup and both copies removed", asked, res)
|
||||
if asked != 1 || res.SlotsNamed != 1 || !exists(f.aPath) || !exists(f.bPath) {
|
||||
t.Fatalf("asked %d, result %+v; want one lookup, the slot named and both files kept", asked, res)
|
||||
}
|
||||
if status, _, _, _ := (resolveFixture{pool: f.pool, groupID: f.groupID}).group(t); status != "merged" {
|
||||
t.Errorf("group = %s, want settled", status)
|
||||
if note := noteOf(t, f.pool, f.groupID); !strings.Contains(note, "none of these songs") {
|
||||
t.Errorf("note %q, want it to say the recording is neither song", note)
|
||||
}
|
||||
if status, _, _, _ := (resolveFixture{pool: f.pool, groupID: f.groupID}).group(t); status != "pending" {
|
||||
t.Errorf("group = %s, want pending", status)
|
||||
}
|
||||
})
|
||||
t.Run("unreachable", func(t *testing.T) {
|
||||
f := seedTrimmedAlbum(t)
|
||||
res, err := ResolveDuplicatesWith(context.Background(), f.pool, nil, "", true, ResolveSources{
|
||||
res, err := ResolveDuplicatesWith(context.Background(), f.pool, nil, true, ResolveSources{
|
||||
Identify: func(context.Context, string) ([]string, error) { return nil, ErrIdentifyUnavailable },
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if res.WrongFiles != 0 || !exists(f.aPath) || !exists(f.bPath) {
|
||||
t.Fatalf("result %+v; want nothing removed while AcoustID cannot answer", res)
|
||||
if res.SlotsNamed != 0 || !exists(f.aPath) || !exists(f.bPath) {
|
||||
t.Fatalf("result %+v; want nothing named while AcoustID cannot answer", res)
|
||||
}
|
||||
if status, _, _, _ := (resolveFixture{pool: f.pool, groupID: f.groupID}).group(t); status != "pending" {
|
||||
t.Errorf("group = %s, want pending", status)
|
||||
@@ -674,17 +718,17 @@ func TestResolveDuplicates_FetchesAMissingTrackList_Integration(t *testing.T) {
|
||||
seedTrackList(t, f.pool, f.album, map[string]int{"Void": 220500, "Reach": 281000})
|
||||
return nil
|
||||
}
|
||||
res, err := ResolveDuplicatesWith(context.Background(), f.pool, nil, "", true, ResolveSources{TrackLists: fetch})
|
||||
res, err := ResolveDuplicatesWith(context.Background(), f.pool, nil, true, ResolveSources{TrackLists: fetch})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if calls != 1 || res.WrongFiles != 1 || exists(f.bPath) {
|
||||
t.Fatalf("fetches %d, result %+v; want one fetch and Reach's copy removed", calls, res)
|
||||
if calls != 1 || res.SlotsNamed != 1 || !exists(f.bPath) {
|
||||
t.Fatalf("fetches %d, result %+v; want one fetch, the slot named and Reach's copy kept", calls, res)
|
||||
}
|
||||
}
|
||||
|
||||
// With MusicBrainz track lists switched off, the resolver asks once, gets
|
||||
// ErrLookupOff, and removes nothing it can't decide without the list.
|
||||
// ErrLookupOff, and names nothing it can't decide without the list.
|
||||
func TestResolveDuplicates_TrackListsSwitchedOff_Integration(t *testing.T) {
|
||||
f := newOneAlbumFixture(t, "acoustic", "Void", "Reach")
|
||||
if _, err := f.pool.Exec(context.Background(),
|
||||
@@ -696,24 +740,24 @@ func TestResolveDuplicates_TrackListsSwitchedOff_Integration(t *testing.T) {
|
||||
calls++
|
||||
return ErrLookupOff
|
||||
}
|
||||
res, err := ResolveDuplicatesWith(context.Background(), f.pool, nil, "", true, ResolveSources{TrackLists: off})
|
||||
res, err := ResolveDuplicatesWith(context.Background(), f.pool, nil, true, ResolveSources{TrackLists: off})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if calls != 1 || res.WrongFiles != 0 || !exists(f.aPath) || !exists(f.bPath) {
|
||||
if calls != 1 || res.SlotsNamed != 0 || !exists(f.aPath) || !exists(f.bPath) {
|
||||
t.Fatalf("fetches %d, result %+v; want one refused fetch and both copies kept", calls, res)
|
||||
}
|
||||
}
|
||||
|
||||
// Without a track list that decides, nothing is removed.
|
||||
// Without a track list that decides, nothing is named.
|
||||
func TestResolveDuplicates_LeavesAnUndecidedSlotForTheOperator_Integration(t *testing.T) {
|
||||
f := newOneAlbumFixture(t, "acoustic", "Void", "Reach")
|
||||
seedTrackList(t, f.pool, f.album, map[string]int{"Void": 220500, "Reach": 221000})
|
||||
res, err := ResolveDuplicates(context.Background(), f.pool, nil, "", true)
|
||||
res, err := ResolveDuplicates(context.Background(), f.pool, nil, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if res.WrongFiles != 0 || !exists(f.aPath) || !exists(f.bPath) {
|
||||
if res.SlotsNamed != 0 || !exists(f.aPath) || !exists(f.bPath) {
|
||||
t.Fatalf("result %+v; want both copies kept when the lengths cannot tell", res)
|
||||
}
|
||||
if status, class, _, _ := (resolveFixture{pool: f.pool, groupID: f.groupID}).group(t); status != "pending" ||
|
||||
@@ -728,8 +772,7 @@ func TestResolveDuplicates_HoldsBackRips_Integration(t *testing.T) {
|
||||
f := newCrossReleaseRipFixture(t)
|
||||
ctx := context.Background()
|
||||
q := dbq.New(f.pool)
|
||||
// Without its group the rip has no clean copy to merge into, so it stays
|
||||
// on disk and only its verdict changes.
|
||||
// Without its group the rip is judged by its name alone.
|
||||
if _, err := f.pool.Exec(ctx, `DELETE FROM duplicate_groups WHERE id = $1`, f.groupID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -743,7 +786,7 @@ func TestResolveDuplicates_HoldsBackRips_Integration(t *testing.T) {
|
||||
}
|
||||
resolve := func() DuplicateResolveResult {
|
||||
t.Helper()
|
||||
res, err := ResolveDuplicates(ctx, f.pool, nil, "", true)
|
||||
res, err := ResolveDuplicates(ctx, f.pool, nil, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user