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

@@ -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);