Files
Chronos/tests/Chronos.App.Tests/Server/SyncTextTests.cs
T
Alby96andClaude Opus 5.5 64fc5521c0 fix(workspace): settle conflicts in one answer and give refused folders a way on
Phase 5a fix round 2 of owner review 2 (desktop):

- Take library's no longer commits the working state first, so a take that
  leaves only the library's values sends no empty version; the working state
  it replaces is kept aside in versions/.replaced, outside the chain.
- Conflicts list this side's value as the working state holds it, so one
  answer settles them instead of asking again for the newer value.
- A conflict of format (library saved by a newer Chronos) offers only Save
  both and Later, says why in its tooltip and shows no raw format numbers.
- Conflict lines count the photos a setting differs on ("Excluded frames
  (3)") instead of dropping the duplicates.
- A read-only library is named as such, not as offline; checkouts from it
  stay editable and their versions wait in the workspace.
- A workspace folder refused inside a library offers Choose folder, and
  Settings > Workspace gets Change...: a plan (projects left, projects found)
  is confirmed before the folder changes; nothing is moved.
- Open in workspace shows the copy's size and the drive's free space, and
  warns when the copy would not fit with its 0.5 GB reserve.
- A cancelled first copy removes the half media it wrote.
- A copy whose project.chronos cannot be read is listed as damaged instead of
  hidden, and goes only through Remove local copy > Discard, after a plan.
- Pruning keeps a version whose archive file is damaged (test added).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 11:52:49 +01:00

207 lines
12 KiB
C#

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 ASettingDifferingOnSeveralPhotosIsOneLineWithTheirCount()
{
var keyframes = new SettingsDifference("pendingFrames.sha:ab12#0.keyframes", "[]", "[{\"x\":1}]");
var lines = SyncText.Differences(
[
new SettingsDifference("pendingFrames.sha:ab12#0.excluded", "true", "false"),
keyframes,
new SettingsDifference("pendingFrames.sha:cd34#0.excluded", "true", "false"),
new SettingsDifference("pendingFrames.sha:ef56#1.excluded", "false", "true"),
new SettingsDifference("pendingFrames.sha:ab12#0.excluded", "true", "false"),
], 10);
// Counted by photo, in the order the settings were met; a setting on one photo keeps its values.
Assert.SequenceEqual(
[Loc.L("Server.Conflict.Count", Loc.L("Server.Setting.ExcludedFrames"), Chronos.App.Infrastructure.Formatting.Count(3)), SyncText.Differences([keyframes], 1)[0]],
lines);
Assert.Contains(Loc.L("Server.Setting.Keyframes"), lines[1]);
Assert.Count(1, SyncText.Differences([new SettingsDifference("pendingFrames.sha:ab12#0.excluded", "true", "false")], 10));
Assert.Contains(Loc.L("Server.Setting.ExcludedFrames"), SyncText.Differences([new SettingsDifference("pendingFrames.sha:ab12#0.excluded", "true", "false")], 10)[0]);
}
[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 };
}