From 466c5eb1b5c1adce90fa2f3bfcc17f90f19ab542 Mon Sep 17 00:00:00 2001 From: vlad Date: Tue, 3 Nov 2026 01:36:40 +0300 Subject: [PATCH] fix: respect pinned album edition in exact Soulseek searches --- .github/workflows/selected-edition-tests.yml | 27 +++++ Tubifarry.Tests/SlskdSelectedEditionTests.cs | 100 ++++++++++++++++++ Tubifarry.Tests/Tubifarry.Tests.csproj | 15 +++ .../Soulseek/SlskdRequestGenerator.cs | 6 ++ Tubifarry/Indexers/Soulseek/SlskdSettings.cs | 4 +- 5 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/selected-edition-tests.yml create mode 100644 Tubifarry.Tests/SlskdSelectedEditionTests.cs create mode 100644 Tubifarry.Tests/Tubifarry.Tests.csproj diff --git a/.github/workflows/selected-edition-tests.yml b/.github/workflows/selected-edition-tests.yml new file mode 100644 index 00000000..f8c6d368 --- /dev/null +++ b/.github/workflows/selected-edition-tests.yml @@ -0,0 +1,27 @@ +name: Selected edition regression tests + +on: + pull_request: + paths: + - 'Tubifarry/**' + - 'Tubifarry.Tests/**' + - '.github/workflows/selected-edition-tests.yml' + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.0.x' + - run: >- + dotnet test Tubifarry.Tests/Tubifarry.Tests.csproj + --configuration Release + -p:CI=true -p:Branch=develop -p:TreatWarningsAsErrors=false diff --git a/Tubifarry.Tests/SlskdSelectedEditionTests.cs b/Tubifarry.Tests/SlskdSelectedEditionTests.cs new file mode 100644 index 00000000..b4091d86 --- /dev/null +++ b/Tubifarry.Tests/SlskdSelectedEditionTests.cs @@ -0,0 +1,100 @@ +using NLog; +using NUnit.Framework; +using NzbDrone.Core.Indexers; +using NzbDrone.Core.IndexerSearch.Definitions; +using NzbDrone.Core.Music; +using Tubifarry.Core.Telemetry; +using Tubifarry.Core.Utilities; +using Tubifarry.Indexers.Soulseek; +using Tubifarry.Indexers.Soulseek.Search.Core; + +namespace Tubifarry.Tests; + +public class SlskdSelectedEditionTests +{ + // Capture the real request generator's lazy pipeline input without starting + // a network search or depending on the internal generator type. + private sealed class CapturePipeline : ISlskdSearchChain + { + public SearchContext? Context { get; private set; } + + public LazyIndexerPageableRequestChain BuildChain(SearchContext context, SearchExecutor searchExecutor) + { + Context = context; + return new LazyIndexerPageableRequestChain(0); + } + } + + private static SearchContext Generate(bool anyReleaseOk, TrackCountFilterType filter, + int? selected, params int[] editions) + { + var pipeline = new CapturePipeline(); + var indexer = new SlskdIndexer(null!, null!, null!, pipeline, null!, null!, + null!, null!, null!, null!, new NoopSentryHelper(), LogManager.GetLogger("test")) + { + Definition = new IndexerDefinition + { + Settings = new SlskdSettings { TrackCountFilter = (int)filter } + } + }; + var releases = editions.Select(count => new AlbumRelease + { + TrackCount = count, + Monitored = count == selected, + Tracks = new List() + }).ToList(); + var album = new Album { AnyReleaseOk = anyReleaseOk, AlbumReleases = releases }; + var criteria = new AlbumSearchCriteria + { + Artist = new Artist + { + Name = "Artist", + Metadata = new ArtistMetadata { Aliases = new List() } + }, + AlbumTitle = "Album", + Albums = new List { album } + }; + + indexer.GetExtendedRequestGenerator().GetSearchRequests(criteria); + return pipeline.Context!; + } + + [TestCase(32, 12, 32)] // Deluxe bonuses must not trigger another regular CD. + [TestCase(10, 10, 20)] // An explicitly selected programme can also be shorter. + public void Exact_respects_explicitly_selected_edition(int selected, int regular, int deluxe) + { + var context = Generate(false, TrackCountFilterType.Exact, selected, regular, deluxe); + Assert.That(context.TrackCount, Is.EqualTo(selected)); + Assert.That(context.TrackCounts, Is.EqualTo(new[] { selected })); + } + + [Test] + public void Exact_keeps_all_editions_when_any_release_is_allowed() + { + var context = Generate(true, TrackCountFilterType.Exact, 32, 12, 32); + Assert.That(context.TrackCounts, Is.EqualTo(new[] { 12, 32 })); + } + + [TestCase(TrackCountFilterType.Disabled)] + [TestCase(TrackCountFilterType.Lower)] + [TestCase(TrackCountFilterType.Unfitting)] + public void Other_filters_keep_existing_edition_semantics(TrackCountFilterType filter) + { + var context = Generate(false, filter, 32, 12, 32); + Assert.That(context.TrackCounts, Is.EqualTo(new[] { 12, 32 })); + } + + [Test] + public void Missing_selected_edition_keeps_all_valid_counts() + { + var context = Generate(false, TrackCountFilterType.Exact, null, 32, 0, 12, 12); + Assert.That(context.TrackCounts, Is.EqualTo(new[] { 12, 32 })); + } + + [Test] + public void Invalid_selected_count_does_not_filter_everything_out() + { + var context = Generate(false, TrackCountFilterType.Exact, 0, 0, 12, 32); + Assert.That(context.TrackCounts, Is.EqualTo(new[] { 12, 32 })); + } +} diff --git a/Tubifarry.Tests/Tubifarry.Tests.csproj b/Tubifarry.Tests/Tubifarry.Tests.csproj new file mode 100644 index 00000000..fd3a467c --- /dev/null +++ b/Tubifarry.Tests/Tubifarry.Tests.csproj @@ -0,0 +1,15 @@ + + + net8.0 + enable + enable + false + true + + + + + + + + diff --git a/Tubifarry/Indexers/Soulseek/SlskdRequestGenerator.cs b/Tubifarry/Indexers/Soulseek/SlskdRequestGenerator.cs index fca6bc76..c5d62079 100644 --- a/Tubifarry/Indexers/Soulseek/SlskdRequestGenerator.cs +++ b/Tubifarry/Indexers/Soulseek/SlskdRequestGenerator.cs @@ -58,6 +58,12 @@ public IndexerPageableRequestChain GetSearchRequests List tracks = trackList?.Select(x => x.Title).ToList() ?? []; List trackDurations = trackList?.Where(t => t.Duration > 0).Select(t => t.Duration).ToList() ?? []; List trackCounts = albumReleases?.Select(r => r.TrackCount).Where(c => c > 0).Distinct().Order().ToList() ?? []; + if ((TrackCountFilterType)Settings.TrackCountFilter == TrackCountFilterType.Exact + && album?.AnyReleaseOk == false && monitoredRelease?.TrackCount > 0) + { + trackCounts = [monitoredRelease.TrackCount]; + } + if (trackCounts.Count == 0 && trackCount > 0) trackCounts = [trackCount]; diff --git a/Tubifarry/Indexers/Soulseek/SlskdSettings.cs b/Tubifarry/Indexers/Soulseek/SlskdSettings.cs index d04e100b..472d95f9 100644 --- a/Tubifarry/Indexers/Soulseek/SlskdSettings.cs +++ b/Tubifarry/Indexers/Soulseek/SlskdSettings.cs @@ -209,7 +209,7 @@ public enum TrackCountFilterType [FieldOption(Label = "Disabled", Hint = "No track count filtering.")] Disabled = 0, - [FieldOption(Label = "Exact", Hint = "Only allow releases whose track count matches one edition of the album.")] + [FieldOption(Label = "Exact", Hint = "Only allow releases whose track count matches the pinned edition, or any edition when no release is pinned.")] Exact = 1, [FieldOption(Label = "Lower", Hint = "Filter out releases with fewer tracks than the shortest edition of the album.")] @@ -218,4 +218,4 @@ public enum TrackCountFilterType [FieldOption(Label = "Unfitting", Hint = "Exclude releases with significantly wrong track count.")] Unfitting = 3 } -} \ No newline at end of file +}