Build ErsatzTV Image / CI image pin matches docker/ci (pull_request) Successful in 5s
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 9s
Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 7s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 7m23s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 7s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 7s
Build ErsatzTV Image / Functional E2E (curl contracts) (pull_request) Successful in 15m20s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 18m18s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
A successful fetch returning zero items made existing.Except([]) flag the ENTIRE library FileNotFound in one scan — feeding EmptyTrashHandler's permanent delete and emptying every affected collection (dead channels). Add a shared MediaServerReconciliationGuard that skips (and logs a Warning) the sweep when incoming==0 while items exist, wired into the three library-level sweeps (Television shows / Movie / OtherVideo). An empty incoming set is indistinguishable at scan time from a mid-restore / emptied-upstream error (both report a zero total), so this deliberately overrides #476's degenerate "last item removed => empty incoming => flag" case. #476's cascade still fires for partial deletions (survivors present); its characterization test moves from an empty incoming to a survivor+removed partial-deletion case. Tests: policy table (MediaServerReconciliationGuardTests) + per-scanner integration proving the wiring (empty incoming + non-empty existing flags/reindexes nothing). Proven non-vacuous by neutralizing the guard. Nested TV season/episode sweeps left unguarded (bounded blast radius); ratio-threshold + projection-failure detection deferred to a follow-up. docs/decisions.md updated. Fixes #477 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
111 lines
4.6 KiB
C#
111 lines
4.6 KiB
C#
using System.IO.Abstractions;
|
|
using ErsatzTV.Core;
|
|
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Core.Interfaces.Metadata;
|
|
using ErsatzTV.Core.Interfaces.Repositories;
|
|
using ErsatzTV.Core.Jellyfin;
|
|
using ErsatzTV.Core.Metadata;
|
|
using ErsatzTV.Scanner.Core.Interfaces;
|
|
using ErsatzTV.Scanner.Core.Interfaces.Metadata;
|
|
using ErsatzTV.Scanner.Core.Metadata;
|
|
using Microsoft.Extensions.Logging;
|
|
using NSubstitute;
|
|
using NUnit.Framework;
|
|
using Shouldly;
|
|
|
|
namespace ErsatzTV.Scanner.Tests.Core.Metadata;
|
|
|
|
// #477: a successful-but-empty media-server fetch must not flag a non-empty movie library FileNotFound
|
|
// (which EmptyTrash could then permanently delete). Assert the sweep is skipped when nothing came in.
|
|
public class MediaServerMovieLibraryScannerTests
|
|
{
|
|
[TestFixture]
|
|
public class CleanupFileNotFoundItems
|
|
{
|
|
[Test]
|
|
public async Task Empty_Incoming_With_Existing_Movies_Does_Not_Flag()
|
|
{
|
|
var movieRepository = Substitute.For<IJellyfinMovieRepository>();
|
|
var scannerProxy = Substitute.For<IScannerProxy>();
|
|
|
|
var library = new JellyfinLibrary { Id = 3, Name = "Movies" };
|
|
|
|
movieRepository.GetExistingMovies(library)
|
|
.Returns(new List<JellyfinItemEtag>
|
|
{
|
|
new() { ItemId = "movie-1", State = MediaItemState.Normal },
|
|
new() { ItemId = "movie-2", State = MediaItemState.Normal }
|
|
});
|
|
|
|
var scanner = new TestMovieLibraryScanner(scannerProxy);
|
|
|
|
Either<BaseError, Unit> result = await scanner.Scan(
|
|
movieRepository,
|
|
new JellyfinConnectionParameters("http://jellyfin.example", "abc", 7),
|
|
library);
|
|
|
|
result.IsRight.ShouldBeTrue();
|
|
|
|
await movieRepository.DidNotReceive().FlagFileNotFound(
|
|
Arg.Any<JellyfinLibrary>(), Arg.Any<List<string>>());
|
|
await scannerProxy.DidNotReceive().ReindexMediaItems(
|
|
Arg.Any<int[]>(), Arg.Any<CancellationToken>());
|
|
}
|
|
}
|
|
|
|
// Minimal concrete subclass exposing the cleanup path. Driven with an empty incoming list, so none of
|
|
// the per-item metadata members below are ever invoked — they exist only to satisfy the contract.
|
|
private sealed class TestMovieLibraryScanner : MediaServerMovieLibraryScanner<
|
|
JellyfinConnectionParameters, JellyfinLibrary, JellyfinMovie, JellyfinItemEtag>
|
|
{
|
|
public TestMovieLibraryScanner(IScannerProxy scannerProxy)
|
|
: base(
|
|
scannerProxy,
|
|
Substitute.For<IFileSystem>(),
|
|
Substitute.For<ILocalChaptersProvider>(),
|
|
Substitute.For<IMetadataRepository>(),
|
|
Substitute.For<ILogger>())
|
|
{
|
|
}
|
|
|
|
public Task<Either<BaseError, Unit>> Scan(
|
|
IJellyfinMovieRepository movieRepository,
|
|
JellyfinConnectionParameters connectionParameters,
|
|
JellyfinLibrary library) =>
|
|
ScanLibrary(
|
|
movieRepository,
|
|
connectionParameters,
|
|
library,
|
|
_ => string.Empty,
|
|
false,
|
|
CancellationToken.None);
|
|
|
|
protected override IAsyncEnumerable<Tuple<JellyfinMovie, int>> GetMovieLibraryItems(
|
|
JellyfinConnectionParameters connectionParameters, JellyfinLibrary library) => EmptyMovies();
|
|
|
|
protected override string MediaServerItemId(JellyfinMovie movie) => movie.ItemId;
|
|
protected override string MediaServerEtag(JellyfinMovie movie) => movie.Etag;
|
|
|
|
protected override Task<Option<MovieMetadata>> GetFullMetadata(
|
|
JellyfinConnectionParameters connectionParameters, JellyfinLibrary library,
|
|
MediaItemScanResult<JellyfinMovie> result, JellyfinMovie incoming, bool deepScan) =>
|
|
throw new NotSupportedException();
|
|
|
|
protected override Task<Option<Tuple<MovieMetadata, MediaVersion>>> GetFullMetadataAndStatistics(
|
|
JellyfinConnectionParameters connectionParameters, JellyfinLibrary library,
|
|
MediaItemScanResult<JellyfinMovie> result, JellyfinMovie incoming) =>
|
|
throw new NotSupportedException();
|
|
|
|
protected override Task<Either<BaseError, MediaItemScanResult<JellyfinMovie>>> UpdateMetadata(
|
|
MediaItemScanResult<JellyfinMovie> result, MovieMetadata fullMetadata,
|
|
CancellationToken cancellationToken) =>
|
|
throw new NotSupportedException();
|
|
|
|
private static async IAsyncEnumerable<Tuple<JellyfinMovie, int>> EmptyMovies()
|
|
{
|
|
await Task.CompletedTask;
|
|
yield break;
|
|
}
|
|
}
|
|
}
|