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:
Alby96andClaude Opus 5.5 committed 2026-12-01 18:57:58 +01:00
1 parent 6dcaf30db6
commit 2c0cfcccf2
17 files changed
+301 -35

No files matched your search

+121 -1
View File
@@ -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 };