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
{
+7
View File
@@ -70,6 +70,13 @@ public sealed class SyncHost(AppServices services) : ISyncConnector, IAsyncDispo
_switch = SwitchAsync(_switch, wanted);
}
/// <summary>Compares now, once the session switch in progress settled; null while signed out.</summary>
public async Task<SyncSnapshot?> RefreshAsync(CancellationToken ct = default)
{
await _switch;
return Agent is { } agent ? await agent.RefreshAsync(ct) : null;
}
/// <summary>Compares again soon (an option changed, an edit on this PC).</summary>
public void RequestRefresh() => Agent?.RequestRefresh();
+17 -14
View File
@@ -142,11 +142,11 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
_ = ReloadAsync();
}
/// <summary>Reads the table again; concurrent requests collapse into one more pass.</summary>
/// <summary>Reads the table again; requests made while a pass runs share the next one, which they wait for.</summary>
public async Task ReloadAsync()
{
Interlocked.Exchange(ref _reloadQueued, 1);
if (!await _reloading.WaitAsync(0)) return;
await _reloading.WaitAsync();
try
{
while (Interlocked.Exchange(ref _reloadQueued, 0) == 1)
@@ -293,18 +293,7 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
SyncAction.TakeServer => SyncResolution.TakeServer,
_ => SyncResolution.SaveBoth,
};
if (resolution != SyncResolution.SaveBoth && !_shell.Services.Dialogs.Confirm(new ConfirmRequest
{
Heading = Loc.L("Server.Conflict." + action + ".Title"),
Message = Loc.L("Server.Conflict." + action + ".Message", entry.Title),
Detail = SyncText.Conflict(entry),
DetailToolTip = Loc.L("Tooltips.Server.Conflict.Detail"),
SafeText = Loc.L("Server.Conflict.Cancel"),
SafeToolTip = Loc.L("Tooltips.Server.Conflict.Cancel"),
ActionText = Loc.L("Server.Sync.Action." + action),
ActionToolTip = Loc.L("Tooltips.Server.Sync." + action),
IsDestructive = true,
})) return;
if (resolution != SyncResolution.SaveBoth && !_shell.Services.Dialogs.Confirm(OverwriteRequest(entry, action))) return;
try
{
await service.ResolveAsync(remote, entry.Id, resolution, CancellationToken.None);
@@ -317,6 +306,20 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
}
}
/// <summary>"Keep this PC's settings?" with the settings that differ: one side's edits are about to be overwritten.</summary>
private static ConfirmRequest OverwriteRequest(SyncEntry entry, SyncAction action) => new()
{
Heading = Loc.L("Server.Conflict." + action + ".Title"),
Message = Loc.L("Server.Conflict." + action + ".Message", entry.Title),
Detail = SyncText.Conflict(entry),
DetailToolTip = Loc.L("Tooltips.Server.Conflict.Detail"),
SafeText = Loc.L("Server.Conflict.Cancel"),
SafeToolTip = Loc.L("Tooltips.Server.Conflict.Cancel"),
ActionText = Loc.L("Server.Sync.Action." + action),
ActionToolTip = Loc.L("Tooltips.Server.Sync." + action),
IsDestructive = true,
};
private async Task UploadAllAsync()
{
if (Host is not { Service: { } service, Server: { } server } || _shell.Services.Engine is not { } engine) return;
+20 -1
View File
@@ -4,6 +4,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Titano.App.DesignTime;
using Titano.App.Server;
using Titano.App.Settings;
using Titano.Core.Diagnostics;
using Titano.Ui.Theming;
@@ -13,7 +14,7 @@ namespace Titano.App.Shell;
/// <summary>
/// <c>Titano.exe --capture &lt;dir&gt;</c>: renders every client screen at 1440×900 in the dark and light themes to
/// <c>&lt;screen&gt;-&lt;theme&gt;.png</c> from <see cref="SampleData"/> (first run on an empty index, then a populated
/// one), for visual review and phase reports (BRIEF §20.2), then exits.
/// one, then the sync table with an upload and a settings conflict), for visual review and phase reports (BRIEF §20.2), then exits.
/// </summary>
public static class ScreenCapture
{
@@ -55,6 +56,8 @@ public static class ScreenCapture
await shell.Library.RefreshAsync();
await shell.Jobs.ReloadAsync();
await shell.Services.Server.RestoreAsync();
await shell.Services.Sync.RefreshAsync();
await shell.Server.Sync.ReloadAsync();
shell.About.SetResult(null);
await shell.Settings.DetectEncodersAsync();
await shell.Settings.SelfTestAsync();
@@ -97,6 +100,19 @@ public static class ScreenCapture
written += await SaveAsync(window, directory, key.ToString().ToLowerInvariant(), theme);
}
}
// The sync table with an upload in progress, then filtered to the settings conflict.
await sample.FillSyncAsync();
await shell.Server.Sync.ReloadAsync();
foreach (var theme in Themes)
{
ThemeManager.Apply(theme);
shell.Navigate(SectionKey.Server);
SelectSyncFilter(shell, SyncFilter.All);
written += await SaveAsync(window, directory, "server-sync", theme);
SelectSyncFilter(shell, SyncFilter.Conflicts);
written += await SaveAsync(window, directory, "server-conflict", theme);
SelectSyncFilter(shell, SyncFilter.All);
}
Log.Info("capture", $"{written} screenshot(s) written to {Path.GetFullPath(directory)}");
if (written == 0) Environment.ExitCode = 1;
}
@@ -111,6 +127,9 @@ public static class ScreenCapture
}
}
private static void SelectSyncFilter(ShellViewModel shell, SyncFilter filter) =>
shell.Server.Sync.Chips.First(c => c.Filter == filter).SelectCommand.Execute(null);
private static async Task<int> SaveAsync(Window window, string directory, string screen, AppTheme theme, ShellViewModel? waitForThumbnails = null)
{
await Settle(window);
@@ -0,0 +1,100 @@
using Titano.App.Sections;
using Titano.App.Server;
using Titano.App.Shell;
using Titano.App.Tests.Windows;
using Titano.Core.Model;
using Titano.Data.Sync;
using Titano.Testing;
using Titano.Ui.Controls;
namespace Titano.App.Tests.Server;
/// <summary>The Server screen's sync table on the capture sample data: comparison, transfer, conflict and the Library's glyphs.</summary>
[WindowsOnly]
[Serial]
[Timeout(300_000)]
public sealed class ServerScreenSmokeTests
{
[Test]
public Task TheSyncTableShowsEveryStateOfTheSample() => ScreenHost.RunAsync(async () =>
{
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
var shell = app.Shell;
await app.Sample.FillAsync();
await shell.Library.RefreshAsync();
await shell.Services.Server.RestoreAsync();
Assert.NotNull(await shell.Services.Sync.RefreshAsync());
var table = shell.Server.Sync;
await table.ReloadAsync();
// 36 sequences here (4 also on the server) and 2 only on the server.
Assert.True(table.IsActive);
Assert.Equal(38, table.Rows.Count);
Assert.Equal(1, Chip(table, SyncFilter.Conflicts).Count);
Assert.Equal(2, Chip(table, SyncFilter.Remote).Count);
Assert.Equal(32, Chip(table, SyncFilter.LocalOnly).Count);
Assert.Equal(SyncStatus.InSync, Row(table, "Harbour sunset").Entry.Status);
Assert.Equal(SyncStatus.ServerAhead, Row(table, "Construction cam · week 38").Entry.Status);
Assert.SequenceEqual([SyncAction.DownloadOriginals], Row(table, "Construction cam · week 38").Actions.Select(a => a.Action));
Assert.SequenceEqual([SyncAction.OpenWithProxies, SyncAction.DownloadOriginals], Row(table, "Sunrise over Superga").Actions.Select(a => a.Action));
Assert.SequenceEqual([SyncAction.Upload], Row(table, "Clouds over the Langhe").Actions.Select(a => a.Action));
var conflict = Row(table, "Holy grail · Monviso");
Assert.Equal(StatusKind.Warning, conflict.StateKind);
Assert.SequenceEqual([SyncAction.KeepMine, SyncAction.TakeServer, SyncAction.SaveBoth], conflict.Actions.Select(a => a.Action));
Assert.Contains("41", conflict.StateToolTip);
Assert.NotNull(table.LastSyncText);
Assert.NotNull(table.ArchiveText);
// The Library shows the real sync state of each local copy.
var holyGrail = shell.Library.Items.Single(i => i.Title == "Holy grail · Monviso");
Assert.Equal(SyncState.Conflict, holyGrail.Sequence.SyncState);
Assert.Contains(holyGrail.Statuses, s => s.Kind == StatusKind.Warning);
Assert.Contains(shell.Library.Items.Single(i => i.Title == "Harbour sunset").Statuses, s => s.Kind == StatusKind.Synced);
shell.Navigate(SectionKey.Server);
await app.ExpectAsync<ServerView>("server");
// An upload in progress: the row shows what the server received and offers Pause.
await app.Sample.FillSyncAsync();
await table.ReloadAsync();
var comet = Row(table, "Comet over the ridge");
Assert.Equal(SyncStatus.Transferring, comet.Entry.Status);
Assert.SequenceEqual([SyncAction.Pause], comet.Actions.Select(a => a.Action));
Assert.Contains("46", comet.ServerText);
await app.ExpectAsync<ServerView>("server-sync");
// The conflict filter leaves the one row waiting for a choice.
Chip(table, SyncFilter.Conflicts).SelectCommand.Execute(null);
Assert.Equal("Holy grail · Monviso", Assert.Contains(table.Rows, _ => true).Title);
Assert.Count(1, table.Rows);
await app.ExpectAsync<ServerView>("server-conflict");
table.SearchText = "nothing like this";
Assert.False(table.HasRows);
Assert.NotNull(table.EmptyText);
});
[Test]
public Task SigningOutEmptiesTheTable() => ScreenHost.RunAsync(async () =>
{
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
var shell = app.Shell;
await app.Sample.FillAsync();
await shell.Services.Server.RestoreAsync();
await shell.Services.Sync.RefreshAsync();
await shell.Server.Sync.ReloadAsync();
Assert.True(shell.Server.Sync.HasRows);
await shell.Services.Server.SignOutAsync();
Assert.Null(await shell.Services.Sync.RefreshAsync());
await shell.Server.Sync.ReloadAsync();
Assert.False(shell.Server.Sync.IsActive);
Assert.False(shell.Server.Sync.HasRows);
shell.Navigate(SectionKey.Server);
await app.ExpectAsync<ServerView>("server-signedout-table");
});
private static SyncFilterChip Chip(SyncTableViewModel table, SyncFilter filter) => table.Chips.Single(c => c.Filter == filter);
private static SyncRow Row(SyncTableViewModel table, string title) => table.Rows.Single(r => r.Title == title);
}
@@ -0,0 +1,136 @@
using Titano.App.Server;
using Titano.Core.Localization;
using Titano.Core.Model;
using Titano.Data.Sync;
using Titano.Testing;
using Titano.Ui.Controls;
namespace Titano.App.Tests.Server;
/// <summary>Words, glyphs and actions of the sync table rows (Server.html).</summary>
public sealed class SyncTextTests
{
private static readonly SyncRights Editor = SyncRights.Of((long)RolePermissions.Default(UserRole.Editor));
private static readonly SyncRights Viewer = SyncRights.Of((long)RolePermissions.Default(UserRole.Viewer));
private static readonly Sequence Local = new()
{
Id = Guid.CreateVersion7(),
ArchiveId = Guid.CreateVersion7(),
Title = "Harbour sunset",
Folder = "2026/harbour",
FrameCount = 3_600,
TotalBytes = 86_000_000_000,
Status = SequenceStatus.ProxiesBuilt,
SettingsJson = """{"exposure":{"deflickerWindow":{"isAuto":false,"manual":41}}}""",
};
private static readonly SyncLink Link = new()
{
Server = "https://nas.local:8443",
RemoteId = Guid.CreateVersion7(),
Title = "Harbour sunset",
TotalBytes = 61_000_000_000,
RemoteStatus = SequenceStatus.ProxiesBuilt | SequenceStatus.ThumbsBuilt,
RenderCount = 2,
};
[Test]
public void RightsFollowTheServerPermissions()
{
Assert.Equal(new SyncRights(true, true), Editor);
Assert.Equal(new SyncRights(false, false), Viewer);
Assert.Equal(new SyncRights(false, true), SyncRights.Of((long)Permissions.RenderNode));
}
[Test]
public void EachStateOffersItsActions()
{
Assert.SequenceEqual([SyncAction.Upload], SyncText.Actions(Entry(SyncStatus.LocalOnly, link: null), Editor));
Assert.Empty(SyncText.Actions(Entry(SyncStatus.LocalOnly, link: null), Viewer));
Assert.SequenceEqual([SyncAction.OpenWithProxies, SyncAction.DownloadOriginals], SyncText.Actions(Entry(SyncStatus.RemoteOnly, local: null), Editor));
Assert.SequenceEqual([SyncAction.OpenWithProxies], SyncText.Actions(Entry(SyncStatus.ProxiesOnly, local: null), Viewer));
Assert.SequenceEqual([SyncAction.Upload], SyncText.Actions(Entry(SyncStatus.LocalAhead, Link with { MissingRemote = 4 }), Editor));
Assert.SequenceEqual([SyncAction.DownloadOriginals], SyncText.Actions(Entry(SyncStatus.ServerAhead, Link with { MissingLocal = 2 }), Editor));
Assert.SequenceEqual([SyncAction.SyncSettings], SyncText.Actions(Entry(SyncStatus.ServerAhead), Editor));
Assert.SequenceEqual([SyncAction.KeepMine, SyncAction.TakeServer, SyncAction.SaveBoth], SyncText.Actions(Entry(SyncStatus.Conflict), Editor));
Assert.Empty(SyncText.Actions(Entry(SyncStatus.InSync), Editor));
Assert.SequenceEqual([SyncAction.Pause], SyncText.Actions(Entry(SyncStatus.Transferring, transfer: Upload(JobState.Running)), Editor));
Assert.SequenceEqual([SyncAction.Pause], SyncText.Actions(Entry(SyncStatus.Transferring, transfer: Upload(JobState.Queued)), Editor));
Assert.SequenceEqual([SyncAction.Resume], SyncText.Actions(Entry(SyncStatus.Transferring, transfer: Upload(JobState.Paused)), Editor));
}
[Test]
public void ColumnsSayWhatEachSideHolds()
{
var originals = Loc.L("Server.Sync.Originals");
var proxies = Loc.L("Server.Sync.Proxies");
Assert.Equal($"{originals} · {proxies}", SyncText.Local(Entry(SyncStatus.InSync)));
Assert.Equal(originals, SyncText.Local(Entry(SyncStatus.InSync, local: Local with { Status = SequenceStatus.None })));
Assert.Equal(proxies, SyncText.Local(Entry(SyncStatus.ProxiesOnly, Link with { ProxiesCached = 10 }, local: null)));
Assert.Equal(Loc.L("Server.Sync.None"), SyncText.Local(Entry(SyncStatus.RemoteOnly, local: null)));
Assert.Equal($"{originals} · {proxies} · {Loc.Plural("Server.Sync.Exports", 2)}", SyncText.Server(Entry(SyncStatus.InSync)));
Assert.Equal(Loc.L("Server.Sync.None"), SyncText.Server(Entry(SyncStatus.LocalOnly, link: null)));
var uploading = Entry(SyncStatus.Transferring, link: null, transfer: Upload(JobState.Running) with { ProgressDone = 462, ProgressTotal = 1_005 });
Assert.Equal(Loc.L("Server.Sync.Received", Loc.L("Common.Percent", "46")), SyncText.Server(uploading));
Assert.Equal(86_000_000_000, SyncText.Size(Entry(SyncStatus.LocalOnly, link: null), SyncAction.Upload));
Assert.Equal(61_000_000_000, SyncText.Size(Entry(SyncStatus.RemoteOnly, local: null), SyncAction.DownloadOriginals));
}
[Test]
public void StatesPairAGlyphWithAWord()
{
Assert.Equal((StatusKind.Done, Loc.L("Server.Sync.State.InSync")), Kind(Entry(SyncStatus.InSync)));
Assert.Equal((StatusKind.Offline, Loc.L("Server.Sync.State.LocalOnly")), Kind(Entry(SyncStatus.LocalOnly, link: null)));
Assert.Equal((StatusKind.Remote, Loc.L("Server.Sync.State.RemoteOnly")), Kind(Entry(SyncStatus.RemoteOnly, local: null)));
Assert.Equal((StatusKind.Warning, Loc.L("Server.Sync.State.Conflict")), Kind(Entry(SyncStatus.Conflict)));
Assert.Equal((StatusKind.Running, Loc.L("Server.Sync.State.Uploading")), Kind(Entry(SyncStatus.Transferring, transfer: Upload(JobState.Running))));
Assert.Equal((StatusKind.Paused, Loc.L("Server.Sync.State.Paused")), Kind(Entry(SyncStatus.Transferring, transfer: Upload(JobState.Paused))));
Assert.Equal((StatusKind.Running, Loc.L("Server.Sync.State.Downloading")),
Kind(Entry(SyncStatus.Transferring, transfer: Upload(JobState.Running) with { Kind = JobKind.Download })));
}
[Test]
public void AConflictNamesTheSettingsThatDiffer()
{
var conflict = Entry(SyncStatus.Conflict, Link with { ConflictSettingsJson = """{"exposure":{"deflickerWindow":{"isAuto":false,"manual":33}}}""" });
var text = SyncText.State(conflict).ToolTip;
Assert.Equal(Loc.L("Server.Conflict.Difference", "exposure.deflickerWindow.manual", "41", "33"), text);
Assert.Equal(Loc.L("Tooltips.Server.Sync.State.Conflict"), SyncText.Conflict(Entry(SyncStatus.Conflict)));
}
[Test]
public void FiltersAndSearchSelectRows()
{
var rows = new[]
{
Entry(SyncStatus.LocalOnly, link: null),
Entry(SyncStatus.RemoteOnly, local: null),
Entry(SyncStatus.ProxiesOnly, local: null),
Entry(SyncStatus.Conflict),
Entry(SyncStatus.InSync, local: Local with { Title = "Comet over the ridge" }),
};
Assert.Equal(5, rows.Count(r => SyncText.Matches(r, SyncFilter.All, string.Empty)));
Assert.Equal(1, rows.Count(r => SyncText.Matches(r, SyncFilter.LocalOnly, string.Empty)));
Assert.Equal(2, rows.Count(r => SyncText.Matches(r, SyncFilter.Remote, string.Empty)));
Assert.Equal(1, rows.Count(r => SyncText.Matches(r, SyncFilter.Conflicts, string.Empty)));
Assert.Equal(1, rows.Count(r => SyncText.Matches(r, SyncFilter.All, "COMET")));
Assert.Equal(0, rows.Count(r => SyncText.Matches(r, SyncFilter.Conflicts, "comet")));
}
private static (StatusKind, string) Kind(SyncEntry entry)
{
var (kind, text, _) = SyncText.State(entry);
return (kind, text);
}
private static SyncEntry Entry(SyncStatus status, SyncLink? link = null, Sequence? local = null, Job? transfer = null) =>
new(local ?? (status is SyncStatus.RemoteOnly or SyncStatus.ProxiesOnly ? null : Local), link ?? (status == SyncStatus.LocalOnly ? null : Link), status,
transfer);
private static Job Upload(JobState state) => new() { Id = Guid.CreateVersion7(), Kind = JobKind.UploadCommit, State = state };
}
@@ -122,7 +122,7 @@ public sealed class ScreenSmokeTests
});
/// <summary>A <see cref="MainWindow"/> on capture services and sample data, shown off screen like <c>--capture</c>.</summary>
private sealed class SampleApp : IAsyncDisposable
internal sealed class SampleApp : IAsyncDisposable
{
private const double Width = 1440;
private const double Height = 900;