merge: third-pass archive, image and analysis fixes (W-1, W-5, W-7, W-13, W-14)
Merge branch fix3/data-images into the verification branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
23 files changed
+1132
-169
No files matched your search
@@ -1,8 +1,11 @@
|
||||
using System.Net;
|
||||
using System.Security.Cryptography;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Titano.Core.Archiving;
|
||||
using Titano.Core.Codecs.Jpeg;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Data;
|
||||
using Titano.Data.Archiving;
|
||||
using Titano.Protocol;
|
||||
using Titano.Protocol.Client;
|
||||
using Titano.Server.Jobs;
|
||||
@@ -106,6 +109,74 @@ public sealed class ArchiveModuleTests(TestContext context)
|
||||
await UntilImagesAsync(server, editor, archive.Id, "garden");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FramesADesktopSharingTheArchiveAddsToASequenceGetThumbnailsAndProxiesAfterThePoll()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context, options =>
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(options.ArchivePath, "roof"));
|
||||
File.WriteAllBytes(Path.Combine(options.ArchivePath, "roof", "IMG_0002.JPG"), Photo());
|
||||
}, ArchiveModule.Register);
|
||||
var archive = server.Services.GetRequiredService<ServerArchive>();
|
||||
var (editor, _, _) = await server.UserAsync("alberto", "editor");
|
||||
await UntilIndexedAsync(server, archive.Id, "roof");
|
||||
await UntilScannedAsync(server);
|
||||
await UntilImagesAsync(server, editor, archive.Id, "roof");
|
||||
await UntilIdleAsync(server);
|
||||
var roof = (await server.Database.Sequences.ListLocationsAsync(archive.Id)).Single(l => l.Folder == "roof");
|
||||
|
||||
// A desktop sharing the archive, with an index of its own, imports a photo taken earlier into the sequence: it files
|
||||
// the photo and lists it in the sidecar itself, keeping the sidecar's ThumbsBuilt and ProxiesBuilt.
|
||||
var desktopFolder = context.CreateTempDirectory("desktop");
|
||||
await using (var desktopIndex = await TitanoDatabase.OpenAsync(DatabaseOptions.Sqlite(Path.Combine(desktopFolder, "titano.db")), context.Cancellation))
|
||||
{
|
||||
var desktop = new ArchiveService(desktopIndex, new ArchiveServiceOptions { Owner = "desktop" });
|
||||
var shared = await desktop.OpenAsync(server.Options.ArchivePath, context.Cancellation);
|
||||
await desktop.Indexer.ScanAsync(shared, ScanMode.Incremental, null, _ => ValueTask.CompletedTask, context.Cancellation);
|
||||
var photo = Photo(seed: 5);
|
||||
var staged = Path.Combine(desktopFolder, "IMG_0001.JPG");
|
||||
await File.WriteAllBytesAsync(staged, photo);
|
||||
await desktop.Ingest.CommitAsync(new IngestRequest(shared.Id, roof.Id, null, null, staged, "IMG_0001.JPG", photo.Length,
|
||||
Convert.ToHexStringLower(SHA256.HashData(photo)), new DateTime(2026, 9, 28, 18, 0, 0), null), context.Cancellation);
|
||||
}
|
||||
Assert.Equal(1, Assert.NotNull(await server.Database.Sequences.GetAsync(roof.Id)).FrameCount);
|
||||
|
||||
// The next poll indexes it and queues the images: the new frame and the one it moved get theirs.
|
||||
Assert.NotNull(await server.Services.GetRequiredService<ArchivePolling>().PollAsync(context.Cancellation));
|
||||
await UntilScannedAsync(server);
|
||||
Assert.Equal(2, Assert.NotNull(await server.Database.Sequences.GetAsync(roof.Id)).FrameCount);
|
||||
await UntilImagesAsync(server, editor, archive.Id, "roof");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AThumbnailDrawnBeforeAVerifyHashedThePhotoIsStillServed()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context, options =>
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(options.ArchivePath, "roof"));
|
||||
File.WriteAllBytes(Path.Combine(options.ArchivePath, "roof", "IMG_0001.JPG"), Photo());
|
||||
}, ArchiveModule.Register);
|
||||
var archive = server.Services.GetRequiredService<ServerArchive>();
|
||||
var (editor, _, _) = await server.UserAsync("alberto", "editor");
|
||||
await UntilIndexedAsync(server, archive.Id, "roof");
|
||||
await UntilScannedAsync(server);
|
||||
await UntilImagesAsync(server, editor, archive.Id, "roof");
|
||||
await UntilIdleAsync(server);
|
||||
var roof = (await server.Database.Sequences.ListLocationsAsync(archive.Id)).Single(l => l.Folder == "roof");
|
||||
var frame = (await server.Database.Frames.ListBySequenceAsync(roof.Id)).Single();
|
||||
Assert.Null(frame.Sha256);
|
||||
|
||||
// A verify gives the photo the scan adopted its first hash; the thumbnail drawn from it before is still its own.
|
||||
var verified = await server.Services.GetRequiredService<ArchiveService>().Verifier.VerifyAsync(
|
||||
Assert.NotNull(await server.Database.Archives.GetAsync(archive.Id)), [roof.Id], default, (_, _, _) => ValueTask.CompletedTask, null,
|
||||
context.Cancellation);
|
||||
Assert.Equal(1L, verified.Hashed);
|
||||
Assert.NotNull(Assert.NotNull(await server.Database.Frames.GetAsync(frame.Id)).Sha256);
|
||||
using var thumb = await editor.GetAsync($"/api/v1/frames/{frame.Id}/thumb");
|
||||
Assert.Equal(HttpStatusCode.OK, thumb.StatusCode);
|
||||
Assert.True(Assert.NotNull(await server.Database.Sequences.GetAsync(roof.Id)).Status.HasFlag(SequenceStatus.ThumbsBuilt), "built");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SettingsADesktopChangedInArchiveJsonReachUploadsAndTheAdminPanel()
|
||||
{
|
||||
@@ -157,28 +228,51 @@ public sealed class ArchiveModuleTests(TestContext context)
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Waits until the first frame of the sequence in <paramref name="folder"/> has its thumbnail and proxy served.</summary>
|
||||
/// <summary>
|
||||
/// Waits until every frame of the sequence in <paramref name="folder"/> has its thumbnail and proxy served and the
|
||||
/// passes that made them have marked the sequence (a pass writes its files before it marks).
|
||||
/// </summary>
|
||||
private static async Task UntilImagesAsync(TestServer server, HttpClient client, Guid archiveId, string folder)
|
||||
{
|
||||
var sequence = (await server.Database.Sequences.ListLocationsAsync(archiveId)).Single(l => l.Folder == folder);
|
||||
var frame = (await server.Database.Frames.ListBySequenceAsync(sequence.Id)).First();
|
||||
var until = DateTime.UtcNow + TimeSpan.FromSeconds(30);
|
||||
foreach (var asset in new[] { "thumb", "proxy" })
|
||||
foreach (var frame in await server.Database.Frames.ListBySequenceAsync(sequence.Id))
|
||||
{
|
||||
while (true)
|
||||
foreach (var asset in new[] { "thumb", "proxy" })
|
||||
{
|
||||
using var response = await client.GetAsync($"/api/v1/frames/{frame.Id}/{asset}");
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
while (true)
|
||||
{
|
||||
Assert.True(await response.Content.ReadAsByteArrayAsync() is [0xFF, 0xD8, ..], $"a JPEG {asset} of {folder}");
|
||||
break;
|
||||
using var response = await client.GetAsync($"/api/v1/frames/{frame.Id}/{asset}");
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
Assert.True(await response.Content.ReadAsByteArrayAsync() is [0xFF, 0xD8, ..], $"a JPEG {asset} of {frame.FileName}");
|
||||
break;
|
||||
}
|
||||
Assert.True(DateTime.UtcNow < until, $"no {asset} of {frame.FileName} in {folder}: {(int)response.StatusCode}");
|
||||
await Task.Delay(100);
|
||||
}
|
||||
Assert.True(DateTime.UtcNow < until, $"no {asset} of {folder}: {(int)response.StatusCode}");
|
||||
await Task.Delay(100);
|
||||
}
|
||||
}
|
||||
var built = Assert.NotNull(await server.Database.Sequences.GetAsync(sequence.Id)).Status;
|
||||
Assert.True(built.HasFlag(SequenceStatus.ThumbsBuilt) && built.HasFlag(SequenceStatus.ProxiesBuilt), $"{folder}: {built}");
|
||||
while (Assert.NotNull(await server.Database.Sequences.GetAsync(sequence.Id)).Status is var built
|
||||
&& !(built.HasFlag(SequenceStatus.ThumbsBuilt) && built.HasFlag(SequenceStatus.ProxiesBuilt)))
|
||||
{
|
||||
Assert.True(DateTime.UtcNow < until, $"{folder}: {built}");
|
||||
await Task.Delay(50);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Waits until no job is waiting or running.</summary>
|
||||
private static async Task UntilIdleAsync(TestServer server)
|
||||
{
|
||||
var until = DateTime.UtcNow + TimeSpan.FromSeconds(30);
|
||||
foreach (var state in new[] { JobState.Queued, JobState.Running, JobState.Queued })
|
||||
{
|
||||
while ((await server.Database.Jobs.ListAsync(state)).Items.Count > 0)
|
||||
{
|
||||
Assert.True(DateTime.UtcNow < until, $"jobs still {state}");
|
||||
await Task.Delay(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Waits for the scan queued at start to finish: its sequences are indexed before it ends.</summary>
|
||||
|
||||
Reference in new issue
Block a user