Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/selected-edition-tests.yml
Original file line number Diff line number Diff line change
@@ -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
100 changes: 100 additions & 0 deletions Tubifarry.Tests/SlskdSelectedEditionTests.cs
Original file line number Diff line number Diff line change
@@ -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<Track>()
}).ToList();
var album = new Album { AnyReleaseOk = anyReleaseOk, AlbumReleases = releases };
var criteria = new AlbumSearchCriteria
{
Artist = new Artist
{
Name = "Artist",
Metadata = new ArtistMetadata { Aliases = new List<string>() }
},
AlbumTitle = "Album",
Albums = new List<Album> { 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 }));
}
}
15 changes: 15 additions & 0 deletions Tubifarry.Tests/Tubifarry.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<ProjectReference Include="../Tubifarry/Tubifarry.csproj" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions Tubifarry/Indexers/Soulseek/SlskdRequestGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public IndexerPageableRequestChain<LazyIndexerPageableRequest> GetSearchRequests
List<string> tracks = trackList?.Select(x => x.Title).ToList() ?? [];
List<int> trackDurations = trackList?.Where(t => t.Duration > 0).Select(t => t.Duration).ToList() ?? [];
List<int> 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];

Expand Down
4 changes: 2 additions & 2 deletions Tubifarry/Indexers/Soulseek/SlskdSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")]
Expand All @@ -218,4 +218,4 @@ public enum TrackCountFilterType
[FieldOption(Label = "Unfitting", Hint = "Exclude releases with significantly wrong track count.")]
Unfitting = 3
}
}
}