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>
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));
|
||||
|
||||
@@ -687,6 +687,47 @@ public abstract class SequenceMergerTests(TestContext context) : DatabaseTest(co
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AFrameRemovedFromTheOtherAfterAStoppedTrashMakesTheNextRetryPlanAgain()
|
||||
{
|
||||
var fx = await FixtureAsync();
|
||||
var merger = Merger(fx);
|
||||
var workspace = new FakeWorkspace();
|
||||
var (engine, handler) = Engine(fx, merger, new FakeProjects(), workspace);
|
||||
await engine.StartAsync(Ct);
|
||||
var keep = await SequenceAsync(fx, "keep", [(1, 0, "IMG_0001.JPG")]);
|
||||
var drop = await SequenceAsync(fx, "drop", [(1, 0, "IMG_0001.JPG"), (2, 10_000, "IMG_0002.JPG"), (3, 20_000, "IMG_0003.JPG")]);
|
||||
var copy = await PairAsync(fx, keep.Id, drop.Id);
|
||||
handler.BeforeStage = stage =>
|
||||
{
|
||||
if (stage == MergeStage.Trash) workspace.Unsent.Add(drop.Id);
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
var plan = await merger.PlanAsync(copy.Id, keep.Id, drop.Id, await ChoicesAsync(fx, keep.Id, drop.Id, CopyPhotoPolicy.Union), NoContext, Ct);
|
||||
var job = await merger.EnqueueAsync(engine, new FoundCopyStore(fx.Db), plan, keep.DisplayTitle, Ct);
|
||||
await fx.WaitForAsync(job.Id, JobState.Failed);
|
||||
Assert.True(File.Exists(MergeJournal.PathFor(fx.Paths, job.Id)), "an unsent workspace keeps the journal");
|
||||
|
||||
// A frame of the other goes to the trash while the merge waits: its frames version never goes back.
|
||||
var gone = (await fx.Db.Frames.ListBySequenceAsync(drop.Id)).First(f => f.Sha256 == Sha(3, 20_000));
|
||||
var trash = await fx.Service.FrameTrash.PlanDeleteAsync(drop.Id, [gone.Id], null, fx.Ct, job.Id);
|
||||
await fx.Service.FrameTrash.DeleteAsync(trash, null, null, fx.Ct, job.Id);
|
||||
handler.BeforeStage = null;
|
||||
workspace.Unsent.Clear();
|
||||
await engine.ResumeAsync(job.Id, Ct);
|
||||
var failed = await fx.WaitForAsync(job.Id, JobState.Failed);
|
||||
|
||||
Assert.Equal(Chronos.Core.Localization.Loc.L("Errors.Copies.Changed", drop.DisplayTitle), failed.Error);
|
||||
Assert.NotNull(await fx.Db.Sequences.GetAsync(drop.Id));
|
||||
Assert.False(File.Exists(MergeJournal.PathFor(fx.Paths, job.Id)), "the next run plans again");
|
||||
|
||||
// The next Retry plans again and asks for a new comparison instead of the same error.
|
||||
await engine.ResumeAsync(job.Id, Ct);
|
||||
failed = await fx.WaitForAsync(job.Id, JobState.Failed);
|
||||
Assert.Equal(Chronos.Core.Localization.Loc.L("Errors.Copies.StalePlan"), failed.Error);
|
||||
Assert.NotNull(await fx.Db.Sequences.GetAsync(drop.Id));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task APhotoSettledThroughAThirdSequenceThatIsGoneByTheTrashKeepsTheOther()
|
||||
{
|
||||
|
||||
@@ -50,6 +50,21 @@ public sealed class CopyEngineTests(TestContext context)
|
||||
Fingerprint = "f",
|
||||
}, f.Ct);
|
||||
|
||||
/// <summary>A paused Integrate job of <paramref name="localId"/>: a pair naming it reads Integrating.</summary>
|
||||
private static async Task<Guid> PausedIntegrateAsync(SyncFixture f, Guid localId)
|
||||
{
|
||||
var id = Guid.CreateVersion7();
|
||||
await f.Db.Jobs.EnqueueAsync(new Job
|
||||
{
|
||||
Id = id,
|
||||
Kind = JobKind.Integrate,
|
||||
TargetIds = [localId],
|
||||
State = JobState.Paused,
|
||||
Created = DateTimeOffset.UtcNow,
|
||||
}, f.Ct);
|
||||
return id;
|
||||
}
|
||||
|
||||
private static async Task<CopyState> StateAsync(SyncFixture f, Guid copyId) => (await f.Sync.Copies.GetAsync(copyId, f.Ct))!.State;
|
||||
|
||||
[Test]
|
||||
@@ -119,6 +134,36 @@ public sealed class CopyEngineTests(TestContext context)
|
||||
Assert.False(kept.IsListed && kept.State == CopyState.Candidate);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UnlinkOfAPairThatNoLongerHoldsTheLinkLeavesTheOtherPairsLinkAndIntegration()
|
||||
{
|
||||
await using var f = await FixtureAsync(context);
|
||||
var photos = f.NewPhotos(2);
|
||||
var first = await f.LocalAsync("Comet", photos);
|
||||
var second = await f.LocalAsync("Comet copy", photos);
|
||||
var remote = f.Remote.Add("Comet NAS", photos);
|
||||
// (second, R) was unlinked earlier; then (first, R) was linked and its Integrate began.
|
||||
var old = await PairAsync(f, second.Id, remote.Id);
|
||||
await f.Sync.Copies.SetStateAsync(old.Id, null, CopyState.KeptApart, null, f.Ct);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, first.Id, f.Ct);
|
||||
var linked = await f.Sync.Copies.EnsureLinkedAsync(f.Server, remote.Id, first.Id, f.Ct);
|
||||
var job = await PausedIntegrateAsync(f, first.Id);
|
||||
Assert.True(await f.Sync.Copies.SetStateAsync(linked.Id, null, CopyState.Integrating, new CopyAnswer(null, null, job, null, DateTimeOffset.UtcNow), f.Ct));
|
||||
using var engine = Engine(f);
|
||||
|
||||
// The stale row still offers Unlink.
|
||||
await engine.UnlinkAsync(old.Id, f.Remote, f.Ct);
|
||||
|
||||
Assert.Equal(CopyState.KeptApart, await StateAsync(f, old.Id));
|
||||
Assert.Equal(first.Id, (await f.Sync.Links.GetAsync(f.Server, remote.Id, f.Ct))!.LocalId);
|
||||
var integrating = (await f.Sync.Copies.GetAsync(linked.Id, f.Ct))!;
|
||||
Assert.Equal((CopyState.Integrating, (Guid?)job), (integrating.State, integrating.JobId));
|
||||
// The pair being integrated refuses an Unlink of its own.
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() => engine.UnlinkAsync(linked.Id, f.Remote, f.Ct));
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() => f.Sync.UnlinkAsync(f.Server, remote.Id, first.Id, f.Ct));
|
||||
Assert.Equal(first.Id, (await f.Sync.Links.GetAsync(f.Server, remote.Id, f.Ct))!.LocalId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task KeepApartOfALinkedPairUnlinksIt()
|
||||
{
|
||||
@@ -169,16 +214,17 @@ public sealed class CopyEngineTests(TestContext context)
|
||||
var (gone, restored) = (remote.Frames[1], remote.Frames[2]);
|
||||
await f.Remote.DeleteFramesAsync(remote.Id, new FrameDeleteRequest([gone.Id, restored.Id], null, false), f.Ct);
|
||||
|
||||
var (plan, lasts) = await engine.PlanTrashHereAsync(pair.Id, [Sha(photos[1]), Sha(photos[2])], f.Ct);
|
||||
var trash = await engine.PlanTrashHereAsync(pair.Id, local.Id, [Sha(photos[1]), Sha(photos[2])], f.Ct);
|
||||
var (plan, lasts) = trash;
|
||||
Assert.Equal(2, plan.Frames.Count);
|
||||
// No other sequence of this PC holds them: the trash takes their last copies, and the confirmation says so.
|
||||
Assert.SequenceEqual(new[] { Sha(photos[1]), Sha(photos[2]) }.Order(StringComparer.Ordinal), lasts.Select(l => l.Key).Order(StringComparer.Ordinal));
|
||||
// Restored on the server after the dry run: nothing moves, all or nothing.
|
||||
remote.AddFrame(photos[2], restored.FileName);
|
||||
await Assert.ThrowsAsync<StaleCopyPlanException>(() => engine.TrashHereAsync(pair.Id, plan, f.Remote, f.Ct));
|
||||
await Assert.ThrowsAsync<StaleCopyPlanException>(() => engine.TrashHereAsync(pair.Id, trash, f.Remote, f.Ct));
|
||||
Assert.Count(3, await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct));
|
||||
|
||||
var again = (await engine.PlanTrashHereAsync(pair.Id, [Sha(photos[1])], f.Ct)).Plan;
|
||||
var again = await engine.PlanTrashHereAsync(pair.Id, local.Id, [Sha(photos[1])], f.Ct);
|
||||
Assert.Equal(1, await engine.TrashHereAsync(pair.Id, again, f.Remote, f.Ct));
|
||||
var left = await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct);
|
||||
Assert.SequenceEqual(new[] { Sha(photos[0]), Sha(photos[2]) }.Order(StringComparer.Ordinal), left.Select(fr => fr.Sha256!).Order(StringComparer.Ordinal));
|
||||
@@ -217,17 +263,52 @@ public sealed class CopyEngineTests(TestContext context)
|
||||
public async Task TrashHereNamesNoLastCopyForAPhotoAnotherSequenceHolds()
|
||||
{
|
||||
await using var f = await FixtureAsync(context);
|
||||
var photos = f.NewPhotos(2);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
await f.LocalAsync("Comet backup", [photos[1]]);
|
||||
var remote = f.Remote.Add("Comet NAS", photos);
|
||||
var photos = f.NewPhotos(3);
|
||||
var local = await f.LocalAsync("Comet", photos[..2]);
|
||||
// The backup holds photo 1 and one of its own (a sequence keeps at least one frame).
|
||||
var backup = await f.LocalAsync("Comet backup", [photos[1], photos[2]]);
|
||||
var remote = f.Remote.Add("Comet NAS", photos[..2]);
|
||||
var pair = await PairAsync(f, local.Id, remote.Id);
|
||||
using var engine = Engine(f);
|
||||
await f.Remote.DeleteFramesAsync(remote.Id, new FrameDeleteRequest([remote.Frames[1].Id], null, false), f.Ct);
|
||||
|
||||
var plan = await engine.PlanTrashHereAsync(pair.Id, [Sha(photos[1])], f.Ct);
|
||||
var plan = await engine.PlanTrashHereAsync(pair.Id, local.Id, [Sha(photos[1])], f.Ct);
|
||||
|
||||
Assert.Equal((1, 0), (plan.Plan.Frames.Count, plan.LastCopies.Count));
|
||||
|
||||
// The other sequence goes to the trash while the confirmation is open: the photo is a last copy now, never moved unnamed.
|
||||
var held = (await f.Db.Frames.ListBySequenceAsync(backup.Id, cancellationToken: f.Ct)).Single(r => r.Sha256 == Sha(photos[1]));
|
||||
var other = await f.Archive.Service.FrameTrash.PlanDeleteAsync(backup.Id, [held.Id], (await f.Db.Sequences.GetAsync(backup.Id, f.Ct))!.FramesVersion, f.Ct);
|
||||
await f.Archive.Service.FrameTrash.DeleteAsync(other, "test", null, f.Ct);
|
||||
await Assert.ThrowsAsync<StaleCopyPlanException>(() => engine.TrashHereAsync(pair.Id, plan, f.Remote, f.Ct));
|
||||
Assert.Count(2, await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct));
|
||||
Assert.Count(1, (await engine.PlanTrashHereAsync(pair.Id, local.Id, [Sha(photos[1])], f.Ct)).LastCopies);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TrashHereOfTwoLocalCopiesTrashesFromTheSequenceAsked()
|
||||
{
|
||||
await using var f = await FixtureAsync(context);
|
||||
var photos = f.NewPhotos(3);
|
||||
var first = await f.LocalAsync("Comet", photos);
|
||||
var second = await f.LocalAsync("Comet copy", photos);
|
||||
using var engine = Engine(f);
|
||||
var pair = (await engine.FindAsync(null, f.Ct)).New.Single();
|
||||
// The pair's first deletes a photo the second still holds (a merge keeping the second reads it "Deleted in other").
|
||||
var (deleter, keeper) = pair.LocalId == first.Id ? (first, second) : (second, first);
|
||||
var gone = (await f.Db.Frames.ListBySequenceAsync(deleter.Id, cancellationToken: f.Ct)).Single(fr => fr.Sha256 == Sha(photos[1]));
|
||||
var deletion = await f.Archive.Service.FrameTrash.PlanDeleteAsync(deleter.Id, [gone.Id], (await f.Db.Sequences.GetAsync(deleter.Id, f.Ct))!.FramesVersion, f.Ct);
|
||||
await f.Archive.Service.FrameTrash.DeleteAsync(deletion, "test", null, f.Ct);
|
||||
|
||||
var plan = await engine.PlanTrashHereAsync(pair.Id, keeper.Id, [Sha(photos[1])], f.Ct);
|
||||
Assert.Equal(keeper.Id, plan.Plan.Sequence.Id);
|
||||
Assert.Equal(1, await engine.TrashHereAsync(pair.Id, plan, null, f.Ct));
|
||||
|
||||
Assert.DoesNotContain(Sha(photos[1]), (await f.Db.Frames.ListBySequenceAsync(keeper.Id, cancellationToken: f.Ct)).Select(fr => fr.Sha256));
|
||||
Assert.Count(2, await f.Db.Frames.ListBySequenceAsync(deleter.Id, cancellationToken: f.Ct));
|
||||
// The sequence that deleted it holds nothing to trash: its own photos are refused.
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() => engine.PlanTrashHereAsync(pair.Id, deleter.Id, [Sha(photos[1])], f.Ct));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => engine.PlanTrashHereAsync(pair.Id, Guid.NewGuid(), [Sha(photos[1])], f.Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -460,7 +541,10 @@ public sealed class CopyEngineTests(TestContext context)
|
||||
IReadOnlyList<(Chronos.Core.Project.BundleHome Home, string Name)> projects =
|
||||
[
|
||||
(new(Chronos.Core.Project.BundleHome.ArchiveKind, linked.Id), "Grade"),
|
||||
(new(Chronos.Core.Project.BundleHome.ServerKind, linkedRemote.Id, Server: ServerIdentity.IdKey(serverId)), "Grade NAS"),
|
||||
(new(Chronos.Core.Project.BundleHome.ArchiveKind, linked.Id), "Vertical"),
|
||||
(new(Chronos.Core.Project.BundleHome.ArchiveKind, linked.Id), "Slow pan"),
|
||||
(new(Chronos.Core.Project.BundleHome.ServerKind, linkedRemote.Id, Server: ServerIdentity.IdKey(serverId)), "Grade"),
|
||||
(new(Chronos.Core.Project.BundleHome.ServerKind, linkedRemote.Id, Server: ServerIdentity.IdKey(serverId)), "Slow pan (STUDIO-PC)"),
|
||||
(new(Chronos.Core.Project.BundleHome.ArchiveKind, apart.Id), "Unpaired"),
|
||||
];
|
||||
using var engine = new CopyEngine(f.Sync, f.Archive.Service, new IntegratePlanner(f.Sync, sides, f.Archive.Service.Projects),
|
||||
@@ -469,7 +553,14 @@ public sealed class CopyEngineTests(TestContext context)
|
||||
|
||||
var twin = (await engine.TwinsAsync(f.Ct)).Single();
|
||||
|
||||
Assert.Equal((pair.Id, linked.Id, "Grade", linkedRemote.Id, "Grade NAS"), (twin.CopyId, twin.LocalId, twin.LocalProject, twin.RemoteId, twin.ServerProject));
|
||||
Assert.Equal((pair.Id, linked.Id, linkedRemote.Id), (twin.CopyId, twin.LocalId, twin.RemoteId));
|
||||
Assert.SequenceEqual(["Grade", "Vertical", "Slow pan"], twin.LocalProjects);
|
||||
Assert.SequenceEqual(["Grade", "Slow pan (STUDIO-PC)"], twin.ServerProjects);
|
||||
// A project is a twin only with its sibling: the same name, or the name Copy across gave it at the other home.
|
||||
Assert.Equal("Grade", twin.CounterpartOf("Grade", atServerHome: false));
|
||||
Assert.Null(twin.CounterpartOf("Vertical", atServerHome: false));
|
||||
Assert.Equal("Slow pan (STUDIO-PC)", twin.CounterpartOf("Slow pan", atServerHome: false));
|
||||
Assert.Equal("Slow pan", twin.CounterpartOf("Slow pan (STUDIO-PC)", atServerHome: true));
|
||||
Assert.Equal(f.Server, twin.Server);
|
||||
// The Edit picker shows the server by its name, never by its key.
|
||||
Assert.Equal("Studio NAS", twin.ServerName);
|
||||
|
||||
@@ -730,6 +730,36 @@ public sealed class IntegrateTests(TestContext context)
|
||||
Assert.False(File.Exists(IntegrateJournal.PathFor(f.Archive.Paths, job.Id)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ALinkTheUserGaveTheServerSequenceAfterTheJournalIsNeverUndoneOnResume()
|
||||
{
|
||||
await using var f = await FixtureAsync(context);
|
||||
var (engine, handler) = Engine(f);
|
||||
await using var _ = engine;
|
||||
await engine.StartAsync(f.Ct);
|
||||
var (local, remote, pair) = await ScenarioAsync(f);
|
||||
var other = await LocalAsync(f, "Comet copy", [(1, 0, "IMG_0001.JPG")]);
|
||||
handler.BeforeStage = stage => stage == IntegrateStage.Link ? throw new IOException("crash before Link") : Task.CompletedTask;
|
||||
var plan = await Planner(f).PlanAsync(f.Remote, pair, await ChoicesAsync(f, local.Id, remote.Id, CopyPhotoPolicy.Union), PlanContext(), f.Ct);
|
||||
var job = await CopyJobs.EnqueueIntegrateAsync(engine, f.Sync.Copies, plan, local.DisplayTitle, f.Ct);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Failed);
|
||||
Assert.True(File.Exists(IntegrateJournal.PathFor(f.Archive.Paths, job.Id)));
|
||||
|
||||
// Meanwhile the user links the server sequence to another copy of this PC.
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, other.Id, f.Ct);
|
||||
handler.BeforeStage = null;
|
||||
var uploads = f.Remote.IntoUploads;
|
||||
await engine.ResumeAsync(job.Id, f.Ct);
|
||||
var failed = await f.Archive.WaitForAsync(job.Id, JobState.Failed);
|
||||
|
||||
Assert.Equal(Loc.L("Errors.Copies.StalePlan"), failed.Error);
|
||||
Assert.Equal(other.Id, (await f.Sync.Links.GetAsync(f.Server, remote.Id, f.Ct))!.LocalId);
|
||||
Assert.Null(await f.Sync.LinkOfAsync(f.Server, local.Id, f.Ct));
|
||||
Assert.Equal(uploads, f.Remote.IntoUploads);
|
||||
Assert.False(File.Exists(IntegrateJournal.PathFor(f.Archive.Paths, job.Id)));
|
||||
Assert.NotEqual(CopyState.Integrating, (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.State);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ARetryAfterAFailureBeforeTheJournalRunsTheIntegrate()
|
||||
{
|
||||
|
||||
@@ -127,7 +127,7 @@ public sealed class SyncServiceCopyTests(TestContext context)
|
||||
await f.RefreshAsync();
|
||||
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync("Comet")).Status);
|
||||
|
||||
await f.Sync.UnlinkAsync(f.Server, remote.Id, f.Ct);
|
||||
await f.Sync.UnlinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
|
||||
var link = await f.Sync.Links.GetAsync(f.Server, remote.Id, f.Ct);
|
||||
Assert.NotNull(link);
|
||||
@@ -244,6 +244,43 @@ public sealed class SyncServiceCopyTests(TestContext context)
|
||||
Assert.True((await f.Sync.Copies.ListByServerAsync(nas.Server, f.Ct)).All(p => p.RemoteGoneHits == 0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ASweepOf404sConfirmsNoEarlierHitEither()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var nas = new FakeSyncRemote { Server = HomeFolders.IdKey(Guid.NewGuid()) };
|
||||
// One pair with a 404 counted more than ten minutes ago (its link already forgotten).
|
||||
var first = f.NewPhotos(2);
|
||||
var gone = await f.LocalAsync("Comet", first);
|
||||
var goneRemote = nas.Add("Comet", first);
|
||||
await f.Sync.LinkAsync(nas.Server, goneRemote.Id, gone.Id, f.Ct);
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
nas.Sequences.Remove(goneRemote.Id);
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(nas.Server, f.Ct)).Single(p => p.LocalId == gone.Id);
|
||||
Assert.Equal(1, pair.RemoteGoneHits);
|
||||
await using (var session = await f.Db.Database.OpenAsync(f.Ct))
|
||||
await session.ExecuteAsync("UPDATE found_copies SET remote_gone_at = $1 WHERE id = $2", [DateTimeOffset.UtcNow.AddMinutes(-11), pair.Id], f.Ct);
|
||||
|
||||
// Then the server serves something else: every linked sequence answers 404 at once.
|
||||
var remotes = new List<FakeSequence>();
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
var photos = f.NewPhotos(1);
|
||||
var local = await f.LocalAsync($"Card {i}", photos);
|
||||
var remote = nas.Add($"Card {i}", photos);
|
||||
await f.Sync.LinkAsync(nas.Server, remote.Id, local.Id, f.Ct);
|
||||
remotes.Add(remote);
|
||||
}
|
||||
foreach (var remote in remotes) nas.Sequences.Remove(remote.Id);
|
||||
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
|
||||
pair = (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!;
|
||||
Assert.Equal(1, pair.RemoteGoneHits);
|
||||
Assert.False(pair.RemoteGone);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AServerKnownOnlyByItsAddressMarksNothing()
|
||||
{
|
||||
|
||||
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 78 KiB |
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 78 KiB |
|
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 89 KiB After Width: | Height: | Size: 90 KiB |
|
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 75 KiB |
|
Before Width: | Height: | Size: 89 KiB After Width: | Height: | Size: 90 KiB |
|
Before Width: | Height: | Size: 87 KiB After Width: | Height: | Size: 87 KiB |
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 78 KiB |
|
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 77 KiB |
|
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 78 KiB |
|
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 77 KiB |
|
Before Width: | Height: | Size: 67 KiB After Width: | Height: | Size: 67 KiB |
|
Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 60 KiB |