fix(copies): close the owner review 6 gaps with tests

Photos not sent: automatic photos of an integrated pair that failed three
times in a row are now told with an error toast that shows the row, and the
row reads "not sent" with the last reason. The matches-found and linked toasts
of background detections run from their Windows notification too.

Maintenance now clears a merge's or an integration's journal whose job is done,
cancelled, or deleted without a cancel and untouched for the history's days.

Tests pin the matches jobs in the priority queue, the owner's defaults (ask
always, union, copy across), the dialog starting from the settings, Choose
each preselecting nothing, no automatic photos for a pair whose server copy
is gone, the repair of a corrupt local frame by an Integrate, and the owner's
whole scenario end to end against a real in-process server.

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 14:03:23 +01:00
1 parent fe752a0a21
commit d10577b175
18 files changed
+804 -11

No files matched your search

@@ -1277,7 +1277,7 @@ public sealed class SettingsViewModel : SectionViewModel
private string? ValidateParallelism(string text) => ValidateInt(text, 1, Math.Max(1, LogicalCores * 2));
/// <summary>The kinds the priority queue lists, in the order of the Jobs screen's kinds the user starts most.</summary>
private static readonly JobKind[] PriorityKinds =
internal static readonly JobKind[] PriorityKinds =
[
JobKind.Render, JobKind.Import, JobKind.Download, JobKind.UploadCommit, JobKind.Scan, JobKind.Rebuild, JobKind.Verify, JobKind.LightAnalyse,
JobKind.DeepAnalyse, JobKind.Thumbs, JobKind.Proxies, JobKind.Maintenance, JobKind.Duplicates, JobKind.Orphans, JobKind.Adopt, JobKind.Move,
@@ -285,14 +285,24 @@ public sealed class CopyListViewModel : ObservableObject, IDisposable
await ReloadAsync();
}
/// <summary>"2 matches found" · Review, and "3 sequences linked" · Show (design §8.4).</summary>
/// <summary>
/// "2 matches found" · Review, and "3 sequences linked" · Show (design §8.4), for Find matches and for the detections
/// that run by themselves (after a refresh, a scan, an import): both only navigate, so a click on their Windows
/// notification runs them too.
/// </summary>
internal void Announce(CopyFindResult found)
{
var asking = found.New.Count + found.AskedAgain.Count;
if (asking > 0)
_shell.Notify(Loc.Plural("Server.Copies.Found", asking), null, Loc.L("Server.Copies.Action.Review"), Loc.L("Tooltips.Server.Copies.ReviewFound"), ShowMatches);
{
_shell.Notify(Loc.Plural("Server.Copies.Found", asking), null, Loc.L("Server.Copies.Action.Review"), Loc.L("Tooltips.Server.Copies.ReviewFound"),
ShowMatches, runsFromNotification: true);
}
if (found.AutoLinked.Count > 0)
_shell.Notify(Loc.Plural("Server.Copies.Linked", found.AutoLinked.Count), null, Loc.L("Server.Sync.Show"), Loc.L("Tooltips.Server.Sync.Show"), ShowMatches);
{
_shell.Notify(Loc.Plural("Server.Copies.Linked", found.AutoLinked.Count), null, Loc.L("Server.Sync.Show"), Loc.L("Tooltips.Server.Sync.Show"),
ShowMatches, runsFromNotification: true);
}
}
private void ShowMatches()
+19
View File
@@ -181,6 +181,24 @@ public sealed class SyncHost(AppServices services) : ISyncConnector, IAsyncDispo
/// <summary>Pauses uploads while the connection is metered and the option is on.</summary>
public UploadHold Uploads { get; } = new(services);
/// <summary>
/// The automatic photo transfers of the signed-in server's integrated pairs that failed in a row, by local sequence
/// (owner review 6, #73; design §6.1): a row reads "not sent" from <see cref="SyncAgent.NotSentAfter"/> on. Empty while
/// signed out.
/// </summary>
public IReadOnlyDictionary<Guid, AutoPhotoFailure> PhotoFailures => Agent?.PhotoFailures ?? NoFailures;
/// <summary>
/// The automatic photo transfers of a local sequence failed <see cref="SyncAgent.NotSentAfter"/> times in a row (the
/// server's key, the local sequence, the last failure; any thread): "{title}: photos not sent" · Show.
/// </summary>
public event Action<string, Guid, AutoPhotoFailure>? PhotosNotSent;
/// <summary>Tells <see cref="PhotosNotSent"/> (the agent, and tests).</summary>
internal void TellPhotosNotSent(string server, Guid localId, AutoPhotoFailure failure) => PhotosNotSent?.Invoke(server, localId, failure);
private static readonly IReadOnlyDictionary<Guid, AutoPhotoFailure> NoFailures = new Dictionary<Guid, AutoPhotoFailure>();
/// <summary>The agent started, stopped or compared, or the table of the signed-in server changed (any thread).</summary>
public event Action? Changed;
@@ -510,6 +528,7 @@ public sealed class SyncHost(AppServices services) : ISyncConnector, IAsyncDispo
var agent = new SyncAgent(service, remote, () => Policy, services.Engine);
agent.Changed += () => Changed?.Invoke();
agent.ProjectChanged += e => ProjectChanged?.Invoke(remote.Server, e);
agent.PhotosNotSent += (localId, failure) => TellPhotosNotSent(remote.Server, localId, failure);
agent.Start();
Volatile.Write(ref _running, new Running(agent, remote, start));
Log.Info("sync", $"Comparing with {remote.Server}");
+34 -1
View File
@@ -226,6 +226,7 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
if (_attached) return;
_attached = true;
Host.Changed += OnChanged;
Host.PhotosNotSent += OnPhotosNotSent;
Loc.CultureChanged += OnCultureChanged;
if (_shell.Services.Jobs is { } jobs)
{
@@ -271,6 +272,7 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
if (!_attached) return;
_attached = false;
Host.Changed -= OnChanged;
Host.PhotosNotSent -= OnPhotosNotSent;
Loc.CultureChanged -= OnCultureChanged;
if (_shell.Services.Jobs is { } jobs)
{
@@ -337,7 +339,8 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
/// <summary>What the Matches list adds to the row of <paramref name="entry"/>: its pair and why Upload all left it out.</summary>
private SyncMark Mark(SyncEntry entry) => entry.Local is { } local
? new SyncMark(Copies.PairOf(local.Id), _skipped.TryGetValue(local.Id, out var why) ? why : null, _shell.Services.Server.Flow.Info?.Name)
? new SyncMark(Copies.PairOf(local.Id), _skipped.TryGetValue(local.Id, out var why) ? why : null, _shell.Services.Server.Flow.Info?.Name,
Host.PhotoFailures.TryGetValue(local.Id, out var failure) && failure.Count >= SyncAgent.NotSentAfter ? failure : null)
: new SyncMark(Copies.PairOf(entry.Id), null, _shell.Services.Server.Flow.Info?.Name);
/// <summary>The rule of Upload all local (design §6.4): what it sends, and what it leaves out and why.</summary>
@@ -550,6 +553,36 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
private void OnChanged() => Dispatch(() => _ = ReloadAsync());
private void OnPhotosNotSent(string server, Guid localId, AutoPhotoFailure failure) => Dispatch(() => _ = TellNotSentAsync(localId));
/// <summary>
/// The new photos of an integrated pair failed to move by themselves three times in a row (design §6.1): "{title}: photos
/// not sent" · Show, which shows the sequence's row (it reads "not sent", the reason in its tooltip).
/// </summary>
internal async Task TellNotSentAsync(Guid localId)
{
var title = _entries.FirstOrDefault(e => e.Local?.Id == localId)?.Title;
if (title is null && _shell.Services.Database is { } db)
{
try
{
title = (await db.Sequences.GetAsync(localId))?.DisplayTitle;
}
catch (Data.DatabaseException ex)
{
Log.Warning("sync", "The sequence whose photos were not sent could not be read", ex);
}
}
if (title is null) return;
var shown = title;
_shell.Notify(Loc.L("Server.Sync.NotSentToast", title), null, Loc.L("Server.Sync.Show"), Loc.L("Tooltips.Server.Sync.ShowNotSent"), () =>
{
_shell.Navigate(SectionKey.Server);
ShowFilter(SyncFilter.All, shown);
}, isError: true, runsFromNotification: true);
await ReloadAsync();
}
private void OnCultureChanged(object? sender, EventArgs e) => Dispatch(() =>
{
foreach (var chip in _chips) chip.Relabel();
+9 -5
View File
@@ -49,10 +49,11 @@ public enum SyncAction
}
/// <summary>
/// What the Matches list adds to a sync row (owner review 6, #73): the pair the row's sequence is in, and why Upload all
/// local left it out.
/// What the Matches list adds to a sync row (owner review 6, #73): the pair the row's sequence is in, why Upload all
/// local left it out, and the automatic photo transfers of an integrated pair that failed too often in a row.
/// </summary>
public readonly record struct SyncMark(Data.Copies.FoundCopy? Copy, Data.Copies.UploadSkip? Skipped, string? ServerName = null)
public readonly record struct SyncMark(Data.Copies.FoundCopy? Copy, Data.Copies.UploadSkip? Skipped, string? ServerName = null,
AutoPhotoFailure? NotSent = null)
{
/// <summary>The row's sequence is in a pair nobody answered yet.</summary>
public bool IsCandidate => Copy is { State: Data.Copies.CopyState.Candidate, RemoteGone: false };
@@ -181,8 +182,9 @@ public static class SyncText
/// <summary>
/// The State column with what the Matches list knows (owner review 6, #73): a transfer still shows first; then a sequence
/// in an unanswered pair reads "match found", one whose server copy was deleted "deleted on server" or "kept here", and
/// one Upload all local left out "skipped" with the reason.
/// in an unanswered pair reads "match found", one whose server copy was deleted "deleted on server" or "kept here", one
/// whose new photos failed to move by themselves <see cref="SyncAgent.NotSentAfter"/> times in a row "not sent" with the
/// last reason, and one Upload all local left out "skipped" with the reason.
/// </summary>
public static (StatusKind Kind, string Text, string ToolTip) State(SyncEntry entry, SyncMark mark)
{
@@ -193,6 +195,8 @@ public static class SyncText
? (StatusKind.Offline, Loc.L("Server.Sync.State.KeptHere"), Loc.L("Tooltips.Server.Copies.State.KeptHere"))
: (StatusKind.Warning, Loc.L("Server.Sync.State.RemoteGone"), Loc.L("Tooltips.Server.Copies.State.RemoteGone"));
}
if (mark.NotSent is { Count: >= SyncAgent.NotSentAfter } failure)
return (StatusKind.Warning, Loc.L("Server.Sync.State.NotSent"), Loc.L("Tooltips.Server.Sync.State.NotSent", failure.Reason));
if (mark.IsCandidate)
return (StatusKind.Warning, Loc.L("Server.Sync.State.CopyFound"), Loc.L("Tooltips.Server.Sync.State.CopyFound", mark.ServerName ?? mark.Copy!.Server ?? string.Empty));
if (mark.Skipped is { } why && entry.Status == SyncStatus.LocalOnly)
@@ -201,7 +201,8 @@ public sealed class ArchiveMaintenance
/// stays while a retry can use it, and goes once the job is done. A job this index does not know (another host's on a
/// shared archive, or one its history forgot) may still be resumed where it is known: its journal and staged conversions
/// stay together while any of them was written within as long as the job history keeps jobs, then go together (staged
/// conversions without a journal, which no resume can use, once idle for a day).
/// conversions without a journal, which no resume can use, once idle for a day). The journal of a merge or an integration
/// goes once its job is done or cancelled, or once this index does not know the job and nothing wrote it for as long.
/// </summary>
private async Task<List<string>> PurgeTemporaryFilesAsync(ArchivePaths paths, IReadOnlyList<SequenceLocation> locations, bool dryRun,
CancellationToken cancellationToken)
@@ -270,6 +271,16 @@ public sealed class ArchiveMaintenance
var state = await StateAsync(job).ConfigureAwait(false);
if (state == JobState.Done || state is null && Expired(job)) found.Add(file);
}
// A merge's or an integration's journal (owner review 6, #73): its job deletes it when it ends or is cancelled, and
// keeps it after a failure for a retry. One whose job ended anyway (a crash before the delete), or that this index
// no longer knows (a job deleted without a cancel, forgotten by the history, or another host's) and that nothing
// wrote for as long as the history keeps jobs, has no retry left to serve.
foreach (var file in Directory.EnumerateFiles(paths.JournalDirectory, "*.json"))
{
if (CopyJournalJob(Path.GetFileName(file)) is not { } job) continue;
var state = await StateAsync(job).ConfigureAwait(false);
if (state is JobState.Done or JobState.Cancelled || state is null && Old(file, JournalAge)) found.Add(file);
}
}
Collect(paths.MetaDirectory, ".*.tmp", TempAge, recursive: false);
foreach (var location in locations)
@@ -296,6 +307,20 @@ public sealed class ArchiveMaintenance
return found.ConvertAll(paths.ToRelative);
}
/// <summary>The journal prefixes of the matches' jobs (<see cref="MergeJournal"/>, <c>IntegrateJournal</c>): "&lt;prefix&gt;&lt;job:N&gt;.json".</summary>
private static readonly string[] CopyJournalPrefixes = ["merge-", "integrate-"];
/// <summary>The job a merge's or an integration's journal belongs to; null for any other file.</summary>
internal static Guid? CopyJournalJob(string name)
{
if (!name.EndsWith(".json", StringComparison.Ordinal)) return null;
foreach (var prefix in CopyJournalPrefixes)
{
if (name.StartsWith(prefix, StringComparison.Ordinal) && Guid.TryParseExact(name[prefix.Length..^".json".Length], "N", out var job)) return job;
}
return null;
}
private async Task<List<string>> CompactPacksAsync(ArchivePaths paths, IReadOnlyList<SequenceLocation> locations, bool dryRun, CancellationToken cancellationToken)
{
var compacted = new List<string>();