E4: copie del fotogramma con il loro nome, eventi che non si perdono, visualizzatore che si chiude
«Copia di nuovo» di un _fotogramma lo rifaceva come _t…, e un lavoro in attesa prendeva un istante del file vecchio. Un'analisi copriva l'evento di una copia finita; il visualizzatore restava sopra la pagina nuova e poteva mostrare un esito superato; la scheda Esportazione perdeva il fuoco a ogni rilettura. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6dcaf30db6
commit
2c0cfcccf2
17 files changed
+301
-35
No files matched your search
@@ -122,4 +122,17 @@ public sealed class ExportFrameNamesTests
|
||||
Assert.HasCount(1, asIs.Notes);
|
||||
StringAssert.StartsWith(asIs.Notes[0], MediaConversionResult.AsIsNotRemuxable + ":");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow("marta/post/a_fotogramma.png", true)]
|
||||
[DataRow("a_fotogramma (2).webp", true)]
|
||||
[DataRow("a_fotogramma (12).jpg", true)]
|
||||
[DataRow("a_t0m01s125.png", false)]
|
||||
[DataRow("a_fotogramma_t0m01s125.png", false)]
|
||||
[DataRow("a_fotogramma_f001.png", false)]
|
||||
[DataRow("a fotogramma.png", false)]
|
||||
[DataRow("a_fotogramma (x).png", false)]
|
||||
[DataRow(null, false)]
|
||||
public void TheNameOfSalvaIlFotogrammaIsKnownAgain(string? path, bool single) =>
|
||||
Assert.AreEqual(single, ExportFrames.IsSingleName(path));
|
||||
}
|
||||
@@ -345,6 +345,53 @@ public sealed class ExportFramesTests
|
||||
Assert.HasCount(1, Fingerprint.Of(bed.Usb));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(null)]
|
||||
[DataRow(VideoAnalysisOutcome.Moving)]
|
||||
[DataRow(VideoAnalysisOutcome.Still)]
|
||||
public async Task AFrameWaitingForAFileThatChangedIsTheOneOfTheNewAnalysisOrNone(VideoAnalysisOutcome? now)
|
||||
{
|
||||
// The job waited (disk full) while the file was replaced: the instant was chosen on the old one, so it would save
|
||||
// any frame of the new one, whatever it is.
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync();
|
||||
var video = (await SaveVideoAsync(bed, bed.Marta, "984", Mp4, ".mp4")).Media[0];
|
||||
var usb = await bed.GeneralAsync(ct: ct);
|
||||
await bed.Db.VideoAnalyses.SetAsync(new VideoAnalysis(video.Sha256!, 1, VideoAnalysisOutcome.Still, Make.T0, TimeSpan.FromMilliseconds(400)), ct);
|
||||
bed.Disk.Free = 0;
|
||||
var start = await bed.CopyAsync(Frames(video, new ExportFramesRequest(FrameMode.Still, null, null, null, ExportFormat.Png)), ct);
|
||||
|
||||
byte[] other = [.. Mp4, 0, 0, 0, 8, (byte)'f', (byte)'r', (byte)'e', (byte)'e'];
|
||||
var sha = Convert.ToHexStringLower(System.Security.Cryptography.SHA256.HashData(other));
|
||||
await File.WriteAllBytesAsync(bed.Library.Layout.FullPath(bed.Marta, video.RelativePath!), other, ct);
|
||||
await bed.Db.Media.UpdateAsync((await bed.Db.Media.GetAsync(video.Id, ct))! with { Sha256 = sha, Bytes = other.Length }, ct);
|
||||
var at = TimeSpan.FromMilliseconds(100);
|
||||
if (now is { } outcome)
|
||||
{
|
||||
await bed.Db.VideoAnalyses.SetAsync(new VideoAnalysis(sha, 1, outcome, Make.T0, outcome == VideoAnalysisOutcome.Still ? at : null), ct);
|
||||
}
|
||||
|
||||
bed.Disk.Free = null;
|
||||
await bed.Service.ResumeAsync([start.Runs.Single().Id], ct);
|
||||
await bed.Service.WaitAsync(ct);
|
||||
var run = await bed.RunAsync(start.Runs.Single().Id, ct);
|
||||
Assert.AreEqual(ExportRunState.Completed, run.State, run.LastError);
|
||||
var item = (await bed.ItemsAsync(start.Runs.Single().Id, ct)).Single();
|
||||
if (now == VideoAnalysisOutcome.Still)
|
||||
{
|
||||
var copy = (await bed.Db.Exports.ListCopiesAsync(usb.Id, ct: ct)).Single();
|
||||
Assert.AreEqual((ExportItemState.Copied, sha), (item.State, copy.SourceSha256), item.LastError);
|
||||
Assert.AreEqual(TimeSpan.FromMilliseconds(ExportFrames.ActualMs(Locate(other, [at]).Single().Actual)), copy.FrameAt);
|
||||
StringAssert.EndsWith(copy.RelativePath, "_fotogramma.png");
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.AreEqual((ExportItemState.Skipped, ExportText.Notes.NotStill), (item.State, item.Note));
|
||||
StringAssert.Contains(ExportText.Note(item.Note), "Il video è cambiato");
|
||||
Assert.IsEmpty(Fingerprint.Of(bed.Usb));
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task OnlyAStillVideoGivesItsFrameAndACopyIsAlwaysTheWholeVideo()
|
||||
{
|
||||
|
||||
@@ -113,6 +113,12 @@ public sealed class StillVideosApiTests
|
||||
var (slowStatus, slowBody) = await slow.SendJsonAsync(HttpMethod.Post, $"/api/media/{video.Id}/still");
|
||||
Assert.AreEqual((HttpStatusCode.ServiceUnavailable, StillVideoText.TooSlow), (slowStatus, slowBody.Str("message")));
|
||||
Assert.IsNull(await slow.Db.VideoAnalyses.GetAsync(video.Sha256!, ct));
|
||||
|
||||
// Analysed before: the selection would skip it, so the answer does not send there.
|
||||
await slow.Db.VideoAnalyses.SetAsync(new VideoAnalysis(video.Sha256!, StillVideoAnalyzer.Algorithm, VideoAnalysisOutcome.Moving, slow.Clock.Now), ct);
|
||||
var (keptStatus, keptBody) = await slow.SendJsonAsync(HttpMethod.Post, $"/api/media/{video.Id}/still");
|
||||
Assert.AreEqual(HttpStatusCode.ServiceUnavailable, keptStatus);
|
||||
StringAssert.StartsWith(keptBody.Str("message"), StillVideoText.TooSlowKept);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -241,6 +247,49 @@ public sealed class StillVideosApiTests
|
||||
Assert.HasCount(2, Directory.GetFiles(usb, "*_fotogramma*.png", SearchOption.AllDirectories));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(180_000, CooperativeCancellation = true)]
|
||||
public async Task CopiaDiNuovoKeepsTheNameFotogramma()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var server = await StartAsync();
|
||||
var marta = await AccountAsync(server);
|
||||
var still = (await WebLibrary.AddPostAsync(server, marta, "fermo", Make.T0.AddDays(-1), WebLibrary.Video(FadeInStill(10)))).Media[0];
|
||||
var usb = server.Temp.Combine("usb");
|
||||
Directory.CreateDirectory(usb);
|
||||
var destinationId = (await server.SendJsonAsync(HttpMethod.Post, "/api/export/destinations", WebLibrary.Destination(usb))).Body.GetProperty("destination").Long("id");
|
||||
Assert.AreEqual(HttpStatusCode.OK, (await server.SendJsonAsync(HttpMethod.Post, $"/api/media/{still.Id}/still")).Status);
|
||||
await WebLibrary.StartAndWaitAsync(server, new { mediaIds = new[] { still.Id }, frames = new { mode = "fermo", format = "png" } });
|
||||
|
||||
async Task<ExportCopy> AgainAsync()
|
||||
{
|
||||
var copy = (await server.Db.Exports.ListCopiesAsync(destinationId, ExportCopyState.Copied, 0, 10, ct)).Single();
|
||||
File.Delete(Path.Combine(usb, LibraryLayout.ToPlatform(copy.RelativePath!)));
|
||||
await server.Db.Exports.UpdateCopyAsync(copy with { State = ExportCopyState.Removed, StateChangedAt = server.Clock.Now }, ct);
|
||||
var (status, job) = await server.SendJsonAsync(HttpMethod.Post, "/api/export/copy-again", new { copyId = copy.Id });
|
||||
Assert.AreEqual(HttpStatusCode.OK, status, job.ToString());
|
||||
await WebLibrary.WaitIdleAsync(server);
|
||||
var again = (await server.Db.Exports.ListCopiesAsync(destinationId, ExportCopyState.Copied, 0, 10, ct)).Single();
|
||||
Assert.AreEqual((copy.FrameAt, copy.Format), (again.FrameAt, again.Format));
|
||||
Assert.IsTrue(File.Exists(Path.Combine(usb, LibraryLayout.ToPlatform(again.RelativePath!))), again.RelativePath);
|
||||
return again;
|
||||
}
|
||||
|
||||
var first = await AgainAsync();
|
||||
StringAssert.EndsWith(first.RelativePath, "_fotogramma.png", "not the name of «Questo istante»");
|
||||
|
||||
// A file of that name that Febe did not write: the number, and «Copia di nuovo» of the numbered one too.
|
||||
var taken = Path.Combine(usb, LibraryLayout.ToPlatform(first.RelativePath!));
|
||||
File.Delete(taken);
|
||||
await server.Db.Exports.UpdateCopyAsync(first with { State = ExportCopyState.Removed, StateChangedAt = server.Clock.Now }, ct);
|
||||
await File.WriteAllBytesAsync(taken, [1, 2, 3], ct);
|
||||
Assert.AreEqual(HttpStatusCode.OK, (await server.SendJsonAsync(HttpMethod.Post, "/api/export/copy-again", new { copyId = first.Id })).Status);
|
||||
await WebLibrary.WaitIdleAsync(server);
|
||||
StringAssert.EndsWith((await server.Db.Exports.ListCopiesAsync(destinationId, ExportCopyState.Copied, 0, 10, ct)).Single().RelativePath, "_fotogramma (2).png");
|
||||
StringAssert.EndsWith((await AgainAsync()).RelativePath, "_fotogramma (2).png");
|
||||
CollectionAssert.AreEqual(new byte[] { 1, 2, 3 }, await File.ReadAllBytesAsync(taken, ct), "never overwritten");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(180_000, CooperativeCancellation = true)]
|
||||
public async Task CercaIVideoFermiCountsWaitsStopsAndEnds()
|
||||
@@ -266,7 +315,9 @@ public sealed class StillVideosApiTests
|
||||
session.InSession = true;
|
||||
Assert.AreEqual(StillVideoText.InSession, (await server.SendJsonAsync(HttpMethod.Post, "/api/still-videos/plan", selection)).Body.Str("waiting"));
|
||||
var started = (await server.SendJsonAsync(HttpMethod.Post, "/api/still-videos/start", selection)).Body;
|
||||
Assert.AreEqual((true, 2), (started.Bool("running"), started.Int("total")), started.ToString());
|
||||
Assert.AreEqual((true, 2, 2), (started.Bool("running"), started.Int("total"), started.Int("added")), started.ToString());
|
||||
var twice = (await server.SendJsonAsync(HttpMethod.Post, "/api/still-videos/start", selection)).Body;
|
||||
Assert.AreEqual((true, 2, 0), (twice.Bool("running"), twice.Int("total"), twice.Int("added")), "queued already: nothing added");
|
||||
await WebLibrary.WaitAsync(async () => (await server.GetJsonAsync("/api/still-videos/progress")).Str("waiting") == StillVideoText.InSession, "the job waits for the session");
|
||||
var stopped = (await server.SendJsonAsync(HttpMethod.Post, "/api/still-videos/stop")).Body;
|
||||
Assert.IsTrue(stopped.Bool("stopped"));
|
||||
@@ -448,6 +499,75 @@ public sealed class StillVideosApiTests
|
||||
await changes.DisposeAsync();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(60_000, CooperativeCancellation = true)]
|
||||
public async Task AChangeFollowedAtOnceByAnAnalysisIsNotLost()
|
||||
{
|
||||
// The Dashboard and the accounts skip «fermi»: during «Cerca i video fermi» a copy that ends must still reach them.
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var server = await StartAsync();
|
||||
using var request = new HttpRequestMessage(HttpMethod.Get, "/api/eventi");
|
||||
request.Headers.TryAddWithoutValidation("Sec-Fetch-Site", "same-origin");
|
||||
using var response = await server.Client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, ct);
|
||||
using var reader = new StreamReader(await response.Content.ReadAsStreamAsync(ct));
|
||||
using var done = CancellationTokenSource.CreateLinkedTokenSource(ct);
|
||||
|
||||
// Again and again: the stream may not be listening to the library yet when its first line comes.
|
||||
var publishing = Task.Run(
|
||||
async () =>
|
||||
{
|
||||
while (!done.IsCancellationRequested)
|
||||
{
|
||||
server.Changes.Publish(new LibraryChange(server.Clock.Now, null, "export"));
|
||||
for (var i = 1; i <= 40; i++)
|
||||
{
|
||||
server.Changes.Publish(new LibraryChange(server.Clock.Now, i, "fermi"));
|
||||
}
|
||||
|
||||
await Task.Delay(3000, done.Token).ContinueWith(_ => { }, TaskScheduler.Default);
|
||||
}
|
||||
},
|
||||
CancellationToken.None);
|
||||
|
||||
var reasons = new HashSet<string>();
|
||||
var library = false;
|
||||
while (reasons.Count < 2 && await reader.ReadLineAsync(ct) is { } line)
|
||||
{
|
||||
if (line.StartsWith("event: ", StringComparison.Ordinal))
|
||||
{
|
||||
library = line == "event: libreria";
|
||||
}
|
||||
else if (library && line.StartsWith("data: ", StringComparison.Ordinal))
|
||||
{
|
||||
using var json = JsonDocument.Parse(line[6..]);
|
||||
reasons.Add(json.RootElement.Str("reason"));
|
||||
}
|
||||
}
|
||||
|
||||
await done.CancelAsync();
|
||||
await publishing;
|
||||
CollectionAssert.AreEquivalent(new[] { "export", "fermi" }, reasons.ToArray());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PendingChangesKeepOneForEachReason()
|
||||
{
|
||||
var pending = new PendingLibraryChanges();
|
||||
Assert.IsFalse(pending.Any);
|
||||
pending.Add(new LibraryChange(Make.T0, 1, "stored"));
|
||||
pending.Add(new LibraryChange(Make.T0.AddSeconds(1), 2, "export"));
|
||||
pending.Add(new LibraryChange(Make.T0.AddSeconds(2), 1, "fermi"));
|
||||
pending.Add(new LibraryChange(Make.T0.AddSeconds(3), 1, "stored"));
|
||||
pending.Add(new LibraryChange(Make.T0.AddSeconds(4), 3, "fermi"));
|
||||
Assert.IsTrue(pending.Any);
|
||||
CollectionAssert.AreEqual(
|
||||
new[] { ("export", (long?)2), ("stored", 1), ("fermi", null) },
|
||||
pending.Take().Select(c => (c.Reason, c.AccountId)).ToArray(),
|
||||
"the account only if it is the same");
|
||||
Assert.IsFalse(pending.Any);
|
||||
Assert.IsEmpty(pending.Take());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------- support
|
||||
|
||||
private static readonly FebeWebOptions Options = new() { Edition = FebeEdition.Desktop, Access = AccessMode.None };
|
||||
|
||||
Reference in new issue
Block a user