Auto-tune channels can now carry per-content-source rotation weights (weighted
round-robin, e.g. 3x Show A / 1x Show B) and query corrections (exclude /
add-untagged), supplied at bulk-create time via an optional
`sources: [{sourceId, weight, excluded}]` on each AutoTunedChannelRequest.
Design (Option A, reuse #70): when a source is customized the channel is backed
by a system-owned MultiCollection of per-source SmartCollections carrying the
weights, with PlaybackOrder.WeightedShuffle -- the exact path
WeightedShuffleCollectionEnumerator already consumes. All-default weights keep
the #69 single-SmartCollection fair-share shape.
- Discriminators: TV -> live show_title:"X" (episodes carry no parent-show id in
the index); movies -> stable id:{mediaItemId}.
- Materialization is axis-dependent: TV materializes every base show individually
(un-weighted shows keep per-show fair-share) + a live remainder at weight 1;
MovieGenre materializes only touched movies + one count-weighted remainder.
- Remainder = (base) AND NOT (materialized union excluded) -- a partition.
- New nullable OwnedByChannelId on SmartCollection + MultiCollection
(dual-provider migration); owned rows are hidden from the collection lists and
cascade-cleaned on channel delete.
Tests: AutoTuneAxisMap query/partition units; DB-backed weighted-path handler
tests (TV materialize-all, movie count-remainder, exclusion, no-customization
fallback); delete-cleanup. Docs: decisions.md, domain-model.md, api-conventions.md;
OpenAPI trio regenerated.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
90 lines
3.5 KiB
C#
90 lines
3.5 KiB
C#
using ErsatzTV.Application.Channels;
|
|
using ErsatzTV.Core.Domain;
|
|
using NUnit.Framework;
|
|
using Shouldly;
|
|
|
|
namespace ErsatzTV.Tests.Application.Channels;
|
|
|
|
[TestFixture]
|
|
public class AutoTuneAxisMapTests
|
|
{
|
|
[Test]
|
|
public void GenerateQuery_Builds_Expected_Lucene()
|
|
{
|
|
AutoTuneAxisMap.GenerateQuery(AutoTuneAxis.TvShow, "The Office")
|
|
.ShouldBe("type:episode AND show_title:\"The Office\"");
|
|
AutoTuneAxisMap.GenerateQuery(AutoTuneAxis.TvGenre, "Comedy")
|
|
.ShouldBe("type:episode AND genre:\"Comedy\"");
|
|
AutoTuneAxisMap.GenerateQuery(AutoTuneAxis.MovieGenre, "Action")
|
|
.ShouldBe("type:movie AND genre:\"Action\"");
|
|
}
|
|
|
|
[Test]
|
|
public void GenerateQuery_Escapes_Quotes_And_Backslashes()
|
|
{
|
|
AutoTuneAxisMap.GenerateQuery(AutoTuneAxis.TvShow, "Bob\"s \\Show")
|
|
.ShouldBe("type:episode AND show_title:\"Bob\\\"s \\\\Show\"");
|
|
}
|
|
|
|
[Test]
|
|
public void GenerateName_Suffixes_Movie_Genres_Only()
|
|
{
|
|
AutoTuneAxisMap.GenerateName(AutoTuneAxis.TvShow, "The Office").ShouldBe("The Office");
|
|
AutoTuneAxisMap.GenerateName(AutoTuneAxis.TvGenre, "Comedy").ShouldBe("Comedy");
|
|
AutoTuneAxisMap.GenerateName(AutoTuneAxis.MovieGenre, "Action").ShouldBe("Action Movies");
|
|
}
|
|
|
|
[Test]
|
|
public void PlaybackOrderFor_Uses_PseudoTV_Defaults()
|
|
{
|
|
AutoTuneAxisMap.PlaybackOrderFor(AutoTuneAxis.TvShow).ShouldBe(PlaybackOrder.SeasonEpisode);
|
|
AutoTuneAxisMap.PlaybackOrderFor(AutoTuneAxis.TvGenre).ShouldBe(PlaybackOrder.Shuffle);
|
|
AutoTuneAxisMap.PlaybackOrderFor(AutoTuneAxis.MovieGenre).ShouldBe(PlaybackOrder.Shuffle);
|
|
}
|
|
|
|
// --- #425: per-source weighted distribution query authorship ---
|
|
|
|
[Test]
|
|
public void GenerateSourceQuery_Uses_ShowTitle_For_Tv_And_Id_For_Movies()
|
|
{
|
|
// TV episodes carry no parent-show id in the index; show_title is the only per-show discriminator.
|
|
AutoTuneAxisMap.GenerateSourceQuery(AutoTuneAxis.TvGenre, "The Office")
|
|
.ShouldBe("type:episode AND show_title:\"The Office\"");
|
|
AutoTuneAxisMap.GenerateSourceQuery(AutoTuneAxis.TvShow, "The Office")
|
|
.ShouldBe("type:episode AND show_title:\"The Office\"");
|
|
|
|
// A movie is the played item, so its own stable media-item id selects it exactly.
|
|
AutoTuneAxisMap.GenerateSourceQuery(AutoTuneAxis.MovieGenre, "1234")
|
|
.ShouldBe("type:movie AND id:1234");
|
|
}
|
|
|
|
[Test]
|
|
public void GenerateSourceQuery_Escapes_Tv_Discriminator()
|
|
{
|
|
AutoTuneAxisMap.GenerateSourceQuery(AutoTuneAxis.TvGenre, "Bob\"s \\Show")
|
|
.ShouldBe("type:episode AND show_title:\"Bob\\\"s \\\\Show\"");
|
|
}
|
|
|
|
[Test]
|
|
public void GenerateRemainderQuery_Returns_Base_When_Nothing_Subtracted()
|
|
{
|
|
AutoTuneAxisMap.GenerateRemainderQuery(AutoTuneAxis.TvGenre, "Comedy", [])
|
|
.ShouldBe("type:episode AND genre:\"Comedy\"");
|
|
}
|
|
|
|
[Test]
|
|
public void GenerateRemainderQuery_Subtracts_Tv_Sources_By_ShowTitle()
|
|
{
|
|
AutoTuneAxisMap.GenerateRemainderQuery(AutoTuneAxis.TvGenre, "Comedy", ["The Office", "Parks"])
|
|
.ShouldBe(
|
|
"(type:episode AND genre:\"Comedy\") AND NOT (show_title:\"The Office\" OR show_title:\"Parks\")");
|
|
}
|
|
|
|
[Test]
|
|
public void GenerateRemainderQuery_Subtracts_Movie_Sources_By_Id()
|
|
{
|
|
AutoTuneAxisMap.GenerateRemainderQuery(AutoTuneAxis.MovieGenre, "Action", ["12", "34"])
|
|
.ShouldBe("(type:movie AND genre:\"Action\") AND NOT (id:12 OR id:34)");
|
|
}
|
|
}
|