E4: prove dei video fermi e dimostrazione a ogni ora
Completa l'elenco di prove del progetto: analizzatore (grana, luce che pulsa, foto notturna, contenitori, durata sconosciuta, flussi rovinati), servizio (lavori lunghi, file spariti o cambiati, errori, «Interrompi», chiusura), copie del fotogramma (pausa e ripresa, validazione, video sempre intero), API (selezioni, stesso file, eventi) e l'interfaccia vera nel browser: visualizzatore, «Salva il fotogramma», «Cerca i video fermi», Dashboard e filtro «Video fermi». Le prove hanno trovato che la dimostrazione dipendeva dall'ora: la storia ferma poteva avere la copertina del video fermo di marta (un file solo invece di due) e il video «Non analizzabile» poteva mancare. Ora la storia è su un'altra immagine e, se le immagini senza copie non bastano, si usano quelle di foto copiate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eea4394a0f
commit
066addbc84
10 files changed
+1100
-18
No files matched your search
@@ -343,6 +343,111 @@ public sealed class StillVideosApiTests
|
||||
Assert.IsFalse((await server.GetJsonAsync("/api/still-videos/progress")).Bool("running"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(120_000, CooperativeCancellation = true)]
|
||||
public async Task EverySelectionIsCountedAndTheSameFileIsAnalysedOnce()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var server = await StartAsync();
|
||||
var marta = await AccountAsync(server);
|
||||
var luca = await server.Db.Accounts.AddAsync(Make.Account("luca.demo", "200"));
|
||||
var same = Still(14);
|
||||
var first = await WebLibrary.AddPostAsync(server, marta, "uno", Make.T0.AddDays(-1), WebLibrary.Video(same), WebLibrary.Photo(4), WebLibrary.Photo(5));
|
||||
var twin = (await server.Db.Entries.AddAsync(
|
||||
Make.Entry(marta.Id, "due", Make.T0.AddDays(-2)),
|
||||
[Make.Stored(Make.Video(1), first.Media[0].Sha256!, first.Media[0].RelativePath!)],
|
||||
ct)).Stored;
|
||||
var other = await WebLibrary.AddPostAsync(server, luca, "tre", Make.T0.AddDays(-3), WebLibrary.Video(Moving()));
|
||||
Assert.AreEqual(first.Media[0].Sha256, twin.Media[0].Sha256);
|
||||
|
||||
async Task<JsonElement> PlanAsync(object selection)
|
||||
{
|
||||
var (status, plan) = await server.SendJsonAsync(HttpMethod.Post, "/api/still-videos/plan", selection);
|
||||
Assert.AreEqual(HttpStatusCode.OK, status, plan.ToString());
|
||||
return plan;
|
||||
}
|
||||
|
||||
// The files, the entries, a filter in both modes, an account: one file counts once, the photos are told apart.
|
||||
foreach (var (selection, toAnalyse, photos) in new (object, int, int)[]
|
||||
{
|
||||
(new { mediaIds = new[] { first.Media[0].Id, first.Media[1].Id } }, 1, 1),
|
||||
(new { mediaIds = new[] { first.Media[1].Id, first.Media[2].Id } }, 0, 2),
|
||||
(new { entryIds = new[] { first.Entry.Id, twin.Entry.Id, other.Entry.Id } }, 2, 2),
|
||||
(new { query = $"accounts={marta.Id}", mode = "grouped" }, 1, 2),
|
||||
(new { query = "kind=videos", mode = "files" }, 2, 0),
|
||||
(new { query = "kind=stillvideos", mode = "files" }, 0, 0),
|
||||
(new { accountId = luca.Id }, 1, 0),
|
||||
})
|
||||
{
|
||||
var plan = await PlanAsync(selection);
|
||||
Assert.AreEqual((toAnalyse, photos), (plan.Int("toAnalyse"), plan.Int("photosSkipped")), $"{JsonSerializer.Serialize(selection)}: {plan}");
|
||||
}
|
||||
|
||||
// Photos only: nothing to start, and the job does not.
|
||||
var none = (await server.SendJsonAsync(HttpMethod.Post, "/api/still-videos/start", new { mediaIds = new[] { first.Media[1].Id } })).Body;
|
||||
Assert.AreEqual((false, 0), (none.Bool("running"), none.Int("total")), none.ToString());
|
||||
|
||||
// Analysed once, under either post; the second asks nothing more.
|
||||
Assert.AreEqual(HttpStatusCode.OK, (await server.SendJsonAsync(HttpMethod.Post, "/api/still-videos/start", new { accountId = marta.Id })).Status);
|
||||
await WebLibrary.WaitAsync(async () => !(await server.GetJsonAsync("/api/still-videos/progress")).Bool("running"), "the job ends");
|
||||
Assert.AreEqual(1, (await server.GetJsonAsync("/api/still-videos/progress")).Int("still"));
|
||||
var shown = (await server.GetJsonAsync($"/api/entries/{twin.Entry.Id}")).Items("media").Single().GetProperty("still");
|
||||
Assert.AreEqual("still", shown.Str("outcome"), "the same file under another post has the same analysis");
|
||||
var tiles = (await server.GetJsonAsync("/api/library?kind=stillvideos&limit=50")).Items("tiles").Select(t => t.Long("id")).ToArray();
|
||||
CollectionAssert.AreEquivalent(new[] { first.Entry.Id, twin.Entry.Id }, tiles);
|
||||
Assert.AreEqual(1, (await PlanAsync(new { query = "kind=stillvideos", mode = "grouped" })).Int("alreadyAnalysed"));
|
||||
|
||||
// An analysis of an algorithm newer than this Febe's is current (there is none older than 1 yet).
|
||||
await server.Db.VideoAnalyses.SetAsync(new VideoAnalysis(other.Media[0].Sha256!, StillVideoAnalyzer.Algorithm + 1, VideoAnalysisOutcome.Moving, server.Clock.Now), ct);
|
||||
var newer = (await server.GetJsonAsync($"/api/entries/{other.Entry.Id}")).Items("media").Single().GetProperty("still");
|
||||
Assert.AreEqual(("moving", true), (newer.Str("outcome"), newer.Bool("current")), newer.ToString());
|
||||
Assert.AreEqual(0, (await PlanAsync(new { accountId = luca.Id })).Int("toAnalyse"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(120_000, CooperativeCancellation = true)]
|
||||
public async Task TheFrameOfAPhotoAnUnknownOrAMissingFileIsRefused()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var server = await StartAsync();
|
||||
var marta = await AccountAsync(server);
|
||||
var post = await WebLibrary.AddPostAsync(server, marta, "fermo", Make.T0.AddDays(-1), WebLibrary.Video(Still(15)), WebLibrary.Photo(4));
|
||||
var video = post.Media[0];
|
||||
Assert.AreEqual(HttpStatusCode.OK, (await server.SendJsonAsync(HttpMethod.Post, $"/api/media/{video.Id}/still")).Status);
|
||||
|
||||
Assert.AreEqual(HttpStatusCode.BadRequest, (await server.SendJsonAsync(HttpMethod.Get, $"/api/media/{post.Media[1].Id}/still/frame")).Status);
|
||||
Assert.AreEqual(HttpStatusCode.NotFound, (await server.SendJsonAsync(HttpMethod.Get, "/api/media/999999/still/frame")).Status);
|
||||
|
||||
// Another file in its place: the analysis was of the old one, so there is no frame to save.
|
||||
var sha = video.Sha256!;
|
||||
await server.Db.Media.UpdateAsync((await server.Db.Media.GetAsync(video.Id, ct))! with { Sha256 = Make.Sha(91) }, ct);
|
||||
var (replaced, body) = await server.SendJsonAsync(HttpMethod.Get, $"/api/media/{video.Id}/still/frame");
|
||||
Assert.AreEqual(HttpStatusCode.Conflict, replaced);
|
||||
StringAssert.StartsWith(body.Str("message"), StillVideoText.NotStill);
|
||||
await server.Db.Media.UpdateAsync((await server.Db.Media.GetAsync(video.Id, ct))! with { Sha256 = sha }, ct);
|
||||
|
||||
File.Delete(WebLibrary.PathOf(server, marta, video));
|
||||
Assert.AreEqual(HttpStatusCode.NotFound, (await server.SendJsonAsync(HttpMethod.Get, $"/api/media/{video.Id}/still/frame?download=1")).Status);
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Still, (await server.Db.VideoAnalyses.GetAsync(sha, ct))!.Outcome, "what was found of the file stays");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(120_000, CooperativeCancellation = true)]
|
||||
public async Task TheOpenPagesHearOfAnAnalysisOnce()
|
||||
{
|
||||
await using var server = await StartAsync();
|
||||
var marta = await AccountAsync(server);
|
||||
var video = (await WebLibrary.AddPostAsync(server, marta, "fermo", Make.T0.AddDays(-1), WebLibrary.Video(Still(16)))).Media[0];
|
||||
var changes = server.Changes.SubscribeAsync().GetAsyncEnumerator();
|
||||
var next = changes.MoveNextAsync().AsTask();
|
||||
|
||||
Assert.AreEqual(HttpStatusCode.OK, (await server.SendJsonAsync(HttpMethod.Post, $"/api/media/{video.Id}/still")).Status);
|
||||
|
||||
Assert.IsTrue(await next.WaitAsync(TimeSpan.FromSeconds(20)), "the library of the open pages is read again");
|
||||
Assert.AreEqual(("fermi", (long?)marta.Id), (changes.Current.Reason, changes.Current.AccountId));
|
||||
await changes.DisposeAsync();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------- support
|
||||
|
||||
private static readonly FebeWebOptions Options = new() { Edition = FebeEdition.Desktop, Access = AccessMode.None };
|
||||
|
||||
Reference in new issue
Block a user