E3: formati e fotogrammi nella copia verso le cartelle esterne

La richiesta di copia porta i formati («Copia in…» per foto e video, poi
la destinazione, poi le impostazioni), i fotogrammi dei video e la «Copia
di nuovo» di una sola copia. Il piano prevede convertiti, copiati com'è e
fotogrammi; il lavoro si ricorda di fotogrammi ed identità esatta per la
ripresa.

La copia converte prima dei controlli di spazio e di FAT32, adotta un file
già presente solo se lunghezza e SHA-256 della conversione coincidono, e
prende i fotogrammi di un video in un solo passaggio, ognuno con il suo
istante esatto come identità. Un file copiato in qualunque forma che non
sia un fotogramma è «già copiato»; un fotogramma non rende mai copiato il
file (nuovo segno FrameOnly). Le note sono un elenco di codici, con i testi
italiani nuovi e il rapporto che mostra i file copiati con una nota.

Le prove dell'archivio e dei piani delle query seguono le nuove ricerche;
due prove nuove coprono una foto convertita e un fotogramma.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-27 23:08:38 +01:00
1 parent 704c1ed9cf
commit b746aff45d
19 files changed
+1941 -257

No files matched your search

@@ -603,6 +603,7 @@ public sealed class ExportConstraintTests
("ListItemsAsync", ExportStore.ItemsOfRunSql(false), [("@r", run), ("@after", 0L), ("@limit", 500L)], false),
("ListItemsAsync (stato)", ExportStore.ItemsOfRunSql(true), [("@r", run), ("@s", "Pending"), ("@after", 0L), ("@limit", 500L)], false),
("ListPendingAsync", MediaConversionStore.PendingSql, [("@after", 0L), ("@limit", 500L)], false),
("FirstItemIdAsync", ExportStore.FirstItemSql, [("@r", run), ("@m", 1L), ("@v", "Frame"), ("@f", "Png")], false),
};
var problems = new List<string>();
foreach (var (name, sql, parameters, sortAllowed) in lookups)
@@ -637,7 +638,12 @@ public sealed class ExportConstraintTests
var lookupsE2 = new (string Name, string Sql, (string, object?)[] Parameters, bool SortAllowed)[]
{
("FindReplacedCopyAsync", ExportStore.ReplacedCopySql, [("@h", Make.Sha(5008)), ("@d", w.General), ("@a", w.Marta)], false),
("FindCopiedElsewhereAsync", ExportStore.CopiedElsewhereSql, [("@h", Make.Sha(17)), ("@v", "Whole"), ("@f", "Original"), ("@a", w.Marta)], true),
("FindCopiedElsewhereAsync", ExportStore.CopiedElsewhereSql, [("@h", Make.Sha(17)), ("@a", w.Marta)], true),
// Tappa E3 (D3): the lookups of a file in any form but a frame sort the few rows of one SHA-256.
("ListCurrentCopiesAnyFormAsync", ExportStore.CurrentCopiesAnyFormSql, [("@h", Make.Sha(17)), ("@d", w.General), ("@a", w.Marta)], true),
("FindLatestCopyAnyFormAsync", ExportStore.LatestCopyAnyFormSql, [("@h", Make.Sha(17)), ("@d", w.General), ("@a", w.Marta)], true),
("ClearFailedAsync", ExportStore.ClearFailedSql, [("@h", Make.Sha(17)), ("@d", w.General), ("@a", w.Marta), ("@v", "Converted"), ("@f", "Png")], false),
("GetCopyStatesAsync", ExportStore.CopyStatesSql(shas), Shas(("@d", w.General)), false),
("GetCopyStatesAsync (sostituiti)", ExportStore.ReplacedStatesSql(shas), Shas(("@d", w.General)), false),
};
+18 -7
View File
@@ -534,26 +534,37 @@ public sealed class ExportStoreTests
using var temp = new TempFolder();
await using var db = await TestDatabase.OpenAsync(temp);
var w = await CreateAsync(db);
Assert.IsNull(await db.Exports.FindCopiedElsewhereAsync(Make.Sha(1), ExportVariant.Whole, ExportFormat.Original));
Assert.IsNull(await db.Exports.FindCopiedElsewhereAsync(Make.Sha(1)));
var own = await db.Exports.AddCopyAsync(w.WholeCopy("a.jpg", destination: w.Own));
var general = await db.Exports.AddCopyAsync(w.WholeCopy("luca.demo/a.jpg", account: w.Luca, media: w.LucaMedia));
await db.Exports.AddCopyAsync(w.WholeCopy("marta.demo/a.jpg") with { State = ExportCopyState.Removed });
Assert.AreEqual(general.Id, (await db.Exports.FindCopiedElsewhereAsync(Make.Sha(1), ExportVariant.Whole, ExportFormat.Original))!.Id, "the newest Copied row");
Assert.IsNull(await db.Exports.FindCopiedElsewhereAsync(Make.Sha(1), ExportVariant.Whole, ExportFormat.Jpg), "another format");
Assert.IsNull(await db.Exports.FindCopiedElsewhereAsync(Make.Sha(2), ExportVariant.Whole, ExportFormat.Original));
Assert.AreEqual(general.Id, (await db.Exports.FindCopiedElsewhereAsync(Make.Sha(1)))!.Id, "the newest Copied row");
Assert.IsNull(await db.Exports.FindCopiedElsewhereAsync(Make.Sha(2)));
// Tappa E3 (D3): a file copied in any form but a frame counts; a frame never does.
var converted = await db.Exports.AddCopyAsync(w.WholeCopy("luca.demo/c.jpg", account: w.Luca, media: w.LucaMedia) with
{
SourceSha256 = Make.Sha(3), CopySha256 = Make.Sha(4), Variant = ExportVariant.Converted, Format = ExportFormat.Jpg,
});
Assert.AreEqual(converted.Id, (await db.Exports.FindCopiedElsewhereAsync(Make.Sha(3)))!.Id, "a Converted Jpg copy counts");
await db.Exports.AddCopyAsync(w.WholeCopy("luca.demo/f_t0m01s000.png", account: w.Luca, media: w.LucaMedia) with
{
SourceSha256 = Make.Sha(7), CopySha256 = Make.Sha(8), Variant = ExportVariant.Frame, Format = ExportFormat.Png, FrameAt = TimeSpan.FromSeconds(1),
});
Assert.IsNull(await db.Exports.FindCopiedElsewhereAsync(Make.Sha(7)), "a frame does not count");
await db.Exports.RetireDestinationAsync(w.General, Make.T0.AddDays(1));
Assert.AreEqual(own.Id, (await db.Exports.FindCopiedElsewhereAsync(Make.Sha(1), ExportVariant.Whole, ExportFormat.Original))!.Id);
Assert.AreEqual(own.Id, (await db.Exports.FindCopiedElsewhereAsync(Make.Sha(1)))!.Id);
await db.Exports.RetireDestinationAsync(w.Own, Make.T0.AddDays(1));
Assert.IsNull(await db.Exports.FindCopiedElsewhereAsync(Make.Sha(1), ExportVariant.Whole, ExportFormat.Original), "a retired folder is not in use");
Assert.IsNull(await db.Exports.FindCopiedElsewhereAsync(Make.Sha(1)), "a retired folder is not in use");
// A copy whose account was removed has no account to be «per un altro account».
var third = await db.Exports.AddDestinationAsync(Destination(ExportScope.General, null, @"G:\Nuova"));
var orphan = await db.Exports.AddCopyAsync(w.WholeCopy("marta.demo/a.jpg", destination: third.Id));
await db.Accounts.DeleteAsync(w.Marta);
Assert.IsNull((await db.Exports.GetCopyAsync(orphan.Id))!.AccountId);
Assert.IsNull(await db.Exports.FindCopiedElsewhereAsync(Make.Sha(1), ExportVariant.Whole, ExportFormat.Original));
Assert.IsNull(await db.Exports.FindCopiedElsewhereAsync(Make.Sha(1)));
}
[TestMethod]
@@ -0,0 +1,95 @@
using System.Security.Cryptography;
using Febe.Core.Domain;
using Febe.Core.Export;
using Febe.Core.Library;
using Febe.Core.Storage;
using Febe.Tests.Codecs.Containers;
using Febe.Tests.Export.Support;
using Febe.Tests.Support;
namespace Febe.Tests.Export;
/// <summary>
/// The copy job of tappa E3 on real folders (WP1.7): a converted copy and a frame copy. The full set of cases is WP6a's;
/// the media are built by the tests.
/// </summary>
[TestClass]
public sealed class ExportConversionTests
{
private static readonly byte[] PngSignature = [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A];
public TestContext TestContext { get; set; } = null!;
[TestMethod]
public async Task APhotoIsConvertedAndThenCountsAsCopiedInAnyForm()
{
var ct = TestContext.CancellationToken;
await using var bed = await ExportTestBed.CreateAsync();
var post = await bed.PostAsync(bed.Marta, "960", 31);
var media = post.Media[0];
await bed.GeneralAsync(ct: ct);
var start = await bed.CopyAsync(
new ExportJobRequest(new ExportSelection.Media([media.Id]), Formats: new ExportFormatChoice(ExportFormat.Png, null)), ct);
var item = (await bed.ItemsAsync(start.Runs.Single().Id, ct)).Single();
Assert.AreEqual((ExportItemState.Copied, ExportVariant.Converted, ExportFormat.Png), (item.State, item.Variant, item.Format));
var copy = (await bed.Db.Exports.GetCopyAsync(item.CopyId!.Value, ct))!;
Assert.AreEqual((ExportVariant.Converted, ExportFormat.Png, media.Sha256), (copy.Variant, copy.Format, copy.SourceSha256));
Assert.AreEqual("marta.demo/" + Path.ChangeExtension(media.RelativePath!, ".png"), copy.RelativePath);
var file = Path.Combine(bed.Usb, LibraryLayout.ToPlatform(copy.RelativePath!));
var bytes = await File.ReadAllBytesAsync(file, ct);
CollectionAssert.AreEqual(PngSignature, bytes[..8]);
Assert.AreEqual(Convert.ToHexStringLower(SHA256.HashData(bytes)), copy.CopySha256);
Assert.AreNotEqual(media.Sha256, copy.CopySha256);
Assert.AreEqual(bytes.Length, copy.Bytes);
Assert.IsFalse(File.Exists(bed.GeneralCopy(bed.Marta, media)), "no byte copy next to it");
// «Già copiato» is any form but a frame (D3): a copy of the account in Originale writes nothing more.
var again = await bed.CopyAccountAsync(bed.Marta, ct: ct);
var second = (await bed.ItemsAsync(again.Runs.Single().Id, ct)).Single();
Assert.AreEqual((ExportItemState.AlreadyCopied, copy.Id, ExportText.Notes.CopiedInAnotherFormat), (second.State, second.CopyId, second.Note));
Assert.AreEqual("Già copiato in un altro formato", ExportText.Note(second.Note));
Assert.HasCount(1, Fingerprint.Of(bed.Usb));
}
[TestMethod]
public async Task AFrameIsWrittenWithItsInstantAndLeavesTheVideoToCopy()
{
var ct = TestContext.CancellationToken;
await using var bed = await ExportTestBed.CreateAsync();
var mp4 = TestVideos.Mp4(ElementaryStream.Load("BA1_Sony_D"));
var post = await bed.Library.SaveAsync(bed.Marta, Make.Entry(bed.Marta.Id, "961", Make.T0.AddDays(-2)), [new TestFile(Make.Video(1), mp4, ".mp4")]);
var video = post.Media[0];
await bed.GeneralAsync(ct: ct);
var frames = new ExportFramesRequest(FrameMode.At, TimeSpan.Zero, null, null, ExportFormat.Png);
var start = await bed.CopyAsync(new ExportJobRequest(new ExportSelection.Media([video.Id]), Frames: frames), ct);
var run = await bed.RunAsync(start.Runs.Single().Id, ct);
Assert.AreEqual(ExportRunState.Completed, run.State);
var item = (await bed.ItemsAsync(run.Id, ct)).Single();
Assert.AreEqual((ExportItemState.Copied, ExportVariant.Frame, ExportFormat.Png, (TimeSpan?)TimeSpan.Zero), (item.State, item.Variant, item.Format, item.FrameAt));
var copy = (await bed.Db.Exports.GetCopyAsync(item.CopyId!.Value, ct))!;
Assert.AreEqual((ExportVariant.Frame, ExportFormat.Png, video.Sha256), (copy.Variant, copy.Format, copy.SourceSha256));
Assert.IsNotNull(copy.FrameAt);
StringAssert.Contains(copy.RelativePath, "_t0m00s");
StringAssert.EndsWith(copy.RelativePath, ".png");
var bytes = await File.ReadAllBytesAsync(Path.Combine(bed.Usb, LibraryLayout.ToPlatform(copy.RelativePath!)), ct);
CollectionAssert.AreEqual(PngSignature, bytes[..8]);
Assert.AreEqual(Convert.ToHexStringLower(SHA256.HashData(bytes)), copy.CopySha256);
// A frame never makes the file copied (D4): the mark says so, and «Copia in…» copies the video itself.
Assert.AreEqual(ExportMark.FrameOnly, (await bed.Db.Exports.GetFileMarksAsync([video.Id], ct))[video.Id]);
var whole = await bed.CopyAccountAsync(bed.Marta, ct: ct);
var copied = (await bed.ItemsAsync(whole.Runs.Single().Id, ct)).Single();
Assert.AreEqual((ExportItemState.Copied, ExportVariant.Whole), (copied.State, copied.Variant));
Assert.AreEqual(ExportMark.Copied, (await bed.Db.Exports.GetFileMarksAsync([video.Id], ct))[video.Id]);
// The same instant asked again is «Già copiato» (its exact identity, D12).
var repeat = await bed.CopyAsync(new ExportJobRequest(new ExportSelection.Media([video.Id]), Frames: frames), ct);
var same = (await bed.ItemsAsync(repeat.Runs.Single().Id, ct)).Single();
Assert.AreEqual((ExportItemState.AlreadyCopied, copy.Id), (same.State, same.CopyId));
Assert.HasCount(2, Fingerprint.Of(bed.Usb));
}
}
@@ -100,7 +100,7 @@ public sealed class ExportCopiesFilterTests
Assert.AreEqual(ExportCopyState.Copied, (await db.Exports.GetCopyStatesAsync(w.Own, [(w.Marta, Make.Sha(1))], ct))[(w.Marta, Make.Sha(1))]);
Assert.IsNotNull(await db.Exports.FindReplacedCopyAsync(w.General, w.Luca, Make.Sha(1), ct));
Assert.IsNull(await db.Exports.FindReplacedCopyAsync(w.Own, w.Luca, Make.Sha(1), ct));
Assert.AreEqual(copy.Id, (await db.Exports.FindCopiedElsewhereAsync(Make.Sha(1), ExportVariant.Whole, ExportFormat.Original, ct: ct))!.Id);
Assert.AreEqual(copy.Id, (await db.Exports.FindCopiedElsewhereAsync(Make.Sha(1), ct: ct))!.Id);
var byAccount = await db.Exports.ListCandidatesAsync(new ExportSelection.Account(w.Marta), 0, 10, ct);
Assert.AreEqual(w.MartaMedia, byAccount.Single().MediaId);