refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
The owner renamed the product and moved the repository to the self-hosted Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control, and asked for Actions and a first automatic release with the server package and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md). - Chronos everywhere: a byte-exact rename of contents and paths, then a per-language review of the forms the old name's ending had dictated. - Gitea instead of GitHub: the update check, licence, issue and support links read ChronosReleasesUrl; the update check takes the highest stable version, offers a pre-release build its final release and reports a repository it cannot see as a failed check. EULA, security policy and Gitea issue forms live at the repository root. - Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release, nightly image and performance gates in the .NET SDK container with git checkout and the system SQLite. The release cross-compiles the Windows programs, checks their icon, version and DPI manifest, packs installers and zips, publishes the Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER). - New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the docker-exec script, which Gitea's service containers do not allow; the throw-away server runs without durability) and pe-check. - Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR, 3 on the shared runner; the weekly performance gates keep theirs). BREAKING CHANGE: programs, settings, data folders, file types, environment variables and the Docker image use the new name; nothing is migrated from Titano, which never had a release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #6.
This commit is contained in:
1 parent
c99842cc86
commit
f2b58522b9
1801 files changed
+11804
-10676
No files matched your search
@@ -0,0 +1,238 @@
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using Chronos.App.Server;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Protocol.Client;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.App.Tests.Server;
|
||||
|
||||
public sealed class ConnectFlowTests
|
||||
{
|
||||
private const string Fingerprint = "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";
|
||||
|
||||
[Test]
|
||||
public async Task AnUnknownCertificateIsConfirmedBeforeThePasswordIsSent()
|
||||
{
|
||||
var server = new FakeServer { SelfSigned = true };
|
||||
var trust = new MemoryTrust();
|
||||
using var flow = new ConnectFlow(server, trust);
|
||||
|
||||
Assert.Equal(ConnectStep.AwaitingTrust, await flow.ProbeAsync("nas.local:8443"));
|
||||
Assert.Equal(Fingerprint, flow.PendingFingerprint);
|
||||
Assert.Equal(new Uri("https://nas.local:8443/"), flow.Address);
|
||||
// The password cannot be sent while the certificate waits for a decision.
|
||||
Assert.Equal(ConnectStep.AwaitingTrust, await flow.SignInAsync("alberto", "secret"));
|
||||
Assert.Equal(0, server.Logins);
|
||||
|
||||
Assert.Equal(ConnectStep.AwaitingCredentials, await flow.ConfirmTrustAsync(true));
|
||||
Assert.Contains(Fingerprint, trust.Fingerprints);
|
||||
Assert.Equal("https://nas.local:8443", trust.Servers.Single());
|
||||
Assert.Equal("Studio NAS", flow.Info!.Name);
|
||||
Assert.NotNull(flow.Latency);
|
||||
|
||||
Assert.Equal(ConnectStep.Connected, await flow.SignInAsync("alberto", "secret"));
|
||||
Assert.Equal(1, server.Logins);
|
||||
Assert.Equal("token-1", flow.Token);
|
||||
Assert.Equal("alberto", flow.User!.Username);
|
||||
Assert.NotNull(flow.Api);
|
||||
// Every client got the trust list current at its creation.
|
||||
Assert.Empty(server.Created[0]);
|
||||
Assert.Contains(Fingerprint, server.Created[^1]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RejectingTheCertificateSendsNothing()
|
||||
{
|
||||
var server = new FakeServer { SelfSigned = true };
|
||||
using var flow = new ConnectFlow(server, new MemoryTrust());
|
||||
await flow.ProbeAsync("https://nas.local:8443");
|
||||
Assert.Equal(ConnectStep.Failed, await flow.ConfirmTrustAsync(false));
|
||||
Assert.Equal(ConnectError.Untrusted, flow.Error);
|
||||
Assert.Equal(ConnectStep.Failed, await flow.SignInAsync("alberto", "secret"));
|
||||
Assert.Equal(0, server.Logins);
|
||||
Assert.Null(flow.Token);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task APubliclyValidCertificateNeedsNoQuestion()
|
||||
{
|
||||
var server = new FakeServer();
|
||||
using var flow = new ConnectFlow(server, new MemoryTrust());
|
||||
Assert.Equal(ConnectStep.AwaitingCredentials, await flow.ProbeAsync("https://chronos.example.com"));
|
||||
Assert.Null(flow.PendingFingerprint);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AWrongPasswordReturnsToTheForm()
|
||||
{
|
||||
var server = new FakeServer { Password = "right" };
|
||||
using var flow = new ConnectFlow(server, new MemoryTrust());
|
||||
await flow.ProbeAsync("nas.local");
|
||||
Assert.Equal(ConnectStep.AwaitingCredentials, await flow.SignInAsync("alberto", "wrong"));
|
||||
Assert.Equal(ConnectError.BadCredentials, flow.Error);
|
||||
Assert.Equal(ConnectStep.Connected, await flow.SignInAsync("alberto", "right"));
|
||||
Assert.Equal(ConnectError.None, flow.Error);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Case("", ConnectError.InvalidAddress)]
|
||||
[Case("ftp://nas.local", ConnectError.InvalidAddress)]
|
||||
[Case("down.local", ConnectError.Unreachable)]
|
||||
[Case("web.local", ConnectError.NotChronos)]
|
||||
public async Task ProbeFailuresAreClassified(string address, ConnectError error)
|
||||
{
|
||||
using var flow = new ConnectFlow(new FakeServer(), new MemoryTrust());
|
||||
Assert.Equal(ConnectStep.Failed, await flow.ProbeAsync(address));
|
||||
Assert.Equal(error, flow.Error);
|
||||
Assert.Null(flow.Api);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ASavedSessionIsRestoredWithoutAPassword()
|
||||
{
|
||||
var server = new FakeServer { SelfSigned = true };
|
||||
var trust = new MemoryTrust();
|
||||
trust.Trust("https://nas.local:8443", Fingerprint);
|
||||
using var flow = new ConnectFlow(server, trust);
|
||||
Assert.Equal(ConnectStep.Connected, await flow.RestoreAsync("https://nas.local:8443", "token-7"));
|
||||
Assert.Equal(0, server.Logins);
|
||||
Assert.Equal("token-7", flow.Token);
|
||||
Assert.Equal("token-7", server.LastTokenSeen);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnExpiredTokenAsksForTheLoginAgain()
|
||||
{
|
||||
var server = new FakeServer { ValidToken = "fresh" };
|
||||
using var flow = new ConnectFlow(server, new MemoryTrust());
|
||||
Assert.Equal(ConnectStep.AwaitingCredentials, await flow.RestoreAsync("nas.local", "stale"));
|
||||
Assert.Equal(ConnectError.SessionExpired, flow.Error);
|
||||
Assert.Null(flow.Token);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AChangedCertificateNeverReceivesTheSavedToken()
|
||||
{
|
||||
var server = new FakeServer { SelfSigned = true };
|
||||
var trust = new MemoryTrust();
|
||||
trust.Trust("https://nas.local:8443", "00:11:22"); // trusted earlier: a different certificate
|
||||
using var flow = new ConnectFlow(server, trust);
|
||||
Assert.Equal(ConnectStep.AwaitingTrust, await flow.RestoreAsync("nas.local:8443", "token-7"));
|
||||
Assert.Equal(ConnectError.CertificateChanged, flow.Error);
|
||||
Assert.Null(server.LastTokenSeen);
|
||||
Assert.Null(flow.Token);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SignOutForgetsTheSession()
|
||||
{
|
||||
var server = new FakeServer();
|
||||
using var flow = new ConnectFlow(server, new MemoryTrust());
|
||||
await flow.ProbeAsync("nas.local");
|
||||
await flow.SignInAsync("alberto", "secret");
|
||||
var changes = 0;
|
||||
flow.Changed += (_, _) => changes++;
|
||||
await flow.SignOutAsync();
|
||||
Assert.Equal(1, server.Logouts);
|
||||
Assert.Equal(ConnectStep.Idle, flow.Step);
|
||||
Assert.Null(flow.Token);
|
||||
Assert.Null(flow.Api);
|
||||
Assert.Equal(1, changes);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddressesAreNormalised()
|
||||
{
|
||||
Assert.True(ServerAddress.TryParse("nas.local:8443", out var a));
|
||||
Assert.Equal("https://nas.local:8443/", a.ToString());
|
||||
Assert.True(ServerAddress.TryParse(" http://10.0.0.5:8080/chronos?x=1 ", out var b));
|
||||
Assert.Equal("http://10.0.0.5:8080/chronos/", b.ToString());
|
||||
Assert.False(ServerAddress.TryParse(" ", out _));
|
||||
Assert.False(ServerAddress.TryParse("ftp://nas", out _));
|
||||
Assert.Equal("https://nas.local:8443", ServerAddress.Display(a));
|
||||
Assert.Equal("https://nas.local:8443", ServerAddress.Display("https://nas.local:8443/"));
|
||||
}
|
||||
|
||||
private sealed class MemoryTrust : ITrustStore
|
||||
{
|
||||
private readonly List<string> _fingerprints = [];
|
||||
|
||||
public List<string> Servers { get; } = [];
|
||||
|
||||
public IReadOnlyCollection<string> Fingerprints => [.. _fingerprints];
|
||||
|
||||
public void Trust(string server, string fingerprint)
|
||||
{
|
||||
Servers.Add(server);
|
||||
_fingerprints.Add(fingerprint);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A server with configurable behaviour, reached through clients that pin certificates like the real one.</summary>
|
||||
private sealed class FakeServer : IServerApiFactory
|
||||
{
|
||||
public bool SelfSigned { get; init; }
|
||||
public string Password { get; init; } = "secret";
|
||||
public string? ValidToken { get; init; }
|
||||
public int Logins { get; set; }
|
||||
public int Logouts { get; set; }
|
||||
public string? LastTokenSeen { get; set; }
|
||||
public List<IReadOnlyCollection<string>> Created { get; } = [];
|
||||
|
||||
public IServerApi Create(Uri baseAddress, IReadOnlyCollection<string> trustedFingerprints)
|
||||
{
|
||||
Created.Add(trustedFingerprints);
|
||||
return new Client(this, baseAddress, trustedFingerprints);
|
||||
}
|
||||
|
||||
private sealed class Client(FakeServer server, Uri baseAddress, IReadOnlyCollection<string> trusted) : IServerApi
|
||||
{
|
||||
public Uri BaseAddress { get; } = baseAddress;
|
||||
public string? Token { get; set; }
|
||||
|
||||
public Task<ServerInfo> GetInfoAsync(CancellationToken ct)
|
||||
{
|
||||
Handshake();
|
||||
return Task.FromResult(new ServerInfo("Studio NAS", "1.3.0", 1, [], server.SelfSigned ? Fingerprint : null, [], new ServerLimits(0, 0)));
|
||||
}
|
||||
|
||||
public Task<LoginResponse> LoginAsync(string username, string password, CancellationToken ct)
|
||||
{
|
||||
Handshake();
|
||||
server.Logins++;
|
||||
if (password != server.Password) throw new ChronosApiException(HttpStatusCode.Unauthorized, new ApiError("bad_credentials", "Wrong"));
|
||||
return Task.FromResult(new LoginResponse("token-" + server.Logins, User(username), false, DateTimeOffset.UtcNow.AddDays(1)));
|
||||
}
|
||||
|
||||
public Task<UserDto> MeAsync(CancellationToken ct)
|
||||
{
|
||||
Handshake();
|
||||
server.LastTokenSeen = Token;
|
||||
if (server.ValidToken is { } valid && Token != valid) throw new ChronosApiException(HttpStatusCode.Unauthorized, new ApiError("expired", "Expired"));
|
||||
return Task.FromResult(User("alberto"));
|
||||
}
|
||||
|
||||
public Task LogoutAsync(CancellationToken ct)
|
||||
{
|
||||
server.Logouts++;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>What TLS would do: a self-signed certificate is accepted only when pinned.</summary>
|
||||
private void Handshake()
|
||||
{
|
||||
if (BaseAddress.Host == "down.local") throw new HttpRequestException("No such host");
|
||||
if (BaseAddress.Host == "web.local") throw new ChronosApiException(HttpStatusCode.NotFound, new ApiError("http_404", "Not Found"));
|
||||
if (server.SelfSigned && !trusted.Contains(Fingerprint)) throw new UntrustedCertificateException(Fingerprint);
|
||||
}
|
||||
|
||||
private static UserDto User(string name) =>
|
||||
new(Guid.Empty, name, null, "editor", 0, 5_000_000_000_000, 2_100_000_000_000, false, false, DateTimeOffset.UtcNow, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
using System.IO;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.App.Tests.Server;
|
||||
|
||||
public sealed class RenderNodeHostTests
|
||||
{
|
||||
private static readonly RenderNodeSession Nas = new(new Uri("https://nas.local:8443/"), "token-a", ["AA:BB", "CC:DD"], Hardware: true);
|
||||
|
||||
/// <summary>Records the nodes it starts; fails the first <see cref="Failures"/> starts.</summary>
|
||||
private sealed class Nodes
|
||||
{
|
||||
public List<(RenderNodeSession Session, Node Node)> Started { get; } = [];
|
||||
public int Failures { get; set; }
|
||||
|
||||
public IRenderNode Start(RenderNodeSession session)
|
||||
{
|
||||
if (Failures-- > 0) throw new IOException("cache folder unavailable");
|
||||
var node = new Node();
|
||||
Started.Add((session, node));
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class Node : IRenderNode
|
||||
{
|
||||
private readonly TaskCompletionSource _completion = new();
|
||||
|
||||
public bool Stopped { get; private set; }
|
||||
|
||||
public Task Completion => _completion.Task;
|
||||
|
||||
/// <summary>The server refused the node (signed out, no render-node right): it ends by itself.</summary>
|
||||
public void Refuse() => _completion.TrySetResult();
|
||||
|
||||
public ValueTask DisposeAsync()
|
||||
{
|
||||
Stopped = true;
|
||||
_completion.TrySetResult();
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheNodeFollowsTheWantedSession()
|
||||
{
|
||||
var nodes = new Nodes();
|
||||
await using var host = new RenderNodeHost(nodes.Start);
|
||||
|
||||
host.Update(Nas);
|
||||
host.Update(Nas);
|
||||
await host.Switching;
|
||||
Assert.Equal(Nas, host.Session);
|
||||
Assert.Count(1, nodes.Started);
|
||||
|
||||
// An equal session (fingerprints in another order) keeps the node.
|
||||
host.Update(Nas with { TrustedFingerprints = ["CC:DD", "AA:BB"] });
|
||||
await host.Switching;
|
||||
Assert.Count(1, nodes.Started);
|
||||
|
||||
// A new token (signed in again) is another session: the old node stops before the new one starts.
|
||||
var renewed = Nas with { Token = "token-b" };
|
||||
host.Update(renewed);
|
||||
await host.Switching;
|
||||
Assert.True(nodes.Started[0].Node.Stopped, "old node stopped");
|
||||
Assert.Equal((renewed, false), (nodes.Started[1].Session, nodes.Started[1].Node.Stopped));
|
||||
|
||||
// A forgotten certificate or another hardware choice also needs a new node.
|
||||
host.Update(renewed with { TrustedFingerprints = [] });
|
||||
await host.Switching;
|
||||
host.Update(renewed with { TrustedFingerprints = [], Hardware = false });
|
||||
await host.Switching;
|
||||
Assert.Count(4, nodes.Started);
|
||||
Assert.True(nodes.Started[2].Node.Stopped, "replaced again");
|
||||
|
||||
host.Update(null);
|
||||
await host.Switching;
|
||||
Assert.Null(host.Session);
|
||||
Assert.True(nodes.Started[3].Node.Stopped, "stopped when no longer wanted");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ANodeThatStoppedItselfIsStartedAgainByTheNextUpdate()
|
||||
{
|
||||
var nodes = new Nodes();
|
||||
await using var host = new RenderNodeHost(nodes.Start);
|
||||
host.Update(Nas);
|
||||
await host.Switching;
|
||||
|
||||
nodes.Started[0].Node.Refuse();
|
||||
host.Update(Nas);
|
||||
await host.Switching;
|
||||
Assert.Count(2, nodes.Started);
|
||||
Assert.Equal((Nas, false), (host.Session, nodes.Started[1].Node.Stopped));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheNodeIsWantedOnlyWhenOfferedAndSignedIn()
|
||||
{
|
||||
var address = new Uri("https://nas.local:8443/");
|
||||
Assert.Equal(Nas, RenderNodeSession.For(offered: true, connected: true, address, "token-a", ["AA:BB", "CC:DD"], hardware: true));
|
||||
Assert.Null(RenderNodeSession.For(offered: false, connected: true, address, "token-a", [], hardware: true));
|
||||
Assert.Null(RenderNodeSession.For(offered: true, connected: false, address, "token-a", [], hardware: true));
|
||||
Assert.Null(RenderNodeSession.For(offered: true, connected: true, address, null, [], hardware: true)); // signed out
|
||||
Assert.Null(RenderNodeSession.For(offered: true, connected: true, null, "token-a", [], hardware: true));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HardwarePreferenceDecidesPerPreset()
|
||||
{
|
||||
Assert.True(AppServices.AllowsHardware(HardwarePreference.PreferHardware, "4k-hevc"));
|
||||
Assert.False(AppServices.AllowsHardware(HardwarePreference.SoftwareOnly, "720p-preview"));
|
||||
Assert.True(AppServices.AllowsHardware(HardwarePreference.HardwareForPreviews, "720p-preview"));
|
||||
Assert.False(AppServices.AllowsHardware(HardwarePreference.HardwareForPreviews, "4k-hevc10-archive"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ANodeThatCannotStartIsRetriedByTheNextUpdate()
|
||||
{
|
||||
var nodes = new Nodes { Failures = 1 };
|
||||
await using var host = new RenderNodeHost(nodes.Start);
|
||||
|
||||
host.Update(Nas);
|
||||
await host.Switching;
|
||||
Assert.Null(host.Session);
|
||||
|
||||
host.Update(Nas);
|
||||
await host.Switching;
|
||||
Assert.Equal(Nas, host.Session);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DisposingStopsTheNodeAndIgnoresLaterUpdates()
|
||||
{
|
||||
var nodes = new Nodes();
|
||||
var host = new RenderNodeHost(nodes.Start);
|
||||
host.Update(Nas);
|
||||
await host.DisposeAsync();
|
||||
|
||||
Assert.True(nodes.Started.Single().Node.Stopped, "stopped on exit");
|
||||
host.Update(Nas);
|
||||
await host.Switching;
|
||||
Assert.Count(1, nodes.Started);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Automation;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Sections;
|
||||
using Chronos.App.Server;
|
||||
using Chronos.App.Shell;
|
||||
using Chronos.App.Tests.Windows;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Testing;
|
||||
using Chronos.Ui.Controls;
|
||||
|
||||
namespace Chronos.App.Tests.Server;
|
||||
|
||||
/// <summary>The Server screen's sync table on the capture sample data: comparison, transfers, 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());
|
||||
await app.Sample.CacheProxiesAsync();
|
||||
var table = shell.Server.Sync;
|
||||
await table.ReloadAsync();
|
||||
|
||||
// 36 sequences here (6 also on the server) and 2 only on the server; the conflict is listed first.
|
||||
Assert.True(table.IsActive);
|
||||
Assert.Equal(38, table.Rows.Count);
|
||||
Assert.Equal("Holy grail · Monviso", table.Rows[0].Title);
|
||||
Assert.True(table.Rows[0].IsConflict);
|
||||
Assert.Equal(1, Chip(table, SyncFilter.Conflicts).Count);
|
||||
Assert.Equal(2, Chip(table, SyncFilter.Remote).Count);
|
||||
Assert.Equal(30, 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], Actions(Row(table, "Construction cam · week 38")));
|
||||
Assert.SequenceEqual([SyncAction.Upload], Actions(Row(table, "Milan skyline dusk")));
|
||||
Assert.SequenceEqual([SyncAction.GetExports], Actions(Row(table, "Star trails, Colle del Nivolet")));
|
||||
var sunrise = Row(table, "Sunrise over Superga");
|
||||
Assert.Equal(SyncStatus.ProxiesOnly, sunrise.Entry.Status);
|
||||
Assert.Equal(Loc.L("Server.Sync.Proxies"), sunrise.LocalText);
|
||||
Assert.SequenceEqual([SyncAction.OpenWithProxies, SyncAction.DownloadOriginals], Actions(sunrise));
|
||||
Assert.SequenceEqual([SyncAction.Upload], Actions(Row(table, "Clouds over the Langhe")));
|
||||
var conflict = Row(table, "Holy grail · Monviso");
|
||||
Assert.Equal(StatusKind.Warning, conflict.StateKind);
|
||||
Assert.SequenceEqual([SyncAction.KeepMine, SyncAction.TakeServer, SyncAction.SaveBoth], Actions(conflict));
|
||||
// The state whole first (its fixed column cuts longer ones), then what differs.
|
||||
Assert.Equal(string.Join(Loc.Separator, conflict.StateText, Loc.L("Server.Conflict.Difference", Loc.L("Server.Setting.DeflickerWindow"), "41", "33")),
|
||||
conflict.StateToolTip);
|
||||
Assert.NotNull(table.LastSyncText);
|
||||
Assert.NotNull(table.ArchiveText);
|
||||
Assert.True(table.UploadAllCommand.CanExecute(null), "the table filled after the view bound");
|
||||
|
||||
// Resolving shows the plan first: what differs and which side is overwritten.
|
||||
var keepMine = SyncTableViewModel.ConflictRequest(conflict.Entry, SyncAction.KeepMine);
|
||||
Assert.True(keepMine.IsDestructive);
|
||||
Assert.Contains(Loc.L("Server.Setting.DeflickerWindow"), keepMine.Detail);
|
||||
Assert.False(SyncTableViewModel.ConflictRequest(conflict.Entry, SyncAction.SaveBoth).IsDestructive);
|
||||
|
||||
// The Library shows the real sync state of each local copy, in one word.
|
||||
var holyGrail = shell.Library.Items.Single(i => i.Title == "Holy grail · Monviso");
|
||||
Assert.Equal(SyncState.Conflict, holyGrail.Sequence.SyncState);
|
||||
Assert.Equal(StatusKind.Warning, holyGrail.Statuses[^1].Kind);
|
||||
Assert.Contains(shell.Library.Items.Single(i => i.Title == "Harbour sunset").Statuses, s => s.Kind == StatusKind.Synced);
|
||||
var milan = shell.Library.Items.Single(i => i.Title == "Milan skyline dusk").Statuses[^1];
|
||||
Assert.Equal((StatusKind.Synced, Loc.L("Library.Status.Synced")), (milan.Kind, milan.Text));
|
||||
|
||||
shell.Navigate(SectionKey.Server);
|
||||
await app.ExpectAsync<ServerView>("server");
|
||||
|
||||
// Tab walks the row buttons of every row: the rows take no focus, the list passes Tab on to their content.
|
||||
var list = app.FindAll<ListBox>().Single(l => l.Name == "SyncList");
|
||||
Assert.Equal(KeyboardNavigationMode.Continue, KeyboardNavigation.GetTabNavigation(list));
|
||||
var rowButtons = app.FindAll<Button>().Where(b => b.DataContext is SyncRowAction && b.IsVisible).ToList();
|
||||
Assert.True(rowButtons.Select(b => b.DataContext).OfType<SyncRowAction>().Count() > 3, "buttons of several rows are on screen");
|
||||
Assert.True(rowButtons.All(b => b.Focusable && b.IsTabStop), "every row button is a tab stop");
|
||||
|
||||
// Screen readers: a row reads as its sequence and state, each of the many "Upload" buttons names its sequence.
|
||||
foreach (var item in app.FindAll<ListBoxItem>().Where(i => i.DataContext is SyncRow && i.IsVisible))
|
||||
{
|
||||
var row = (SyncRow)item.DataContext;
|
||||
Assert.Equal(row.Title, AutomationProperties.GetName(item));
|
||||
Assert.Equal(row.StateText, AutomationProperties.GetItemStatus(item));
|
||||
}
|
||||
Assert.True(rowButtons.All(b => AutomationProperties.GetName(b) == ((SyncRowAction)b.DataContext).AccessibleName), "row buttons carry their row's name");
|
||||
Assert.Equal(Loc.L("Server.Sync.ActionFor", Loc.L("Server.Sync.Action.Upload"), "Clouds over the Langhe"),
|
||||
Row(table, "Clouds over the Langhe").Actions.Single().AccessibleName);
|
||||
|
||||
// The filters are a radio group: the chosen one is checked, so its state reaches screen readers.
|
||||
var chips = app.FindAll<RadioButton>().Where(r => r.DataContext is SyncFilterChip).ToList();
|
||||
Assert.Count(Enum.GetValues<SyncFilter>().Length, chips);
|
||||
Assert.True(chips.All(c => c.IsChecked == ((SyncFilterChip)c.DataContext).IsSelected), "the checked chip is the chosen filter");
|
||||
|
||||
// While connected the address is read-only text (selectable, not dimmed), kept left to right; status changes are announced.
|
||||
var address = app.FindAll<TextBox>().Single(t => t.Name == "AddressBox");
|
||||
Assert.True(address.IsEnabled && address.IsReadOnly, "the connected address is read-only, not disabled");
|
||||
Assert.Equal(FlowDirection.LeftToRight, address.FlowDirection);
|
||||
var known = app.FindAll<Button>().Single(b => b.Name == "KnownButton");
|
||||
Assert.False(string.IsNullOrEmpty(AutomationProperties.GetName(known)), "the icon-only button has a name");
|
||||
Assert.True(ToolTipService.GetShowOnDisabled(known), "a disabled ▾ still says why");
|
||||
Assert.Equal(AutomationLiveSetting.Polite, AutomationProperties.GetLiveSetting(
|
||||
app.FindAll<StatusGlyph>().First(g => g.IsVisible && g.Text == shell.Server.StatusText)));
|
||||
|
||||
// The web admin admits administrators only: the sample user is an editor.
|
||||
Assert.False(table.CanOpenAdmin);
|
||||
Assert.False(app.FindAll<Button>().Any(b => b.Content as string == Loc.L("Server.Sync.OpenAdmin") && b.IsVisible), "no admin link for an editor");
|
||||
|
||||
// Transfers in every state: the rows show what moves and offer Pause or Resume.
|
||||
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], Actions(comet));
|
||||
Assert.Contains("46", comet.ServerText);
|
||||
Assert.Equal(StatusKind.Queued, Row(table, "Fog lifting, Asti").StateKind);
|
||||
// One job at a time (owner review 1): the download halfway waits for the upload.
|
||||
Assert.Equal((StatusKind.Queued, Loc.L("Server.Sync.State.Waiting")), (Row(table, "Sunrise over Superga").StateKind, Row(table, "Sunrise over Superga").StateText));
|
||||
Assert.SequenceEqual([SyncAction.Resume], Actions(Row(table, "Lake Como storm")));
|
||||
await app.ExpectAsync<ServerView>("server-sync");
|
||||
|
||||
// A reload keeps the row's buttons (focus, tooltips and clicks survive progress and comparisons).
|
||||
var pause = comet.Actions[0];
|
||||
await table.ReloadAsync();
|
||||
Assert.Same(pause, Row(table, "Comet over the ridge").Actions[0]);
|
||||
|
||||
// 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");
|
||||
|
||||
// One row, no scrolling: the header still lines up with the cells (same padding, constant scroll-bar gutter).
|
||||
var only = table.Rows[0];
|
||||
Assert.Approximately(Left(Text(app, Loc.L("Server.Sync.Column.Local"))), Left(Text(app, only.LocalText)), 1.5, "This PC column");
|
||||
Assert.Approximately(Left(Text(app, Loc.L("Server.Sync.Column.State"))),
|
||||
Left(app.FindAll<StatusGlyph>().First(g => g.DataContext == only && g.IsVisible)), 1.5, "State column");
|
||||
|
||||
// No match: one sentence and its one action, which shows every sequence again.
|
||||
table.SearchText = "nothing like this";
|
||||
Assert.False(table.HasRows);
|
||||
Assert.NotNull(table.EmptyText);
|
||||
Assert.Equal(SyncEmpty.NoMatch, table.Empty);
|
||||
table.ClearFiltersCommand.Execute(null);
|
||||
Assert.Equal(string.Empty, table.SearchText);
|
||||
Assert.True(Chip(table, SyncFilter.All).IsSelected);
|
||||
Assert.Equal(Chip(table, SyncFilter.All).Count, table.Rows.Count);
|
||||
|
||||
// Another language relabels chips and rows at once.
|
||||
UiLanguage.Apply("it");
|
||||
try
|
||||
{
|
||||
Assert.Equal("Tutte · 38", Chip(table, SyncFilter.All).Text);
|
||||
}
|
||||
finally
|
||||
{
|
||||
UiLanguage.Apply("en");
|
||||
}
|
||||
});
|
||||
|
||||
[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);
|
||||
Assert.Equal(SyncEmpty.SignedOut, shell.Server.Sync.Empty);
|
||||
Assert.False(shell.Server.Sync.UploadAllCommand.CanExecute(null));
|
||||
Assert.Equal(Loc.L("Tooltips.Server.Sync.UploadAll.NotConnected"), shell.Server.Sync.UploadAllToolTip);
|
||||
shell.Navigate(SectionKey.Server);
|
||||
await app.ExpectAsync<ServerView>("server-signedout-table");
|
||||
|
||||
// Nothing to filter while signed out: chips and search give way to the one action, Connect.
|
||||
Assert.False(app.FindAll<RadioButton>().Any(r => r.DataContext is SyncFilterChip && r.IsVisible), "no filter chips while signed out");
|
||||
Assert.False(app.FindAll<TextBox>().Any(t => AutomationProperties.GetName(t) == Loc.L("Server.Sync.Search") && t.IsVisible), "no search while signed out");
|
||||
Assert.True(app.FindAll<Button>().Any(b => b.Content as string == Loc.L("Server.Connect") && b.IsVisible), "the empty table offers Connect");
|
||||
});
|
||||
|
||||
private static TextBlock Text(ScreenSmokeTests.SampleApp app, string text) => app.FindAll<TextBlock>().First(t => t.Text == text && t.IsVisible);
|
||||
|
||||
/// <summary>The left edge of an element in window coordinates.</summary>
|
||||
private static double Left(FrameworkElement element) => element.TranslatePoint(new Point(0, 0), Window.GetWindow(element)).X;
|
||||
|
||||
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);
|
||||
|
||||
private static IEnumerable<SyncAction> Actions(SyncRow row) => row.Actions.Select(a => a.Action);
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
using System.Net;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Server;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Protocol.Client;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.App.Tests.Server;
|
||||
|
||||
/// <summary>The login form cancelled while the server is still answering (DESK-8): nothing signs this PC in afterwards.</summary>
|
||||
public sealed class ServerSessionSignInTests
|
||||
{
|
||||
[Test]
|
||||
public async Task CancelEndsTheSignInStillWaitingForTheServer()
|
||||
{
|
||||
var server = new GatedServer { HonoursCancellation = true };
|
||||
var settings = new AppSettings();
|
||||
using var session = new ServerSession(settings, () => { }, server, new PlainProtector());
|
||||
Task<string?>? pending = null;
|
||||
var dialogs = new Dialogs((_, _, signIn) =>
|
||||
{
|
||||
pending = signIn("alberto", "secret");
|
||||
return false;
|
||||
});
|
||||
|
||||
Assert.False(await session.ConnectAsync("nas.local:8443", dialogs));
|
||||
// The request the form left behind was cancelled, and the session dropped the connection it belonged to.
|
||||
await Assert.ThrowsAsync<OperationCanceledException>(() => pending!);
|
||||
Assert.False(session.IsConnected);
|
||||
Assert.Equal(ConnectStep.Idle, session.Flow.Step);
|
||||
Assert.Null(settings.ProtectedToken);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnAnswerArrivingAfterCancelSignsNothingIn()
|
||||
{
|
||||
var server = new GatedServer { HonoursCancellation = false };
|
||||
var settings = new AppSettings();
|
||||
using var session = new ServerSession(settings, () => { }, server, new PlainProtector());
|
||||
Task<string?>? pending = null;
|
||||
var dialogs = new Dialogs((_, _, signIn) =>
|
||||
{
|
||||
pending = signIn("alberto", "secret");
|
||||
return false;
|
||||
});
|
||||
|
||||
Assert.False(await session.ConnectAsync("nas.local:8443", dialogs));
|
||||
// The server accepts the password only now: the answer belongs to a connection that is gone.
|
||||
server.Answer();
|
||||
Assert.NotNull(await pending!);
|
||||
Assert.False(session.IsConnected);
|
||||
Assert.Equal(ConnectStep.Idle, session.Flow.Step);
|
||||
Assert.Null(session.Flow.Token);
|
||||
Assert.Null(settings.ProtectedToken);
|
||||
Assert.Null(settings.ServerUrl);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SignedInJustBeforeTheCancelSignsOutAgain()
|
||||
{
|
||||
var server = new GatedServer { HonoursCancellation = false };
|
||||
server.Answer();
|
||||
var settings = new AppSettings();
|
||||
using var session = new ServerSession(settings, () => { }, server, new PlainProtector());
|
||||
var dialogs = new Dialogs((_, _, signIn) =>
|
||||
{
|
||||
// The server's answer was handled first, then the click on Cancel closed the form.
|
||||
Assert.Null(signIn("alberto", "secret").GetAwaiter().GetResult());
|
||||
return false;
|
||||
});
|
||||
|
||||
Assert.False(await session.ConnectAsync("nas.local:8443", dialogs));
|
||||
Assert.False(session.IsConnected);
|
||||
Assert.Equal(1, server.Logouts);
|
||||
Assert.Null(settings.ProtectedToken);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ASignInTheFormConfirmsIsRemembered()
|
||||
{
|
||||
var server = new GatedServer { HonoursCancellation = true };
|
||||
server.Answer();
|
||||
var settings = new AppSettings();
|
||||
using var session = new ServerSession(settings, () => { }, server, new PlainProtector());
|
||||
var dialogs = new Dialogs((_, _, signIn) => signIn("alberto", "secret").GetAwaiter().GetResult() is null);
|
||||
|
||||
Assert.True(await session.ConnectAsync("nas.local:8443", dialogs));
|
||||
Assert.True(session.IsConnected);
|
||||
Assert.Equal("token-1", settings.ProtectedToken);
|
||||
Assert.Equal(0, server.Logouts);
|
||||
}
|
||||
|
||||
private sealed class Dialogs(Func<string, string?, Func<string, string, Task<string?>>, bool> signIn) : IAppDialogs
|
||||
{
|
||||
public string? PickFolder(string title, string? initialFolder = null) => null;
|
||||
public string? PickJsonFile(string title) => null;
|
||||
public bool Confirm(ConfirmRequest request) => true;
|
||||
public bool SignIn(string server, string? username, Func<string, string, Task<string?>> callback) => signIn(server, username, callback);
|
||||
}
|
||||
|
||||
private sealed class PlainProtector : ITokenProtector
|
||||
{
|
||||
public string Protect(string token) => token;
|
||||
public string? Unprotect(string protectedToken) => protectedToken;
|
||||
}
|
||||
|
||||
/// <summary>A server whose login answers only when the test says so.</summary>
|
||||
private sealed class GatedServer : IServerApiFactory
|
||||
{
|
||||
private readonly TaskCompletionSource _answer = new();
|
||||
|
||||
/// <summary>The request ends when its token is cancelled (as over HTTP); otherwise the answer is already on its way.</summary>
|
||||
public bool HonoursCancellation { get; init; }
|
||||
|
||||
public int Logins { get; private set; }
|
||||
public int Logouts { get; private set; }
|
||||
|
||||
public void Answer() => _answer.TrySetResult();
|
||||
|
||||
public IServerApi Create(Uri baseAddress, IReadOnlyCollection<string> trustedFingerprints) => new Client(this, baseAddress);
|
||||
|
||||
private sealed class Client(GatedServer server, Uri baseAddress) : IServerApi
|
||||
{
|
||||
public Uri BaseAddress { get; } = baseAddress;
|
||||
public string? Token { get; set; }
|
||||
|
||||
public Task<ServerInfo> GetInfoAsync(CancellationToken ct) =>
|
||||
Task.FromResult(new ServerInfo("Studio NAS", "1.3.0", 1, [], null, [], new ServerLimits(0, 0)));
|
||||
|
||||
public async Task<LoginResponse> LoginAsync(string username, string password, CancellationToken ct)
|
||||
{
|
||||
server.Logins++;
|
||||
await (server.HonoursCancellation ? server._answer.Task.WaitAsync(ct) : server._answer.Task);
|
||||
if (password != "secret") throw new ChronosApiException(HttpStatusCode.Unauthorized, new ApiError("bad_credentials", "Wrong"));
|
||||
return new LoginResponse("token-" + server.Logins, User(username), false, DateTimeOffset.UtcNow.AddDays(1));
|
||||
}
|
||||
|
||||
public Task<UserDto> MeAsync(CancellationToken ct) => Task.FromResult(User("alberto"));
|
||||
|
||||
public Task LogoutAsync(CancellationToken ct)
|
||||
{
|
||||
server.Logouts++;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
private static UserDto User(string name) =>
|
||||
new(Guid.Empty, name, null, "editor", 0, 5_000_000_000_000, 0, false, false, DateTimeOffset.UtcNow, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using System.Diagnostics;
|
||||
using Chronos.App.DesignTime;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Tests.Uploader;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.App.Tests.Server;
|
||||
|
||||
public sealed class SyncHostTests
|
||||
{
|
||||
/// <summary>Dialogs that answer like a user who cancels everything.</summary>
|
||||
private sealed class NoDialogs : IAppDialogs
|
||||
{
|
||||
public string? PickFolder(string title, string? initialFolder = null) => null;
|
||||
public string? PickJsonFile(string title) => null;
|
||||
public bool Confirm(ConfirmRequest request) => false;
|
||||
public bool SignIn(string server, string? username, Func<string, string, Task<string?>> signIn) => false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DESK-1: a signed-in user whose archive is not polled (no archive, or offline at start) exits. Nothing before the
|
||||
/// sync agent's stop leaves the UI thread, and the agent stops asynchronously: its continuation must not need the UI
|
||||
/// thread that App.OnExit blocks, or the exit waits 10 s and never closes the engine and the index.
|
||||
/// </summary>
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
public void ExitWithASignedInSessionAndNoPollingDoesNotWaitForTheUiThread()
|
||||
{
|
||||
var environment = AppEnvironment.ForCapture();
|
||||
try
|
||||
{
|
||||
SingleThreadedContext.Run(async () =>
|
||||
{
|
||||
var services = new AppServices(environment, new AppSettings { Language = "en" }, () => { }, new NoDialogs());
|
||||
var sample = SampleData.Configure(services);
|
||||
// An index without the archive poller (OpenAsync never ran) and a saved session, as for a server-only user.
|
||||
await sample.OpenEmptyAsync();
|
||||
await sample.FillAsync();
|
||||
services.Settings.RenderNodeOptIn = false;
|
||||
await services.Server.RestoreAsync();
|
||||
Assert.True(services.Server.IsConnected, "session restored");
|
||||
var until = DateTime.UtcNow + TimeSpan.FromSeconds(10);
|
||||
while (services.Sync.Agent is null)
|
||||
{
|
||||
Assert.True(DateTime.UtcNow < until, "sync agent not started");
|
||||
await Task.Delay(20);
|
||||
}
|
||||
|
||||
// App.OnExit blocks the UI thread until the services stop.
|
||||
var clock = Stopwatch.StartNew();
|
||||
Assert.True(services.DisposeAsync().AsTask().Wait(TimeSpan.FromSeconds(10)), "services stopped");
|
||||
Assert.Less(clock.Elapsed.TotalSeconds, 5, "the exit waited for the UI thread");
|
||||
Assert.Null(services.Sync.Agent);
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
environment.DeleteCaptureData();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
using Chronos.App.Server;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Testing;
|
||||
using Chronos.Ui.Controls;
|
||||
|
||||
namespace Chronos.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, true), Editor);
|
||||
Assert.Equal(new SyncRights(false, false, false), Viewer);
|
||||
Assert.Equal(new SyncRights(false, true, false), 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));
|
||||
|
||||
// Without the edit right nothing of this PC is sent: no "Keep mine", no settings push.
|
||||
Assert.SequenceEqual([SyncAction.TakeServer, SyncAction.SaveBoth], SyncText.Actions(Entry(SyncStatus.Conflict), Viewer));
|
||||
Assert.Empty(SyncText.Actions(Entry(SyncStatus.LocalAhead), Viewer));
|
||||
Assert.SequenceEqual([SyncAction.SyncSettings], SyncText.Actions(Entry(SyncStatus.ServerAhead), Viewer));
|
||||
|
||||
// Renders travel on request once the originals agree.
|
||||
var exports = Link with { ExportsToGet = 3, ExportsToGetBytes = 1_900_000_000, ExportsToSend = 1, ExportsToSendBytes = 600_000_000 };
|
||||
Assert.SequenceEqual([SyncAction.GetExports, SyncAction.SendExports], SyncText.Actions(Entry(SyncStatus.InSync, exports), Editor));
|
||||
Assert.SequenceEqual([SyncAction.GetExports], SyncText.Actions(Entry(SyncStatus.InSync, exports), Viewer));
|
||||
Assert.SequenceEqual([SyncAction.KeepMine, SyncAction.TakeServer, SyncAction.SaveBoth], SyncText.Actions(Entry(SyncStatus.Conflict, exports), Editor));
|
||||
Assert.Equal(Loc.Plural("Tooltips.Server.Sync.GetExports", 3, Chronos.App.Infrastructure.Formatting.Bytes(1_900_000_000)),
|
||||
SyncText.ToolTip(Entry(SyncStatus.InSync, exports), SyncAction.GetExports));
|
||||
|
||||
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 AConflictNamesTheSettingsThatDifferInWords()
|
||||
{
|
||||
var theirs = new SyncPayload(Local.Title, ["boats"], 0, null, """{"exposure":{"deflickerWindow":{"isAuto":false,"manual":33},"deflicker":{"isAuto":false,"manual":true}}}""");
|
||||
var conflict = Entry(SyncStatus.Conflict, Link with { ConflictRemote = theirs });
|
||||
|
||||
var lines = SyncText.Conflict(conflict, 10);
|
||||
|
||||
Assert.SequenceEqual(
|
||||
[
|
||||
Loc.L("Server.Conflict.Difference", Loc.L("Server.Setting.Tags"), Loc.L("Server.Sync.None"), "boats"),
|
||||
Loc.L("Server.Conflict.Difference", Loc.L("Server.Setting.Deflicker"), Loc.L("Server.Setting.Auto"), Loc.L("Server.Setting.Manual")),
|
||||
Loc.L("Server.Conflict.Difference", Loc.L("Server.Setting.DeflickerWindow"), "41", "33"),
|
||||
], lines);
|
||||
// The State tooltip is one line: the first difference and how many more.
|
||||
Assert.Equal(Loc.L("Server.Conflict.More", lines[0], "2"), SyncText.State(conflict).ToolTip);
|
||||
Assert.False(SyncText.State(conflict).ToolTip.Contains('\n', StringComparison.Ordinal), "one line");
|
||||
Assert.Equal(Loc.L("Tooltips.Server.Sync.State.Conflict"), SyncText.ConflictSummary(Entry(SyncStatus.Conflict)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ASequenceThatCouldNotBeComparedSaysWhy()
|
||||
{
|
||||
var (kind, text, tip) = SyncText.State(Entry(SyncStatus.InSync, Link with { Error = "403 forbidden" }));
|
||||
|
||||
Assert.Equal((StatusKind.Warning, Loc.L("Server.Sync.State.Failed")), (kind, text));
|
||||
Assert.Contains("403 forbidden", tip);
|
||||
}
|
||||
|
||||
[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")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ATransferCountsWhereItsOriginalsAre()
|
||||
{
|
||||
var uploadNotOnServer = Entry(SyncStatus.Transferring, transfer: Upload(JobState.Queued)) with { Link = null };
|
||||
var download = new Job { Id = Guid.CreateVersion7(), Kind = JobKind.Download, State = JobState.Running };
|
||||
var downloadNotHere = Entry(SyncStatus.Transferring, transfer: download) with { Local = null };
|
||||
var uploadOnBoth = Entry(SyncStatus.Transferring, transfer: Upload(JobState.Running));
|
||||
|
||||
Assert.True(SyncText.Matches(uploadNotOnServer, SyncFilter.LocalOnly, string.Empty));
|
||||
Assert.False(SyncText.Matches(uploadNotOnServer, SyncFilter.Remote, string.Empty));
|
||||
Assert.True(SyncText.Matches(downloadNotHere, SyncFilter.Remote, string.Empty));
|
||||
Assert.False(SyncText.Matches(downloadNotHere, SyncFilter.LocalOnly, string.Empty));
|
||||
// Partly on both sides: neither "only here" nor "only on the server".
|
||||
Assert.False(SyncText.Matches(uploadOnBoth, SyncFilter.LocalOnly, string.Empty));
|
||||
Assert.False(SyncText.Matches(uploadOnBoth, SyncFilter.Remote, string.Empty));
|
||||
Assert.True(SyncText.Matches(uploadOnBoth, SyncFilter.All, string.Empty));
|
||||
}
|
||||
|
||||
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 };
|
||||
}
|
||||
Reference in new issue
Block a user