fix(copies): close the sixth verification round of owner review 6

A merge that finds the other changed drops its journal so the retry plans
again. Unlink and Keep apart name the local side and leave a link that now
joins another sequence alone; Link only and the Integrate job refuse to
touch a link or a pair another integration holds. A sweep of 404s asks the
server once. To trash... trashes from the kept sequence after a swap and
every trash re-checks for new last copies. The Compare dialog and Settings
choices fit in every language, Details segments say which value they take,
twins need their sibling at the other home, and a linked row keeps three
buttons. Captures updated for the dialog and Settings scenes.

Refs #73

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-17 21:58:58 +01:00
1 parent bf7701d279
commit 38764972ad
77 files changed
+965 -123

No files matched your search

@@ -1,4 +1,8 @@
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Media;
using Chronos.App.DesignTime;
using Chronos.App.Infrastructure;
using Chronos.App.Library;
using Chronos.App.Sections;
@@ -176,6 +180,9 @@ public sealed class CopyScreenSmokeTests
var detail = merge.Details[0];
Assert.Equal(detail.Line.There ?? Loc.L("Server.Sync.None"), detail.HereToolTip);
Assert.Equal(detail.Line.Here ?? Loc.L("Server.Sync.None"), detail.ThereToolTip);
// The segments say what choosing them does, with the worded value each takes, not the raw value.
Assert.Equal(Loc.L("Tooltips.Server.Copies.Detail.UseKept", detail.HereText), detail.HereChoiceToolTip);
Assert.Equal(Loc.L("Tooltips.Server.Copies.Detail.UseOther", detail.ThereText), detail.ThereChoiceToolTip);
detail.ChoiceIndex = 0;
await merge.PlanNowAsync();
@@ -215,6 +222,16 @@ public sealed class CopyScreenSmokeTests
var scroll = Assert.Contains(app.FindAll<ScrollViewer>(), s => s.IsVisible && s.ScrollableHeight > 0
&& s.Content is Grid grid && grid.Children.OfType<ItemsControl>().Count() == 2);
Assert.True(scroll.ViewportHeight > 0);
// Each heading shares its list's column, so the scroll bar never moves a list off its heading.
var lists = ((Grid)scroll.Content).Children.OfType<ItemsControl>().ToList();
var headings = ((Grid)scroll.Content).Children.OfType<TextBlock>().ToList();
Assert.Count(2, headings);
for (var i = 0; i < 2; i++)
{
var window = Window.GetWindow(scroll);
Assert.Approximately(lists[i].TranslatePoint(new Point(0, 0), window).X, headings[i].TranslatePoint(new Point(0, 0), window).X, 0.5,
$"heading {i} starts where its list does");
}
// The sample pair has its own projects back for the other scenes.
var lighthouse = shell.Server.Sync.Copies.Pairs.Single(p => p.Here.Title == CopyScenes.Lighthouse);
Assert.Equal(2, (await shell.Services.Sync.Copies!.CompareAsync(lighthouse.Copy.Id, null, CancellationToken.None)).Projects.Here.Count);
@@ -370,6 +387,217 @@ public sealed class CopyScreenSmokeTests
CopyScenes.Reset(shell);
});
[Test]
public Task ASwappedMergeOffersToTrashOnDeletedInOtherFromTheKeptSequenceOnly() => ScreenHost.RunAsync(async () =>
{
await using var app = await StartAsync();
var shell = app.Shell;
var engine = (SampleCopyEngine)shell.Services.Sync.Copies!;
var list = shell.Server.Sync.Copies;
await CopyScenes.ShowAsync(shell, "server-copies");
var alps = list.Pairs.Single(p => p.Here.Title == CopyScenes.Alps);
var start = new DateTime(2025, 7, 14, 5, 30, 0);
// The pair's first deleted 3 photos its other still holds (Deleted here), and the other deleted 2 the first holds.
var restore = engine.With(alps.Copy.Id, p => p with
{
Photos = [.. p.Photos, .. SampleCopies.Photos(PhotoClass.DeletedHere, 3, start, 950, here: false, there: true),
.. SampleCopies.Photos(PhotoClass.DeletedThere, 2, start, 960, here: true, there: false)],
});
try
{
var dialog = Assert.NotNull(list.Open(alps, CopyDialogPart.Photos, PhotoClass.DeletedHere));
await dialog.LoadAsync();
Assert.Equal(alps.Copy.OtherId, dialog.KeepOptions.Single(o => o.IsChecked).SequenceId);
// Kept: the pair's other. Its "Deleted in other" (the first deleted them) offers To trash…, from the kept one.
var deletedInOther = dialog.Classes.Single(c => c.Class == PhotoClass.DeletedHere);
Assert.Equal(CopyText.Class(PhotoClass.DeletedThere, merge: true), deletedInOther.Text);
dialog.SelectedClass = deletedInOther;
Assert.True(dialog.CanTrashHere);
var plan = await dialog.PlanTrashHereAsync([dialog.Photos[0].Key]);
Assert.Equal(alps.Copy.OtherId, plan.Plan.Sequence.Id);
// "Deleted in kept": its frames are the dropped sequence's, which go with the merge; no To trash….
var deletedInKept = dialog.Classes.Single(c => c.Class == PhotoClass.DeletedThere);
Assert.Equal(CopyText.Class(PhotoClass.DeletedHere, merge: true), deletedInKept.Text);
dialog.SelectedClass = deletedInKept;
Assert.False(dialog.CanTrashHere);
// Kept: the pair's first. Now Deleted there reads "Deleted in other" and trashes from the first.
dialog.KeepOptions.Single(o => o.SequenceId == alps.Copy.LocalId).IsChecked = true;
dialog.SelectedClass = dialog.Classes.Single(c => c.Class == PhotoClass.DeletedThere);
Assert.True(dialog.CanTrashHere);
Assert.Equal(alps.Copy.LocalId, (await dialog.PlanTrashHereAsync([dialog.Photos[0].Key])).Plan.Sequence.Id);
dialog.SelectedClass = dialog.Classes.Single(c => c.Class == PhotoClass.DeletedHere);
Assert.False(dialog.CanTrashHere);
}
finally
{
restore();
CopyScenes.Reset(shell);
}
});
[Test]
public Task InMainMarksTheVersionTheKeptSequencesMainUses() => ScreenHost.RunAsync(async () =>
{
await using var app = await StartAsync();
var shell = app.Shell;
var dialog = Assert.NotNull(await CopyScenes.ShowAsync(shell, "server-copies-versions"));
var alps = shell.Server.Sync.Copies.Pairs.Single(p => p.Here.Title == CopyScenes.Alps);
var review = await shell.Services.Sync.Copies!.CompareAsync(alps.Copy.Id, null, CancellationToken.None);
Assert.Equal(alps.Copy.OtherId, dialog.KeepOptions.Single(o => o.IsChecked).SequenceId);
// The two Mains use different versions: the kept sequence's (the pair's other) is marked.
Assert.Count(1, dialog.Photos.Where(p => p.InMain));
foreach (var marked in dialog.Photos.Where(x => x.InMain)) Assert.DoesNotContain(marked.Key, review.ExcludedThere);
await app.ExpectAsync<ServerView>("server-copies-versions");
// Both sides hold both versions: the side reads whole beside "In Main", and Drop… keeps its gap.
var view = app.FindAll<ServerView>().First(v => v.IsVisible);
foreach (var row in app.FindAll<ListBoxItem>().Where(i => i is { DataContext: CopyPhotoRow, IsVisible: true }))
{
var photo = (CopyPhotoRow)row.DataContext;
var side = Descendants<TextBlock>(row).Single(t => t.Text == photo.SideText);
// Layout rounding may take under a pixel; a trimmed text loses a whole character to the ellipsis.
Assert.True(Needed(side, side.Text) <= side.ActualWidth + 1.0, $"'{side.Text}' needs {Needed(side, side.Text):0.0} px, has {side.ActualWidth:0.0}");
var drop = Descendants<Button>(row).Single(b => b.IsVisible);
Assert.True(drop.Margin.Left >= 10, "Drop… keeps a gap from the side cell");
}
Assert.NotNull(view);
// Kept: the pair's first. The marker follows its Main.
dialog.KeepOptions.Single(o => o.SequenceId == alps.Copy.LocalId).IsChecked = true;
Assert.Count(1, dialog.Photos.Where(p => p.InMain));
foreach (var marked in dialog.Photos.Where(x => x.InMain)) Assert.DoesNotContain(marked.Key, review.ExcludedHere);
CopyScenes.Reset(shell);
});
[Test]
public Task ATwinNeedsItsSiblingAtTheOtherHome() => ScreenHost.RunAsync(async () =>
{
await using var app = await StartAsync();
var shell = app.Shell;
var engine = (SampleCopyEngine)shell.Services.Sync.Copies!;
// The integrated pair: Main and Vertical on this PC, only Main on the server.
var bridge = engine.Pairs.Single(p => p.Copy is { Kind: CopyKind.LocalServer, State: CopyState.Integrated });
Assert.SequenceEqual(["Main", "Vertical"], bridge.Projects.Here.Select(p => p.Name));
Assert.SequenceEqual(["Main"], bridge.Projects.There.Select(p => p.Name));
await CopyScenes.ShowAsync(shell, "edit-picker-twins");
var picker = shell.Sequence.Picker;
var home = Chronos.App.Workspace.WorkspaceHost.ArchiveHome(bridge.Copy.LocalId);
IReadOnlyList<Chronos.App.Workspace.WorkspaceEntry> entries =
[
new(Guid.CreateVersion7(), bridge.Copy.LocalId, "Main", true, home, bridge.Here.Title, HasMedia: true, SampleData.Now),
new(Guid.CreateVersion7(), bridge.Copy.LocalId, "Vertical", false, home, bridge.Here.Title, HasMedia: true, SampleData.Now),
];
await picker.ShowSampleWorkspaceAsync(entries, new Chronos.Data.Workspaces.WorkspaceStatus(Chronos.Data.Workspaces.WorkspaceState.InSync, false, 0, 0,
false, false, false, null, null, null));
var main = picker.WorkspaceItems.Single(i => i.Entry.Name == "Main");
var vertical = picker.WorkspaceItems.Single(i => i.Entry.Name == "Vertical");
Assert.True(main.HasTwin, "Main has its sibling on the server");
Assert.Contains(main.Name, main.TwinToolTip!);
Assert.False(vertical.HasTwin, "Vertical is only on this PC");
CopyScenes.Reset(shell);
});
[Test]
public Task TheDialogsPolicyAndVersionChoicesFitTheirBoxesInEveryLanguage() => ScreenHost.RunAsync(async () =>
{
await using var app = await StartAsync();
var shell = app.Shell;
var dialog = Assert.NotNull(await CopyScenes.ShowAsync(shell, "server-copies-choose"));
await app.ExpectAsync<ServerView>("server-copies-choose");
var policy = app.FindAll<ComboBox>().Single(c => c.IsVisible && AutomationProperties.GetName(c) == Loc.L("Server.Copies.Policy.Label"));
var version = app.FindAll<ComboBox>().First(c => c.IsVisible && c.DataContext is CopyPhotoRow);
List<string> misses = [];
try
{
foreach (var language in Languages.Shipped)
{
UiLanguage.Apply(language);
app.Window.UpdateLayout();
await app.Window.Dispatcher.InvokeAsync(() => { }, System.Windows.Threading.DispatcherPriority.ApplicationIdle);
foreach (var merge in new[] { false, true })
{
Fits(misses, language, policy, CopyDialogViewModel.PolicyOptions(merge).Select(o => o.Label));
Fits(misses, language, version, CopyDialogViewModel.VersionChoices(merge).Select(o => o.Label));
}
}
}
finally
{
UiLanguage.Apply("en");
}
Assert.True(misses.Count == 0, string.Join(Environment.NewLine, misses));
Assert.NotNull(dialog);
CopyScenes.Reset(shell);
});
[Test]
public Task TheMatchesSettingsFitTheirBoxesInEveryLanguage() => ScreenHost.RunAsync(async () =>
{
await using var app = await StartAsync();
var shell = app.Shell;
var settings = shell.Settings;
shell.Navigate(SectionKey.Settings);
settings.Page = SettingsPage.Server;
await app.ExpectAsync<Chronos.App.Sections.SettingsView>("settings-server");
string[] names = ["Settings.Server.CopyLinking", "Settings.Server.CopyPhotos", "Settings.Server.CopyProjects"];
List<string> misses = [];
try
{
foreach (var language in Languages.Shipped)
{
UiLanguage.Apply(language);
settings.CopyRows.Refresh();
app.Window.UpdateLayout();
await app.Window.Dispatcher.InvokeAsync(() => { }, System.Windows.Threading.DispatcherPriority.ApplicationIdle);
foreach (var name in names)
{
var box = app.FindAll<ComboBox>().Single(c => c.IsVisible && AutomationProperties.GetName(c) == Loc.L(name));
var labels = box.ItemsSource.Cast<object>().Select(o => (string)o.GetType().GetProperty("Label")!.GetValue(o)!);
Fits(misses, language, box, labels);
}
}
}
finally
{
UiLanguage.Apply("en");
settings.CopyRows.Refresh();
}
Assert.True(misses.Count == 0, string.Join(Environment.NewLine, misses));
});
/// <summary>
/// Adds to <paramref name="misses"/> each label that does not show whole in <paramref name="box"/>'s selection box (its
/// content site, inside the margins).
/// </summary>
private static void Fits(List<string> misses, string language, ComboBox box, IEnumerable<string> labels)
{
box.ApplyTemplate();
var site = (FrameworkElement)box.Template.FindName("ContentSite", box);
var room = box.ActualWidth - site.Margin.Left - site.Margin.Right - box.BorderThickness.Left - box.BorderThickness.Right;
var probe = new TextBlock { FontFamily = box.FontFamily, FontSize = box.FontSize, FontWeight = box.FontWeight, FlowDirection = box.FlowDirection };
foreach (var label in labels.Where(l => Needed(probe, l) > room + 0.5))
misses.Add($"{language}: '{label}' needs {Needed(probe, label):0.0} px, its box has {room:0.0}");
}
/// <summary>The width <paramref name="text"/> takes in <paramref name="cell"/>'s font.</summary>
private static double Needed(TextBlock cell, string text) => new FormattedText(text, System.Globalization.CultureInfo.CurrentUICulture, cell.FlowDirection,
new Typeface(cell.FontFamily, cell.FontStyle, cell.FontWeight, cell.FontStretch), cell.FontSize, Brushes.Black, 1.0).WidthIncludingTrailingWhitespace;
private static IEnumerable<T> Descendants<T>(DependencyObject node)
where T : DependencyObject
{
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(node); i++)
{
var child = VisualTreeHelper.GetChild(node, i);
if (child is T match) yield return match;
foreach (var inner in Descendants<T>(child)) yield return inner;
}
}
private static async Task<Toast> ToastAsync(List<Toast> raised, string title)
{
for (var i = 0; i < 250 && !raised.Any(t => t.Title == title); i++) await Task.Delay(20);
@@ -46,8 +46,13 @@ public sealed class CopyTextTests
Assert.SequenceEqual([CopyAction.Compare, CopyAction.Merge, CopyAction.KeepApart], CopyText.Actions(Copy(CopyState.Candidate, CopyKind.LocalLocal)));
Assert.SequenceEqual([CopyAction.Compare, CopyAction.AskAgain], CopyText.Actions(Copy(CopyState.KeptApart)));
Assert.SequenceEqual([CopyAction.Compare, CopyAction.Integrate, CopyAction.Unlink], CopyText.Actions(Copy(CopyState.Linked)));
Assert.SequenceEqual([CopyAction.Compare, CopyAction.Integrate, CopyAction.Unlink, CopyAction.Review],
CopyText.Actions(Copy(CopyState.Linked, deletedThere: 3)));
// Three buttons at most: a linked pair with photos deleted there reaches Integrate through Compare… or Review.
Assert.SequenceEqual([CopyAction.Compare, CopyAction.Unlink, CopyAction.Review], CopyText.Actions(Copy(CopyState.Linked, deletedThere: 3)));
foreach (var state in Enum.GetValues<CopyState>())
{
foreach (var copy in new[] { Copy(state), Copy(state, deletedThere: 3), Copy(state, gone: true), Copy(state, CopyKind.LocalLocal, deletedThere: 3) })
Assert.LessOrEqual(CopyText.Actions(copy).Count, 3, $"{state}: at most three row buttons");
}
Assert.SequenceEqual([CopyAction.Compare, CopyAction.Unlink], CopyText.Actions(Copy(CopyState.Integrated)));
Assert.SequenceEqual([CopyAction.Compare, CopyAction.Unlink, CopyAction.Review], CopyText.Actions(Copy(CopyState.Integrated, deletedThere: 3)));
Assert.SequenceEqual([CopyAction.Pause], CopyText.Actions(Copy(CopyState.Integrating), JobState.Running));