Files
Chronos/tests/Chronos.App.Tests/Server/SyncTextTests.cs
T
Alby96andClaude Opus 5.5 26bab759fe feat(app): workspace projects whose home is a server, pushed and pulled like this PC's archive
Owner review 2, R8, phase 5b (client part), ported onto the final phase 5a.
A Chronos Server with the "projects" capability is now the home of
workspace projects. A server sequence is edited in the workspace like a
local one, not inside the library, and its versions sync with the server
"like git".

- Data: ServerProjectHome is an IProjectHome over ChronosClient.
  - These are HomeUnavailableException, so the workspace shows Offline: a
    server out of reach, an expired sign-in, a 503 (lease, offline archive,
    projects_unreadable), a 409 folder_in_use, and a server without projects.
  - 404 sequence/project/version and refused names are ProjectException;
    other refusals keep their meaning.
  - A deleted project's head is 404 project, so final 5a's HeadAsync NotFound
    rule reads it as Gone. The original 5b's IsLiveAsync and
    WorkspaceStatus.Gone are dropped. IProjectHome gains rename and delete.
- Data: WorkspaceJobs.CopyFromServer downloads into the workspace, through
  the desktop's session, the proxies of one frames version (or the
  thumbnails standing in for them), with the aliases of the server's
  conversions. It is rebuilt on final 5a's copy handler:
  - the copy:frame:fv:folder checkpoint, EnsureSpace (from the server's proxy
    sizes), WritingMedia, and the cancelled-copy clean-up;
  - the editor's current file is never overwritten;
  - each file is hashed as it arrives and checked on disk, four at a time.
  It never writes this PC's archive. Originals are still refused until 5c.
- Data: SyncAgent passes on the server's projectChanged events, and after a
  lost event stream it reports that changes may have been missed.
- App: SyncHost gives the server home over one session client. The Server
  screen offers Open in workspace, disabled with its reason on older
  servers, whose sequences keep opening with proxies.
- App: Edit opens or checks out server projects with final 5a's refusals:
  unreadable copies, a disabled damaged or newer Main, a refused folder. The
  "sequence left the index" refusal now applies only to projects of this
  PC's archive.
- App: the picker and the chip follow projectChanged (Server newer, Not on
  server). Every state, conflict, delete, remove and failure text uses its
  ".Server" form when one exists (WorkspaceText.ForHome). That includes 5a's
  newer-format conflict, the save conflict, the taken-values toast, Gone and
  version-too-large.
- App: a render of a server project first offers to send what is not on the
  server, then renders the version the server holds. Offline, Gone, Damaged
  and missing media hold the render. Analyses and renders run as server jobs
  (ServerJobs, shared with RemoteSequenceSource).
- Pruning keeps final 5a's rule: a version is pruned only after HoldsAsync
  reads it back.
- Strings in en and it; ARCHITECTURE, DECISIONS and CHANGELOG.

Tests:
- ServerProjectHome error mapping, using a fake handler.
- Against the in-process server:
  - two workspaces on one project: fast-forward, replay and merge, keep mine,
    take server, save both, restore;
  - the copy job verifying, resuming and following new frames;
  - a project deleted on the server (Gone from its head; a push sends
    nothing);
  - an offline server.
- SyncAgent project events.
- App tests for the host, the project menu and renders of a server home.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 11:45:06 +01:00

240 lines
15 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));
// A server that keeps no projects opens its sequences with proxies; the workspace is offered disabled (owner review 2, R8).
Assert.SequenceEqual([SyncAction.OpenWithProxies, SyncAction.DownloadOriginals, SyncAction.OpenInWorkspace],
SyncText.Actions(Entry(SyncStatus.RemoteOnly, local: null), Editor));
Assert.SequenceEqual([SyncAction.OpenWithProxies, SyncAction.OpenInWorkspace], 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 async Task AServerThatKeepsProjectsOpensItsSequencesInTheWorkspace()
{
// Owner review 2, R8, phase 5b: the workspace replaces Open with proxies, and the originals can still come down.
var projects = Editor with { KeepsProjects = true };
Assert.SequenceEqual([SyncAction.OpenInWorkspace, SyncAction.DownloadOriginals], SyncText.Actions(Entry(SyncStatus.RemoteOnly, local: null), projects));
Assert.SequenceEqual([SyncAction.OpenInWorkspace], SyncText.Actions(Entry(SyncStatus.ProxiesOnly, local: null), Viewer with { KeepsProjects = true }));
Assert.True(SyncText.IsEnabled(SyncAction.OpenInWorkspace, projects), "a server that keeps projects opens them");
Assert.Equal(Loc.L("Tooltips.Server.Sync.OpenInWorkspace"), SyncText.ToolTip(Entry(SyncStatus.RemoteOnly, local: null), SyncAction.OpenInWorkspace, projects));
// An older server's row says why its workspace action is disabled; the other actions are not.
Assert.False(SyncText.IsEnabled(SyncAction.OpenInWorkspace, Editor), "an older server keeps no projects");
Assert.True(SyncText.IsEnabled(SyncAction.OpenWithProxies, Editor), "proxies open as before");
Assert.Equal(Loc.L("Tooltips.Server.Sync.OpenInWorkspace.NoProjects"), SyncText.ToolTip(Entry(SyncStatus.RemoteOnly, local: null), SyncAction.OpenInWorkspace, Editor));
// The row's button is disabled with its reason, and enabled once the server keeps projects.
var acted = new List<SyncAction>();
var row = new SyncRow(Entry(SyncStatus.RemoteOnly, local: null), Editor, (_, action) =>
{
acted.Add(action);
return Task.CompletedTask;
});
var workspace = row.Actions.Single(a => a.Action == SyncAction.OpenInWorkspace);
Assert.Equal((false, Loc.L("Tooltips.Server.Sync.OpenInWorkspace.NoProjects")), (workspace.Command.CanExecute(null), workspace.ToolTip));
row.Update(Entry(SyncStatus.RemoteOnly, local: null), projects);
workspace = row.Actions.First();
Assert.Equal((SyncAction.OpenInWorkspace, true), (workspace.Action, workspace.Command.CanExecute(null)));
workspace.Command.Execute(null);
await Task.Yield();
Assert.SequenceEqual([SyncAction.OpenInWorkspace], acted);
}
[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 };
}