E3: prove di codec, rimuxaggio, fotogrammi, copie e conversione
Le prove del nucleo della tappa E3 (WP6a), con i media costruiti dalle prove: il controllo delle foto (stesso formato, HEIC/AVIF/raw, animate, CMYK e oltre 8 bit, budget di pixel), metadati nei blocchi giusti e perdite annotate, pixel identici in WEBP senza perdita; il rimuxaggio da MOV (nuovo TestVideos.Mov) e Matroska a MP4 con campioni, date, rotazione, lingua ed edit; i fotogrammi H.264 e H.265 all'istante, ogni k secondi e N in tutto; i suffissi protetti dal taglio a 240; le copie convertite, com'è con nota, adozione, «già copiato» in ogni forma, «Copia di nuovo» esatta, spazio sul convertito, fotogrammi nella cartella delle copie (FrameOnly, una copia per campione, lotti su più pagine, tetto); la conversione della libreria (perdite, rimuxaggio, doppioni, importazione delle copie convertite). Servono a fissare il comportamento di E3 prima dell'unione. Nessun codice del prodotto cambia; un limite trovato (istanti a meno di 1 ms in «N in tutto») è annotato per Alberto. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d06b587806
commit
f5e12c5d74
9 files changed
+1408
-4
No files matched your search
@@ -413,6 +413,125 @@ public sealed class LibraryConversionTests
|
||||
Assert.AreEqual(0, await bed.Library.Db.Duplicates.CountPendingAsync(DuplicateOrigin.Import, ct), "never a probable duplicate of its original");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task WhatWasNotKeptIsRecordedOnTheConvertedRow()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
using var temp = new TempFolder();
|
||||
await using var library = await TestLibrary.CreateAsync(temp);
|
||||
await TurnOnAsync(library, ExportFormat.Jpg);
|
||||
using var clear = Imaging.TestImages.Gradient(40, 30, seed: 9); // transparent pixels
|
||||
var (account, entry) = await SaveAsync(library, "1", new TestFile(Make.Photo(1), Core.Codecs.Images.ImageConverter.Encode(clear, Core.Codecs.Images.ImageFormat.Png, null), ".png"));
|
||||
|
||||
Assert.AreEqual(1, (await Worker(library).RunOnceAsync(ct)).Converted);
|
||||
|
||||
var row = (await library.Db.Conversions.ListByMediaAsync(entry.Media[0].Id, ct)).Single();
|
||||
Assert.AreEqual((MediaConversionState.Converted, ExportText.Notes.TransparencyWhite), (row.State, row.LastError), "the loss codes of a Converted row (D19)");
|
||||
Assert.IsTrue(File.Exists(library.Layout.FullPath(account, row.RelativePath!)));
|
||||
Assert.IsFalse(LibraryConversionText.IsAsIs(row.LastError));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AMovIsRemuxedNextToTheOriginal()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
using var temp = new TempFolder();
|
||||
await using var library = await TestLibrary.CreateAsync(temp);
|
||||
await (ExportSettings.Default with { LibraryVideoFormat = ExportFormat.Mp4 }).SaveAsync(library.Db.Settings, ct);
|
||||
var mov = Codecs.Containers.TestVideos.Mov(Codecs.Containers.ElementaryStream.Load("BA1_Sony_D"), new Codecs.Containers.MovOptions(Audio: true, Language: "ita"));
|
||||
var (account, entry) = await SaveAsync(library, "1", new TestFile(Make.Video(1), mov, ".mov"));
|
||||
var media = entry.Media[0];
|
||||
var original = library.Layout.FullPath(account, media.RelativePath!);
|
||||
|
||||
Assert.AreEqual(1, (await Worker(library).RunOnceAsync(ct)).Converted);
|
||||
|
||||
var row = (await library.Db.Conversions.ListByMediaAsync(media.Id, ct)).Single();
|
||||
Assert.AreEqual((MediaConversionState.Converted, ExportFormat.Mp4, media.Sha256), (row.State, row.Format, row.SourceSha256));
|
||||
Assert.AreEqual(Path.ChangeExtension(media.RelativePath!, ".mp4"), row.RelativePath);
|
||||
var mp4 = await File.ReadAllBytesAsync(library.Layout.FullPath(account, row.RelativePath!), ct);
|
||||
Assert.AreEqual((Convert.ToHexStringLower(SHA256.HashData(mp4)), (long?)mp4.Length), (row.Sha256, row.Bytes));
|
||||
using var stream = new MemoryStream(mp4);
|
||||
var container = Core.Codecs.Containers.ContainerReader.Read(stream, Core.Codecs.Containers.ContainerReader.AnyDate, samples: false)!;
|
||||
Assert.AreNotEqual("qt ", container.MajorBrand);
|
||||
Assert.AreEqual("ita", container.Video!.Language);
|
||||
CollectionAssert.AreEqual(mov, await File.ReadAllBytesAsync(original, ct), "the MOV stays as it is");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TheDuplicateLoserTakesItsConversions()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
using var temp = new TempFolder("doppioni");
|
||||
await using var library = await TestLibrary.CreateAsync(temp);
|
||||
await TurnOnAsync(library, ExportFormat.Png);
|
||||
var account = await library.Db.Accounts.AddAsync(Make.Account("doppie.prova"), ct);
|
||||
var older = await library.SaveAsync(account, Make.Entry(account.Id, "100", Make.T0 - TimeSpan.FromDays(3)), [TestFile.Photo(1, 41, 320, 400)]);
|
||||
var series = await library.SaveAsync(account, Make.Entry(account.Id, "200", Make.T0 - TimeSpan.FromDays(2)), [TestFile.Photo(1, 41, 240, 300), TestFile.Photo(2, 77, 320, 320)]);
|
||||
Assert.AreEqual(3, (await Worker(library).RunOnceAsync(ct)).Converted);
|
||||
var lost = (await library.Db.Conversions.ListByMediaAsync(series.Media[0].Id, ct)).Single();
|
||||
var kept = (await library.Db.Conversions.ListByMediaAsync(series.Media[1].Id, ct)).Single();
|
||||
|
||||
// «Tieni quello in libreria» for the first file of the series: its PNG goes with it, the second file's stays.
|
||||
var review = new DownloadDuplicateReview(library.Db, library.Layout, library.Journal, library.Clock, library.Thumbnails, library.Index);
|
||||
var pair = (await review.ListAsync(ct: ct)).Single(c => c.Candidate.EntryId == series.Entry.Id);
|
||||
var result = await review.DecideAsync(pair.Pair.Id, DuplicateDecision.KeepExisting, ct: ct);
|
||||
|
||||
Assert.AreEqual(1, result.FilesRemoved);
|
||||
Assert.AreEqual(MediaConversionState.Removed, (await library.Db.Conversions.GetAsync(lost.Id, ct))!.State);
|
||||
Assert.IsFalse(File.Exists(library.Layout.FullPath(account, lost.RelativePath!)), "the converted file of the loser goes");
|
||||
Assert.AreEqual(MediaConversionState.Converted, (await library.Db.Conversions.GetAsync(kept.Id, ct))!.State);
|
||||
Assert.IsTrue(File.Exists(library.Layout.FullPath(account, kept.RelativePath!)));
|
||||
var olderRow = (await library.Db.Conversions.ListByMediaAsync(older.Media[0].Id, ct)).Single();
|
||||
Assert.IsTrue(File.Exists(library.Layout.FullPath(account, olderRow.RelativePath!)), "the winner's PNG stays");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ImportingACopyConvertedForADestinationOrAFrameSaysItIsInTheLibrary()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
using var temp = new TempFolder("importa");
|
||||
await using var bed = await ImportTestBed.CreateAsync(temp);
|
||||
var (account, saved) = await bed.AccountWithPhotoAsync("luca.demo", "501", TestFile.PhotoBytes(29, 64, 48));
|
||||
var media = saved.Media[0];
|
||||
|
||||
// Two files a destination of Febe got: a PNG copy of the photo and a frame (here any picture: only its SHA counts).
|
||||
using var picture = TestImages.Scene(29, 64, 48);
|
||||
var png = TestImages.Png(picture);
|
||||
using var other = TestImages.Scene(30, 48, 64);
|
||||
var frame = TestImages.Png(other);
|
||||
var usb = await bed.Library.Db.Exports.AddDestinationAsync(new ExportDestination { Scope = ExportScope.General, RootPath = temp.Combine("usb"), ContentTypes = ContentTypes.All, CreatedAt = Make.T0 }, ct);
|
||||
foreach (var (bytes, variant, at, name) in new[] { (png, ExportVariant.Converted, (TimeSpan?)null, "copia.png"), (frame, ExportVariant.Frame, TimeSpan.FromMilliseconds(1250), "fotogramma.png") })
|
||||
{
|
||||
await bed.Library.Db.Exports.AddCopyAsync(new ExportCopy
|
||||
{
|
||||
DestinationId = usb.Id,
|
||||
AccountId = account.Id,
|
||||
MediaId = media.Id,
|
||||
SourceSha256 = media.Sha256!,
|
||||
Variant = variant,
|
||||
Format = ExportFormat.Png,
|
||||
FrameAt = at,
|
||||
State = ExportCopyState.Copied,
|
||||
RelativePath = "luca.demo/" + name,
|
||||
Bytes = bytes.Length,
|
||||
CopySha256 = Convert.ToHexStringLower(SHA256.HashData(bytes)),
|
||||
CopiedAt = Make.T0,
|
||||
}, ct);
|
||||
bed.Write("luca.demo/" + name, bytes);
|
||||
}
|
||||
|
||||
var run = await bed.AnalyzeAsync();
|
||||
|
||||
foreach (var name in new[] { "copia.png", "fotogramma.png" })
|
||||
{
|
||||
var file = await bed.FileAsync(run.Id, "luca.demo/" + name);
|
||||
Assert.AreEqual(ImportOutcome.AlreadyInLibrary, file.Outcome, name);
|
||||
Assert.AreEqual(Core.Import.ImportText.NoteConvertedCopy, file.LastError, name);
|
||||
}
|
||||
|
||||
Assert.AreEqual(0, await bed.Library.Db.Duplicates.CountPendingAsync(DuplicateOrigin.Import, ct), "never a probable duplicate of its original");
|
||||
}
|
||||
|
||||
private static LibraryConversionEnvironment Environment(TestLibrary library, LongWorkGate? gate = null, ConversionThrottle? throttle = null) => new()
|
||||
{
|
||||
Storage = library.Db,
|
||||
|
||||
Reference in new issue
Block a user