merge: proxy and decode-tier fixes (V-1, V-24, V-25, V-26, V-27, V-28)
Merge branch fix2/proxies-tiers 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:
28 files changed
+1049
-92
No files matched your search
@@ -32,10 +32,14 @@ public sealed class RemoteEditingTests(TestContext context)
|
||||
var sequence = (await server.Database.Sequences.GetAsync(frame.SequenceId))!;
|
||||
var path = new ArchivePaths(server.Options.ArchivePath).Sequence(sequence.Folder).AnalysisPath;
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||
const string report = """{"version":1,"frameCount":1}""";
|
||||
var report = Reports.Minimal(1).ToJson();
|
||||
await File.WriteAllTextAsync(path, report, context.Cancellation);
|
||||
Assert.Equal(report, await client.GetAnalysisReportAsync(frame.SequenceId, context.Cancellation));
|
||||
|
||||
// One made for other frames is not this sequence's report.
|
||||
await File.WriteAllTextAsync(path, Reports.Minimal(2).ToJson(), context.Cancellation);
|
||||
Assert.Null(await client.GetAnalysisReportAsync(frame.SequenceId, context.Cancellation), "another frame count");
|
||||
|
||||
var gone = await Assert.ThrowsAsync<TitanoApiException>(() => client.GetAnalysisReportAsync(Guid.CreateVersion7(), context.Cancellation));
|
||||
Assert.Equal(HttpStatusCode.NotFound, gone.Status);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using Titano.Core.Analysis.Deep;
|
||||
|
||||
namespace Titano.Server.Tests;
|
||||
|
||||
/// <summary>Deep-analysis reports as a server keeps them in <c>.titano/analysis.json</c>.</summary>
|
||||
internal static class Reports
|
||||
{
|
||||
/// <summary>A report of <paramref name="frames"/> frames that found <paramref name="undecodable"/> unreadable and measured nothing else.</summary>
|
||||
public static DeepAnalysisReport Minimal(int frames, params int[] undecodable) => new()
|
||||
{
|
||||
FrameCount = frames,
|
||||
Flicker = new FlickerSummary(0, 0, null, 0, 0, 1),
|
||||
Exposure = new ExposureSummary(0, 0, null, null, 0, []),
|
||||
WhiteBalance = new WhiteBalanceSummary(0, 0, null, null),
|
||||
Shake = new ShakeSummary(0, 0, 0, 0, false, 0),
|
||||
Motion = new MotionSummary(0, null, null, null),
|
||||
Sky = new SkySummary(DayNight.Unknown, 0, 0, 0, null, false, null),
|
||||
Issues = new FrameIssues(undecodable, [], [], [], []),
|
||||
};
|
||||
}
|
||||
@@ -63,6 +63,28 @@ public sealed class ProcessingModuleTests(TestContext context)
|
||||
Assert.Contains(Drain(events), e => e is SequenceChangedEvent { Change: "settings" } changed && changed.SequenceId == sequenceId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AProxyThatArrivesHasTheSequenceAnalysedAgain()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context, services: Production);
|
||||
var (editor, _, _) = await server.UserAsync("alberto", "editor");
|
||||
// A HEIF original the server cannot decode (BRIEF §2.3): what it renders depends on the proxy a client sends.
|
||||
var upload = await Uploads.UploadAsync(editor, [0, 0, 0, 24, .. "ftypheic"u8, 0, 0, 0, 0, .. "mif1heic"u8, .. Uploads.Photo(2000, 1)], "IMG_0001.HEIC",
|
||||
sessionKey: "roof");
|
||||
await LightAnalysesAsync(server, upload.SequenceId, 1);
|
||||
var frame = Assert.NotNull(await server.Database.Frames.GetAsync(upload.FrameId));
|
||||
|
||||
using var image = new Core.Imaging.ImageBuffer(320, 240);
|
||||
var exif = ExifWriter.BuildJpegApp1(new FrameMetadata { CapturedAt = frame.CapturedAt, Software = "Titano" });
|
||||
using var proxy = new ByteArrayContent(JpegEncoder.Encode(image, new JpegEncodeOptions { App1Segments = [exif[4..]] }));
|
||||
proxy.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/jpeg");
|
||||
using (var stored = await editor.PutAsync($"/api/v1/frames/{frame.Id}/proxy", proxy))
|
||||
await stored.ExpectAsync(HttpStatusCode.NoContent);
|
||||
|
||||
// A frame read from its proxy is no longer preview-only, so the advisor's Auto values are worked out again.
|
||||
await LightAnalysesAsync(server, upload.SequenceId, 2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheServerRendersManagedFormatsAndLeavesMp4ToRenderNodes()
|
||||
{
|
||||
@@ -196,6 +218,19 @@ public sealed class ProcessingModuleTests(TestContext context)
|
||||
return drained;
|
||||
}
|
||||
|
||||
/// <summary>Waits until <paramref name="count"/> light analyses of the sequence have finished.</summary>
|
||||
private static async Task LightAnalysesAsync(TestServer server, Guid sequenceId, int count)
|
||||
{
|
||||
var until = DateTime.UtcNow + TimeSpan.FromSeconds(30);
|
||||
while (true)
|
||||
{
|
||||
var done = (await server.Database.Jobs.ListAsync(JobState.Done, JobKind.LightAnalyse, 200)).Items.Count(j => j.TargetIds.Contains(sequenceId));
|
||||
if (done >= count) return;
|
||||
Assert.True(DateTime.UtcNow < until, $"light analyses finished: {done} of {count}");
|
||||
await Task.Delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Uploads a synthetic scene with Exif into one new sequence; returns its id.</summary>
|
||||
private static async Task<Guid> UploadSceneAsync(HttpClient editor)
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Net.Http.Headers;
|
||||
using Titano.Core.Codecs.Jpeg;
|
||||
using Titano.Core.Imaging;
|
||||
using Titano.Core.Metadata;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Protocol;
|
||||
using Titano.Server.Storage;
|
||||
using Titano.Testing;
|
||||
@@ -62,6 +63,94 @@ public sealed class ProxyUploadTests(TestContext context)
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnotherPhotosProxyInTheFramesPlaceIsAskedForAgainAndNeverServed()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register);
|
||||
var (editor, _, _) = await server.UserAsync("alberto", "editor");
|
||||
var upload = await Uploads.UploadAsync(editor, Heif(1), "IMG_0001.HEIC", sessionKey: "roof");
|
||||
var frame = Assert.NotNull(await server.Database.Frames.GetAsync(upload.FrameId));
|
||||
var sequence = Assert.NotNull(await server.Database.Sequences.GetAsync(upload.SequenceId));
|
||||
// Proxies are named by frame index: after a frame was inserted before this one, its place holds another photo's.
|
||||
var path = new Core.Archiving.ArchivePaths(server.Options.ArchivePath).Sequence(sequence.Folder).Proxy(frame.Index);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||
await File.WriteAllBytesAsync(path, Proxy(frame.CapturedAt!.Value.AddSeconds(-10)));
|
||||
|
||||
Assert.Equal((true, false), Wanted((await ManifestAsync(editor, upload.SequenceId)).Frames.Single()));
|
||||
using (var served = await editor.GetAsync($"/api/v1/frames/{frame.Id}/proxy"))
|
||||
Assert.Equal("asset_missing", (await served.ExpectErrorAsync(HttpStatusCode.NotFound, "not_found")).Details);
|
||||
|
||||
// The frame's own proxy takes its place.
|
||||
var proxy = Proxy(frame.CapturedAt!.Value);
|
||||
using (var stored = await PutAsync(editor, frame.Id, proxy))
|
||||
await stored.ExpectAsync(HttpStatusCode.NoContent);
|
||||
Assert.Equal((false, true), Wanted((await ManifestAsync(editor, upload.SequenceId)).Frames.Single()));
|
||||
await Http.BytesEqualAsync(proxy, editor.GetByteArrayAsync($"/api/v1/frames/{frame.Id}/proxy"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FramesAddedAfterEveryProxyArrivedAreAskedForTheirs()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register);
|
||||
var (editor, _, _) = await server.UserAsync("alberto", "editor");
|
||||
var first = await Uploads.UploadAsync(editor, Heif(1), "IMG_0001.HEIC", sessionKey: "roof");
|
||||
var frame = Assert.NotNull(await server.Database.Frames.GetAsync(first.FrameId));
|
||||
using (var stored = await PutAsync(editor, frame.Id, Proxy(frame.CapturedAt!.Value)))
|
||||
await stored.ExpectAsync(HttpStatusCode.NoContent);
|
||||
|
||||
// A frame comes after the proxy pass found every proxy there: until the next pass the status still says so, yet
|
||||
// the new frame is asked for its proxy and the first keeps its own.
|
||||
var second = await Uploads.UploadAsync(editor, Heif(2), "IMG_0002.HEIC", sessionKey: "roof");
|
||||
Assert.Equal(first.SequenceId, second.SequenceId);
|
||||
await server.Database.Sequences.UpdateStatusAsync(first.SequenceId, SequenceStatus.ProxiesBuilt, SequenceStatus.None, context.Cancellation);
|
||||
var frames = (await ManifestAsync(editor, first.SequenceId)).Frames;
|
||||
Assert.Equal((false, true), Wanted(frames.Single(f => f.Id == first.FrameId)));
|
||||
Assert.Equal((true, false), Wanted(frames.Single(f => f.Id == second.FrameId)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AProxyTheServerMadeIsServedForAFrameTimedToTheTick()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register);
|
||||
var (editor, _, _) = await server.UserAsync("alberto", "editor");
|
||||
// Seven sub-second digits: the sidecar, and the proxy made from it, keep them all; the index keeps six.
|
||||
var upload = await Uploads.UploadAsync(editor, Proxy(new DateTime(2026, 9, 28, 18, 2, 11).AddTicks(1_234_567)), "IMG_0001.JPG", sessionKey: "roof");
|
||||
|
||||
// The proxy pass the upload queued makes the frame's proxy, and the server serves it.
|
||||
var until = DateTime.UtcNow + TimeSpan.FromSeconds(30);
|
||||
while (true)
|
||||
{
|
||||
using var proxy = await editor.GetAsync($"/api/v1/frames/{upload.FrameId}/proxy");
|
||||
if (proxy.StatusCode == HttpStatusCode.OK) break;
|
||||
Assert.True(DateTime.UtcNow < until, $"proxy not served: {(int)proxy.StatusCode}");
|
||||
await Task.Delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AReportThatFoundAFrameUnreadableBeforeItsProxyCameIsNotServed()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register);
|
||||
var (editor, _, _) = await server.UserAsync("alberto", "editor");
|
||||
var upload = await Uploads.UploadAsync(editor, Heif(1), "IMG_0001.HEIC", sessionKey: "roof");
|
||||
var frame = Assert.NotNull(await server.Database.Frames.GetAsync(upload.FrameId));
|
||||
var sequence = Assert.NotNull(await server.Database.Sequences.GetAsync(upload.SequenceId));
|
||||
// A deep analysis ran before the proxy came and found no pixels in the HEIF original.
|
||||
var path = new Core.Archiving.ArchivePaths(server.Options.ArchivePath).Sequence(sequence.Folder).AnalysisPath;
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||
Reports.Minimal(1, undecodable: 0).Save(path);
|
||||
var url = $"/api/v1/sequences/{sequence.Id}/analysis/report";
|
||||
using (var before = await editor.GetAsync(url))
|
||||
await before.ExpectAsync(HttpStatusCode.OK);
|
||||
|
||||
// Once the frame is read from its proxy, that verdict and its advice to exclude the frame no longer hold, even
|
||||
// before a light analysis has dropped the deep status.
|
||||
using (var stored = await PutAsync(editor, frame.Id, Proxy(frame.CapturedAt!.Value)))
|
||||
await stored.ExpectAsync(HttpStatusCode.NoContent);
|
||||
using var after = await editor.GetAsync(url);
|
||||
Assert.Equal("analysis", (await after.ExpectErrorAsync(HttpStatusCode.NotFound, "not_found")).Details);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FramesTheServerDecodesAskForNoProxy()
|
||||
{
|
||||
@@ -87,6 +176,8 @@ public sealed class ProxyUploadTests(TestContext context)
|
||||
return JpegEncoder.Encode(image, new JpegEncodeOptions { Quality = 85, App1Segments = [exif[4..]] });
|
||||
}
|
||||
|
||||
private static (bool WantsProxy, bool HasProxy) Wanted(ManifestFrame frame) => (frame.WantsProxy, frame.HasProxy);
|
||||
|
||||
private static Task<HttpResponseMessage> PutAsync(HttpClient client, Guid frameId, byte[] body)
|
||||
{
|
||||
var content = new ByteArrayContent(body);
|
||||
|
||||
Reference in new issue
Block a user