E3: correzioni della revisione di formati e fotogrammi
Le 16 osservazioni confermate della revisione, ognuna con la sua prova: - JPEG: il controllo stima la memoria di lavoro del decodificatore (progressivo), così un file che non si decodifica esce «troppo grande» e non «illeggibile». - Un EXIF che non si tiene lascia un EXIF minimo con l'orientamento, perché la foto convertita non esca girata. - Fotogrammi: istanti in millisecondi interi; la copia trova l'indice del nome dall'istante, non dall'ordine delle righe. - Video di durata sconosciuta misurati prima di registrare: contano nei limiti di 500 per richiesta e 5000 per video. - Rimuxaggio: la durata del segmento di elst passa nell'MP4, la fine tagliata resta nascosta (anche nei fotogrammi). - H.264: il punto di recupero vale come IDR solo con exact_match_flag. - MP3 in MP4: objectTypeIndication 0x69 fino a 24 kHz, 0x6B oltre. - Conversione della libreria: il lavoro toglie le righe di un formato spento o cambiato; spegnere toglie anche i «Non riuscito»; «Riprova» solo i formati di adesso; pausa per spazio prima di rileggere l'originale. - «Anche i N» conta e mette in coda solo il tipo che si cambia; le impostazioni dell'esportazione si salvano una per volta. - Eliminazione e «Tieni il più grande» scelgono i convertiti nella stessa transazione: nessun convertito orfano. - Un file arrivato tardi in un elemento vecchio mette in coda solo sé (file nuovo = salvato da quando il formato è scelto). - Zip dei fotogrammi a pezzi di 64 KB: un browser lento che legge non si interrompe, uno fermo sì. Decisioni in docs/decisioni.md (28/11), §4.10 della specifica precisato. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eb79b05fda
commit
958cb71cd6
38 files changed
+1276
-222
No files matched your search
@@ -81,6 +81,35 @@ public sealed class LibraryConversionTests
|
||||
Assert.IsEmpty(await library.Db.Conversions.ListByMediaAsync(jpg.Media[0].Id, ct));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ALateFileOfAnOldEntryQueuesItselfOnly()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
using var temp = new TempFolder();
|
||||
await using var library = await TestLibrary.CreateAsync(temp);
|
||||
var account = await library.Db.Accounts.AddAsync(Make.Account("marta.demo", "100"));
|
||||
var added = await library.Db.Entries.AddAsync(Make.Entry(account.Id, "1", Make.T0), [Make.Photo(1), Make.Photo(2)], ct);
|
||||
var (first, second) = (added.Stored.Media[0], added.Stored.Media[1]);
|
||||
await StorePngAsync(library, account, added.Stored.Entry, first, 31);
|
||||
await library.Ingest.AppendJournalAsync(added.Stored.Entry.Id, ct);
|
||||
|
||||
// Photos to JPG with «Solo i nuovi»: the PNG already in the library is left alone...
|
||||
library.Clock.Now += TimeSpan.FromMinutes(5);
|
||||
var settings = await TurnOnAsync(library, ExportFormat.Jpg);
|
||||
await new LibraryConversionQueue(library.Db, library.Clock).OnSettingsChangedAsync(ExportSettings.Default, settings, ct);
|
||||
|
||||
// ...also when the second file of its series arrives later: only that one is new.
|
||||
library.Clock.Now += TimeSpan.FromMinutes(5);
|
||||
await StorePngAsync(library, account, added.Stored.Entry, second, 32);
|
||||
await library.Ingest.AppendJournalAsync(added.Stored.Entry.Id, ct);
|
||||
|
||||
Assert.IsEmpty(await library.Db.Conversions.ListByMediaAsync(first.Id, ct), "the old file had its answer");
|
||||
Assert.AreEqual(MediaConversionState.Pending, (await library.Db.Conversions.ListByMediaAsync(second.Id, ct)).Single().State);
|
||||
|
||||
// «Anche i N» still counts the old one.
|
||||
Assert.AreEqual(1, (await new LibraryConversionQueue(library.Db, library.Clock).PreviewExistingAsync(settings, ct)).Files);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TurningOffDropsThePendingRowsAndKeepsTheConvertedOnes()
|
||||
{
|
||||
@@ -278,6 +307,108 @@ public sealed class LibraryConversionTests
|
||||
Assert.AreEqual(MediaConversionState.Pending, (await library.Db.Conversions.ListByMediaAsync(entry.Media[0].Id, ct)).Single().State);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ALowDiskPausesBeforeTheOriginalIsReadAgain()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
using var temp = new TempFolder();
|
||||
await using var library = await TestLibrary.CreateAsync(temp);
|
||||
await TurnOnAsync(library, ExportFormat.Jpg);
|
||||
var (account, entry) = await SavePngAsync(library, "1", 23);
|
||||
var space = new FakeFreeSpaceProbe();
|
||||
space.Set(library.Layout.AccountFolder(account), 1024, 2 * FakeFreeSpaceProbe.GB);
|
||||
var throttle = new ConversionThrottle();
|
||||
var worker = new LibraryConversionWorker(Environment(library, throttle: throttle) with { FreeSpace = space });
|
||||
|
||||
// Another conversion holds the throttle: a pass that decoded the photo again would wait for it.
|
||||
using var release = new ManualResetEventSlim();
|
||||
var other = throttle.RunAsync(_ => release.Wait(TimeSpan.FromMinutes(1)), ct);
|
||||
try
|
||||
{
|
||||
for (var wakeUp = 0; wakeUp < 3; wakeUp++)
|
||||
{
|
||||
var pass = await worker.RunOnceAsync(ct).WaitAsync(TimeSpan.FromSeconds(30), ct);
|
||||
Assert.AreEqual((0, false), (pass.Done, pass.Again));
|
||||
Assert.AreEqual(LibraryConversionText.LowSpace, (await worker.StatusAsync(ct)).Waiting);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
release.Set();
|
||||
await other;
|
||||
}
|
||||
|
||||
Assert.AreEqual(MediaConversionState.Pending, (await library.Db.Conversions.ListByMediaAsync(entry.Media[0].Id, ct)).Single().State);
|
||||
space.Set(library.Layout.AccountFolder(account), 50 * FakeFreeSpaceProbe.GB, 100 * FakeFreeSpaceProbe.GB);
|
||||
Assert.AreEqual(1, (await worker.RunOnceAsync(ct)).Converted, "space again: it converts");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AFormatTurnedOffOrChangedIsNeitherRetriedNorConverted()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
using var temp = new TempFolder();
|
||||
await using var library = await TestLibrary.CreateAsync(temp);
|
||||
var jpg = await TurnOnAsync(library, ExportFormat.Jpg);
|
||||
var (account, entry) = await SavePngAsync(library, "1", 24);
|
||||
var media = entry.Media[0];
|
||||
var path = library.Layout.FullPath(account, media.RelativePath!);
|
||||
var bytes = await File.ReadAllBytesAsync(path, ct);
|
||||
File.Delete(path);
|
||||
await Worker(library).RunOnceAsync(ct);
|
||||
Assert.AreEqual(MediaConversionState.Failed, (await library.Db.Conversions.ListByMediaAsync(media.Id, ct)).Single().State);
|
||||
await File.WriteAllBytesAsync(path, bytes, ct);
|
||||
var queue = new LibraryConversionQueue(library.Db, library.Clock);
|
||||
|
||||
// Photos to PNG without the queue told (another way in): «Riprova» puts back only the formats set now.
|
||||
var png = jpg with { LibraryPhotoFormat = ExportFormat.Png };
|
||||
await png.SaveAsync(library.Db.Settings, ct);
|
||||
Assert.AreEqual(0, await queue.RetryFailedAsync(ct));
|
||||
|
||||
// Told: the failures of the format changed go with its queue, they are neither counted nor retried.
|
||||
await queue.OnSettingsChangedAsync(jpg, png, ct);
|
||||
Assert.IsEmpty(await library.Db.Conversions.ListByMediaAsync(media.Id, ct));
|
||||
Assert.AreEqual(0, (await library.Db.Conversions.CountByStateAsync(ct)).Failed);
|
||||
|
||||
// A row left in the old format (put back by a supersession, say) is dropped by the worker, never written.
|
||||
await library.Db.Conversions.EnqueueAsync([new Febe.Core.Storage.MediaConversionRequest(media.Id, ExportFormat.Jpg, media.Sha256!)], library.Clock.Now, ct);
|
||||
var pass = await Worker(library).RunOnceAsync(ct);
|
||||
Assert.AreEqual(0, pass.Converted);
|
||||
Assert.IsEmpty(await library.Db.Conversions.ListByMediaAsync(media.Id, ct));
|
||||
Assert.IsFalse(File.Exists(Path.ChangeExtension(path, ".jpg")), "no JPG while the photos are set to PNG");
|
||||
|
||||
// Turned off altogether: the same.
|
||||
var off = png with { LibraryPhotoFormat = ExportFormat.Original };
|
||||
await off.SaveAsync(library.Db.Settings, ct);
|
||||
await library.Db.Conversions.EnqueueAsync([new Febe.Core.Storage.MediaConversionRequest(media.Id, ExportFormat.Png, media.Sha256!)], library.Clock.Now, ct);
|
||||
Assert.AreEqual(0, (await Worker(library).RunOnceAsync(ct)).Converted);
|
||||
Assert.IsEmpty(await library.Db.Conversions.ListByMediaAsync(media.Id, ct));
|
||||
Assert.HasCount(1, Directory.GetFiles(library.Layout.AccountFolder(account), "*.*", SearchOption.AllDirectories).Where(f => !f.EndsWith(AccountJournal.FileName, StringComparison.Ordinal)), "only the original");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AConversionRecordedWhileTheEntryIsDeletedGoesWithIt()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
using var temp = new TempFolder();
|
||||
await using var library = await TestLibrary.CreateAsync(temp);
|
||||
await TurnOnAsync(library, ExportFormat.Jpg);
|
||||
var (account, entry) = await SavePngAsync(library, "1", 25);
|
||||
var media = entry.Media[0];
|
||||
var worker = Worker(library);
|
||||
|
||||
// The worker records its conversion while the deletion writes its journal line (the file is still there).
|
||||
var clock = new HookClock(library.Clock.Now, () => worker.RunOnceAsync(ct));
|
||||
var deletion = new LibraryDeletion(library.Db, library.Layout, new AccountJournal(clock), library.Clock);
|
||||
var result = await deletion.DeleteAsync(entry.Entry.Id, DeletionMode.Remember, ct);
|
||||
|
||||
Assert.AreEqual(1, clock.Pass?.Converted, "converted during the deletion");
|
||||
var row = (await library.Db.Conversions.ListByMediaAsync(media.Id, ct)).Single();
|
||||
Assert.AreEqual(MediaConversionState.Removed, row.State, "the row says the truth");
|
||||
Assert.IsFalse(File.Exists(library.Layout.FullPath(account, row.RelativePath!)), "the converted file goes with the entry");
|
||||
Assert.AreEqual(1, result.ConvertedFiles);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AnUnpluggedAccountFolderIsNotCreated()
|
||||
{
|
||||
@@ -532,6 +663,29 @@ public sealed class LibraryConversionTests
|
||||
Assert.AreEqual(0, await bed.Library.Db.Duplicates.CountPendingAsync(DuplicateOrigin.Import, ct), "never a probable duplicate of its original");
|
||||
}
|
||||
|
||||
/// <summary>A clock that runs <c>work</c> once, the first time it is read (inside the journal append of a deletion).</summary>
|
||||
private sealed class HookClock(DateTimeOffset now, Func<Task<LibraryConversionPass>> work) : IClock
|
||||
{
|
||||
public LibraryConversionPass? Pass { get; private set; }
|
||||
|
||||
public DateTimeOffset Now
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Pass is null)
|
||||
{
|
||||
Pass = Task.Run(work).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
return now;
|
||||
}
|
||||
}
|
||||
|
||||
public TimeZoneInfo LocalZone => TestZones.Rome;
|
||||
|
||||
public Task Delay(TimeSpan time, CancellationToken ct) => Task.CompletedTask;
|
||||
}
|
||||
|
||||
private static LibraryConversionEnvironment Environment(TestLibrary library, LongWorkGate? gate = null, ConversionThrottle? throttle = null) => new()
|
||||
{
|
||||
Storage = library.Db,
|
||||
@@ -552,6 +706,12 @@ public sealed class LibraryConversionTests
|
||||
return settings;
|
||||
}
|
||||
|
||||
private static async Task StorePngAsync(TestLibrary library, Account account, Entry entry, Media media, int scene)
|
||||
{
|
||||
using var image = TestImages.Scene(scene, 64, 48);
|
||||
await library.Ingest.SaveMediaAsync(account, entry, media, new MediaContent { Content = new MemoryStream(TestImages.Png(image)), Extension = ".png" });
|
||||
}
|
||||
|
||||
private static Task<(Account Account, EntryWithMedia Entry)> SavePngAsync(TestLibrary library, string id, int scene)
|
||||
{
|
||||
using var image = TestImages.Scene(scene, 64, 48);
|
||||
|
||||
Reference in new issue
Block a user