feat(server): run on the real archive engine
ArchiveModule registers the archive engine as the server's ingest, its proxy/thumbnail locator and its job handlers (through the new IJobHandlerProvider); Program.cs passes it to ServerHost.Build. The server opens its archive through ArchiveService so archive.json always exists. The server's path-safety helper is renamed ArchivePathGuard to stop clashing with the archive layout's ArchivePaths, and the server migration is renumbered 0003. An end-to-end test uploads a photo, finds it in the layout and fetches the thumbnail built by the queued job. CI's PostgreSQL jobs now run the server tests too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
15 files changed
+150
-22
No files matched your search
@@ -0,0 +1,52 @@
|
||||
using System.Net;
|
||||
using Titano.Core.Archiving;
|
||||
using Titano.Core.Codecs.Jpeg;
|
||||
using Titano.Server.Storage;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Server.Tests.Storage;
|
||||
|
||||
/// <summary>The production composition: uploads committed by the real archive engine, thumbnails built by its job.</summary>
|
||||
[Category("server")]
|
||||
public sealed class ArchiveModuleTests(TestContext context)
|
||||
{
|
||||
[Test]
|
||||
public async Task UploadsLandInTheArchiveLayoutAndGetThumbnails()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register);
|
||||
var (editor, _, _) = await server.UserAsync("alberto", "editor");
|
||||
var photo = Photo();
|
||||
|
||||
var frame = await Uploads.UploadAsync(editor, photo, "IMG_0001.JPG", sessionKey: "roof");
|
||||
|
||||
var row = Assert.NotNull(await server.Database.Frames.GetAsync(frame.FrameId));
|
||||
var sequence = Assert.NotNull(await server.Database.Sequences.GetAsync(frame.SequenceId));
|
||||
var paths = new ArchivePaths(server.Options.ArchivePath).Sequence(sequence.Folder);
|
||||
Assert.True(File.Exists(paths.ManifestPath), "sequence.json");
|
||||
Assert.SequenceEqual(photo, await File.ReadAllBytesAsync(Path.Combine(server.Options.ArchivePath, row.RelativePath)));
|
||||
Assert.Count(0, Directory.GetFiles(Path.Combine(server.Options.ArchivePath, ".titano", "staging")));
|
||||
|
||||
// The commit queues a thumbnail job; its handler comes from the archive module.
|
||||
var until = DateTime.UtcNow + TimeSpan.FromSeconds(30);
|
||||
while (true)
|
||||
{
|
||||
using var thumb = await editor.GetAsync($"/api/v1/frames/{frame.FrameId}/thumb");
|
||||
if (thumb.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
var jpeg = await thumb.Content.ReadAsByteArrayAsync();
|
||||
Assert.True(jpeg is [0xFF, 0xD8, ..], "a JPEG thumbnail");
|
||||
break;
|
||||
}
|
||||
Assert.True(DateTime.UtcNow < until, $"thumbnail not built: {(int)thumb.StatusCode}");
|
||||
await Task.Delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] Photo()
|
||||
{
|
||||
const int width = 96, height = 64;
|
||||
var pixels = new byte[width * height * 3];
|
||||
for (var i = 0; i < pixels.Length; i++) pixels[i] = (byte)(i * 7 % 251);
|
||||
return JpegEncoder.Encode(pixels, width, height, 3, new JpegEncodeOptions { Quality = 90 });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user