Files
Chronos/tests/Titano.App.Tests/Server/ServerScreenSmokeTests.cs
T
Claude 2d40a613b9 fix(sync): resolve conflicts against the versions shown, isolate failures, renders on request
- Conflicts are settled against the versions the user was shown; a later change on
  either side refuses the choice and compares again. Title, tags, rating and notes
  changed differently on both sides are a conflict too (no silent tag union).
- Links are written under the engine's gate and forgotten only after a 404; linked
  local copies are read by id; unlinked copies with the same originals are linked
  by content.
- A failure on one sequence is recorded on its link; the others are still compared.
- Downloads hash unverified local copies first and restore originals missing here.
- Background proxy downloads give way to the user's requests; "Keep proxies offline"
  refreshes the caches of sequences opened with proxies, checks free space and backs
  off after a failure.
- Renders travel on request: Send exports (chunked, hash-verified upload keeping the
  render id; new POST /sequences/{id}/renders endpoints) and Get exports.
- Server screen: stable row buttons, mockup column grid, Tab through rows, conflict
  rows first on the card colour, localised conflict detail, Save both confirmation,
  Pause metered uploads, culture switch, Library one-word sync glyphs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-03 10:26:56 +00:00

152 lines
7.9 KiB
C#

using System.Windows.Controls;
using System.Windows.Input;
using Titano.App.Infrastructure;
using Titano.App.Sections;
using Titano.App.Server;
using Titano.App.Shell;
using Titano.App.Tests.Windows;
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>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));
Assert.Equal(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");
// 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);
Assert.Equal((StatusKind.Running, Loc.L("Server.Sync.State.Downloading")), (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");
table.SearchText = "nothing like this";
Assert.False(table.HasRows);
Assert.NotNull(table.EmptyText);
// 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.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");
});
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);
}