feat(app): sample server for sync captures, server-sync and server-conflict screenshots, sync tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-02 23:00:15 +00:00
1 parent 25653c052b
commit b31c6aa332
7 files changed
+430 -19

No files matched your search

+149 -3
View File
@@ -9,6 +9,7 @@ using Titano.Core.Imaging;
using Titano.Core.Model;
using Titano.Core.Video;
using Titano.Data;
using Titano.Data.Sync;
using Titano.Protocol;
using Titano.Protocol.Client;
@@ -17,14 +18,18 @@ namespace Titano.App.DesignTime;
/// <summary>
/// Synthetic content for <c>--capture</c> screenshots and the screen smoke tests ONLY: a temporary SQLite index
/// with an archive of generated JPEGs (one sequence stores its thumbnail as an embedded preview inside a fake RAW
/// file), jobs in every state, a fake signed-in server and a fake encoder inventory. Everything lives in the
/// file), jobs in every state, a fake signed-in server with sequences to compare (one in conflict) and a fake
/// encoder inventory. Everything lives in the
/// capture environment's temporary folder; nothing touches the network or the user's data.
/// </summary>
public sealed class SampleData
{
public const string ServerFingerprint = "9A:3C:71:E0:5B:12:C4:88:0F:6D:2A:91:E7:44:B3:5C:19:D2:6F:80:A1:3E:57:C9:0B:64:F8:2D:93:A6:71:CE";
private const string ServerAddress = "https://nas.local:8443";
private readonly AppServices _services;
private readonly SampleSyncRemote _remote = new();
private TitanoDatabase? _db;
private SampleData(AppServices services) => _services = services;
@@ -38,7 +43,9 @@ public sealed class SampleData
services.Server = new ServerSession(settings, services.SaveSettings, new SampleServerApiFactory(), new PlainTokenProtector());
services.Encoders = new SampleEncoders();
services.CheckForUpdateAsync = _ => Task.FromResult<ReleaseInfo?>(null);
return new SampleData(services);
var sample = new SampleData(services);
services.Sync.RemoteFactory = (_, _, _) => sample._remote;
return sample;
}
/// <summary>Opens the empty temporary index (first run: no archive, nothing indexed).</summary>
@@ -68,6 +75,7 @@ public sealed class SampleData
await db.Sequences.SetTagsAsync(sequences[9].Sequence.Id, ["holy grail"]);
foreach (var job in Jobs(sequences.Select(s => s.Sequence).ToList(), archive.Id)) await db.Jobs.EnqueueAsync(job);
await FillServerAsync(db, sequences.Select(s => s.Sequence).ToList());
settings.LastArchivePath = @"D:\TitanoArchive";
settings.ServerUrl = "https://nas.local:8443";
@@ -79,6 +87,82 @@ public sealed class SampleData
settings.FirstRunCompleted = true;
}
/// <summary>An upload in progress for the sync table (Comet over the ridge, 46 %).</summary>
public async Task FillSyncAsync()
{
var db = _db ?? throw new InvalidOperationException("FillAsync first.");
var comet = (await db.Sequences.ListAsync(new Data.Repositories.SequenceQuery { Text = "Comet", Limit = 1 })).Items[0];
var now = DateTimeOffset.UtcNow;
await db.Jobs.EnqueueAsync(new Job
{
Id = Guid.CreateVersion7(),
Kind = JobKind.UploadCommit,
TargetIds = [comet.Id],
TargetLabel = comet.DisplayTitle,
ParametersJson = $$"""{"server":"{{ServerAddress}}"}""",
State = JobState.Running,
Priority = JobPriority.User,
ProgressDone = 462,
ProgressTotal = 1_005,
ItemsPerSecond = 1.6,
Eta = TimeSpan.FromMinutes(4),
NodeId = _services.WorkerId,
Attempts = 1,
Created = now.AddMinutes(-5),
Started = now.AddMinutes(-5),
});
}
/// <summary>
/// The server's side: four sequences this PC also holds (two the same, one with settings changed on both sides, one
/// with more originals on the server) and two only on the server; the others are only here.
/// </summary>
private async Task FillServerAsync(TitanoDatabase db, IReadOnlyList<Sequence> local)
{
Guid Id(string title) => local.First(s => s.Title == title).Id;
await db.Sequences.EditAsync(Id("Holy grail · Monviso"), new Data.Repositories.SequenceEdit { SettingsJson = DeflickerWindow(41) }, null);
var linked = new (string Title, int Frames, string? Settings)[]
{
("Harbour sunset", 3, null),
("Aurora, Tromsø", 3, null),
("Holy grail · Monviso", 3, DeflickerWindow(33)),
("Construction cam · week 38", 8, null),
};
foreach (var (title, frames, settings) in linked)
{
// The server's copy carries the same title, tags and rating as this PC's.
var sequence = (await db.Sequences.GetAsync(Id(title)))!;
var remote = _remote.Add(SampleSyncRemote.Dto(sequence), settings, frames);
await _services.Sync.Service!.LinkAsync(ServerAddress, remote, sequence.Id);
}
_remote.Add(SampleSyncRemote.Dto(new Sequence
{
Id = Guid.CreateVersion7(),
ArchiveId = Guid.Empty,
Title = "Sunrise over Superga",
Folder = "2026/2026-07-02 Sony ILCE-7M4",
FrameCount = 2_880,
TotalBytes = 2_880 * 21_000_000L,
Status = SequenceStatus.ProxiesBuilt | SequenceStatus.ThumbsBuilt,
RenderedCount = 1,
UpdatedAt = DateTimeOffset.UtcNow,
}), null, 3);
_remote.Add(SampleSyncRemote.Dto(new Sequence
{
Id = Guid.CreateVersion7(),
ArchiveId = Guid.Empty,
Title = "Lake Como storm",
Folder = "2026/2026-08-21 Canon EOS R5",
FrameCount = 1_450,
TotalBytes = 1_450 * 45_000_000L,
Status = SequenceStatus.ThumbsBuilt,
UpdatedAt = DateTimeOffset.UtcNow,
}), null, 3);
static string DeflickerWindow(int frames) =>
"""{"exposure":{"deflickerWindow":{"isAuto":false,"manual":""" + frames.ToString(System.Globalization.CultureInfo.InvariantCulture) + "}}}";
}
private IEnumerable<(Sequence Sequence, string[] Colours, bool Raw)> Sequences(Guid archiveId)
{
var now = new DateTime(2026, 9, 28, 18, 2, 11);
@@ -278,7 +362,8 @@ public sealed class SampleData
private sealed class SampleServerApi(Uri baseAddress, IReadOnlyCollection<string> trusted) : IServerApi
{
private static readonly UserDto User = new(Guid.Empty, "alberto", "Alberto", "editor", 0, 5_000_000_000_000, 2_100_000_000_000, false, false,
private static readonly UserDto User = new(Guid.Empty, "alberto", "Alberto", "editor", (long)RolePermissions.Default(UserRole.Editor), 5_000_000_000_000,
2_100_000_000_000, false, false,
new DateTimeOffset(2025, 1, 1, 0, 0, 0, TimeSpan.Zero), DateTimeOffset.UtcNow);
public Uri BaseAddress { get; } = baseAddress;
@@ -308,6 +393,67 @@ public sealed class SampleData
}
}
/// <summary>
/// The sample server's sequences for the sync table: listings, manifests (frames hashed from their index, so
/// unhashed sample frames match them by count) and settings edits; transfers are not part of the screenshots.
/// </summary>
private sealed class SampleSyncRemote : ISyncRemote
{
private readonly Dictionary<Guid, (SequenceDto Dto, string? Settings, int Frames)> _sequences = [];
public string Server => ServerAddress;
public static SequenceDto Dto(Sequence s) => new(Guid.CreateVersion7(), s.Title, s.DisplayTitle, s.Folder, s.CameraMake, s.CameraModel, s.Lens,
s.FirstCapture, s.LastCapture, s.FrameCount, s.MedianInterval, s.TotalBytes, (long)s.Status, s.RenderedCount, null, s.Tags, s.Rating, s.Notes, 2, 1,
0, null, s.UpdatedAt);
public Guid Add(SequenceDto dto, string? settings, int frames)
{
_sequences[dto.Id] = (dto, settings, frames);
return dto.Id;
}
public Task<IReadOnlyList<SequenceDto>> ListSequencesAsync(CancellationToken cancellationToken) =>
Task.FromResult<IReadOnlyList<SequenceDto>>([.. _sequences.Values.Select(s => s.Dto)]);
public Task<SequenceDto> GetSequenceAsync(Guid id, CancellationToken cancellationToken) => Task.FromResult(_sequences[id].Dto);
public Task<SequenceManifest> GetManifestAsync(Guid id, CancellationToken cancellationToken)
{
var (dto, settings, frames) = _sequences[id];
var hasProxy = (dto.Status & (long)SequenceStatus.ProxiesBuilt) != 0;
return Task.FromResult(new SequenceManifest(id, dto.FramesVersion, dto.SettingsVersion, settings, dto.Tags,
[.. Enumerable.Range(0, frames).Select(i => new ManifestFrame(Guid.CreateVersion7(), i, $"IMG_{i + 1:0000}.JPG", 24_000_000,
Convert.ToHexStringLower(System.Security.Cryptography.SHA256.HashData(BitConverter.GetBytes(i))), hasProxy, true))], []));
}
public Task<IReadOnlyList<FrameDto>> ListFramesAsync(Guid sequenceId, CancellationToken cancellationToken) => Task.FromResult<IReadOnlyList<FrameDto>>([]);
public Task<SequenceDto> UpdateSequenceAsync(Guid id, UpdateSequenceRequest request, CancellationToken cancellationToken)
{
var (dto, _, frames) = _sequences[id];
var updated = dto with { SettingsVersion = dto.SettingsVersion + 1, UpdatedAt = DateTimeOffset.UtcNow };
_sequences[id] = (updated, request.SettingsJson, frames);
return Task.FromResult(updated);
}
public Task<CompleteUploadResponse?> UploadFileAsync(string path, Guid? sequenceId, string? sessionKey, string sha256, DateTime? capturedAt,
CancellationToken cancellationToken) => throw new NotSupportedException("The sample server takes no uploads.");
public Task DownloadFrameAsync(Guid frameId, string kind, Stream destination, CancellationToken cancellationToken) =>
throw new NotSupportedException("The sample server serves no files.");
public async IAsyncEnumerable<ServerEvent> EventsAsync([System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken)
{
await Task.Delay(Timeout.Infinite, cancellationToken);
yield break;
}
public void Dispose()
{
}
}
/// <summary>No encryption: the capture environment is thrown away.</summary>
private sealed class PlainTokenProtector : ITokenProtector
{