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

The metered hold now records the jobs it paused in the index and forgets
any job the user pauses, resumes, retries or cancels, so it never resumes
a pause of the user's and still resumes its own after a restart.

Drop... reports why its dry run is blocked instead of asking first, and
dropping the version Main uses lets Main use the version that stays,
with its hero and keyframes. That version reads "In Main".

Merges:
- A re-plan no longer hashes the other's photos again.
- A resumed merge verifies photos flagged damaged while it waited.
- A merge is blocked while the other's folder holds photos the index
  has not read; this is checked again under the lease before the trash.
- Choose each offers Keep both, Kept and Other, and blocks until every
  differing photo is chosen.
- Classes are named by role.

The Compare dialog:
- Its headings stay over their columns.
- The Projects part scrolls.
- Every confirmation line carries its own prefix, and a merge's facts
  carry none.
- A server card in a match offers Compare... alone.

The Italian strings follow the glossary.

Finding 9 (a local drop counting 0 photos) is not reproduced; a test now
keeps the count at 2.

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 20:51:23 +01:00
1 parent 2c06e7ac2b
commit bf7701d279
159 files changed
+1759 -126

No files matched your search

@@ -143,6 +143,9 @@ public sealed class CopyScreenSmokeTests
var dropped = list.Pairs.Single(p => p.Here.Title == CopyScenes.Alps) is var alps && plan.KeepId == alps.Copy.LocalId ? alps.There : alps.Here;
Assert.Equal(dropped.Photos.ToString(System.Globalization.CultureInfo.InvariantCulture), request.TypedConfirmation);
Assert.Contains(request.TypedConfirmation!, request.TypedPrompt!);
// Its first line is the dropped sequence's fact, not a photo held elsewhere.
Assert.False(request.Detail!.StartsWith(Loc.L("Server.Copies.Confirm.Elsewhere", string.Empty).Trim(), StringComparison.Ordinal),
"a merge's facts carry no Held elsewhere prefix");
await app.ExpectAsync<ServerView>("server-copies-merge");
// Choose on "choose the sequence to keep" takes the keyboard to the first Kept radio of the Plan part.
@@ -198,6 +201,26 @@ public sealed class CopyScreenSmokeTests
CopyScenes.Reset(shell);
});
[Test]
public Task ManyProjectsScrollInsideTheDialog() => ScreenHost.RunAsync(async () =>
{
await using var app = await StartAsync();
var shell = app.Shell;
var dialog = Assert.NotNull(await CopyScenes.ShowAsync(shell, "server-copies-projects-many"));
Assert.True(dialog.IsProjects);
Assert.Equal((CopyScenes.ManyProjects, CopyScenes.ManyProjects), (dialog.HereProjects.Count, dialog.ThereProjects.Count));
await app.ExpectAsync<ServerView>("server-copies-projects-many");
// Both lists sit in one scroll viewer that holds more than it shows: the dialog's footer stays in view.
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);
// 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);
CopyScenes.Reset(shell);
});
[Test]
public Task TheLibraryAndSettingsShowTheMatches() => ScreenHost.RunAsync(async () =>
{
@@ -287,10 +287,64 @@ public sealed class CopyTextTests
[
Loc.L("Server.Copies.Plan.OnThisPc"),
" " + Loc.L("Server.Copies.Confirm.LastCopy", "IMG_0002.JPG"),
" IMG_0001.JPG",
// A replaced version under an "Only copy:" line carries its own prefix (owner review 6, verification round 5).
" " + Loc.L("Server.Copies.Confirm.Replaced", "IMG_0001.JPG"),
Loc.L("Server.Copies.Plan.OnServer", "Studio NAS"),
" IMG_0003.JPG",
" " + Loc.L("Server.Copies.Confirm.Replaced", "IMG_0003.JPG"),
], lines);
// To trash… and Delete on server…: the only copies first, the photos held elsewhere each with their prefix, once.
var trash = CopyDialogViewModel.Lines(lasts, ["IMG_0002.JPG", "IMG_0001.JPG", "IMG_0001.JPG"]).Split(Environment.NewLine);
Assert.SequenceEqual(
[
Loc.L("Server.Copies.Confirm.LastCopy", "IMG_0002.JPG"),
Loc.L("Server.Copies.Confirm.Elsewhere", "IMG_0001.JPG"),
], trash);
// A merge's facts are not photos held elsewhere: they carry no prefix, after the only copies.
var facts = CopyDialogViewModel.Lines(lasts, ["1 render moved"], elsewhere: false).Split(Environment.NewLine);
Assert.SequenceEqual(
[
Loc.L("Server.Copies.Confirm.LastCopy", "IMG_0002.JPG"),
"1 render moved",
], facts);
}
[Test]
public void AMergeNamesItsSidesByRoleAndAsksForAVersionOfEachDifferentPhoto()
{
// Class words: by role once a sequence is kept, oriented from the kept one; by place before.
var onlyHere = new CopyClassRow(new PhotoClassTotal(PhotoClass.OnlyHere, 38, 570_000_000, 0), CopyPhotoPolicy.Union, isMerge: true);
Assert.Equal(Loc.L("Server.Copies.Class.OnlyKept"), onlyHere.Text);
var raised = new List<string?>();
onlyHere.PropertyChanged += (_, e) => raised.Add(e.PropertyName);
onlyHere.Swapped = true;
Assert.Equal(Loc.L("Server.Copies.Class.OnlyOther"), onlyHere.Text);
Assert.Contains(nameof(CopyClassRow.Text), raised);
raised.Clear();
onlyHere.Places = ("Main archive", "Studio archive");
Assert.Equal(Loc.L("Server.Copies.Class.OnlyHere"), onlyHere.Text);
Assert.Contains(nameof(CopyClassRow.Text), raised);
Assert.Equal(Loc.L("Server.Copies.Class.DeletedOther"), CopyText.Class(PhotoClass.DeletedThere, merge: true));
Assert.Equal(Loc.L("Server.Copies.Class.Differs"), CopyText.Class(PhotoClass.Differs, merge: true));
Assert.Equal(Loc.L("Server.Copies.Class.OnlyHere"), new CopyClassRow(new PhotoClassTotal(PhotoClass.OnlyHere, 1, 1, 0)).Text);
// Choose each in a merge: its own tooltip, no Leave, and the unchosen block leads to the photos.
Assert.Equal(Loc.L("Tooltips.Server.Copies.Class.Differs.ChooseMerge"),
CopyText.ClassToolTip(PhotoClass.Differs, CopyPhotoPolicy.ChoosePerPhoto, isMerge: true));
Assert.Equal(Loc.L("Tooltips.Server.Copies.Class.Differs.Choose"), CopyText.ClassToolTip(PhotoClass.Differs, CopyPhotoPolicy.ChoosePerPhoto));
Assert.SequenceEqual([PhotoChoice.KeepBoth, PhotoChoice.TakeHere, PhotoChoice.TakeThere],
CopyDialogViewModel.VersionChoices(merge: true).Select(o => o.Value));
Assert.Contains(PhotoChoice.Leave, CopyDialogViewModel.VersionChoices(merge: false).Select(o => o.Value));
Assert.True(CopyText.HasChoose(CopyBlock.PhotosUnchosen));
// A version choice not made yet is read out as such, not as Leave.
var photo = new ComparedPhoto(PhotoClass.Differs, "k",
new CopyPhotoInput(Guid.NewGuid(), 0, "IMG_0004.JPG", "a", 10, null, false), new CopyPhotoInput(Guid.NewGuid(), 0, "IMG_0004.JPG", "b", 12, null, false),
1, 1, 10);
var row = new CopyPhotoRow(photo, isMerge: true, canBring: false, canChoose: true, CopyDialogViewModel.VersionChoices(true), null, () => { }, null);
Assert.Equal(Loc.L("Server.Copies.ControlFor", "IMG_0004.JPG", Loc.L("Server.Copies.Version.None")), row.ChoiceAccessibleName);
Assert.False(row.InMain);
}
[Test]
@@ -75,32 +75,16 @@ public sealed class UploadHoldTests
Assert.True(UploadHold.HeldNow(Of(JobKind.UploadCommit, $$"""{"server":"{{Server}}","automatic":true}"""), metered: true, optionOn: false));
}
[Test]
public async Task AnAutomaticTransferPausedBeforeARestartResumesOnceTheConnectionIsNotMetered()
/// <summary>A fresh index in a temporary folder and its job engine (not started).</summary>
private static async Task HoldScenarioAsync(Func<Chronos.Data.ChronosDatabase, Chronos.Data.Jobs.JobEngine, Task> body)
{
var folder = Path.Combine(Path.GetTempPath(), "chronos-hold-" + Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(folder);
try
{
await using var db = await Chronos.Data.ChronosDatabase.OpenAsync(Chronos.Data.DatabaseOptions.Sqlite(Path.Combine(folder, "index.db")));
var automatic = Of(JobKind.Download, $$"""{"server":"{{Server}}","mode":"Originals","automatic":true}""");
var manual = Of(JobKind.Download, $$"""{"server":"{{Server}}","mode":"Originals"}""");
foreach (var job in new[] { automatic, manual })
{
await db.Jobs.EnqueueAsync(job);
await db.Jobs.SetStateAsync(job.Id, JobState.Paused, null);
}
await using var engine = new Chronos.Data.Jobs.JobEngine(db, [], new Chronos.Data.Jobs.JobEngineOptions { Workers = 1, WorkerId = "test" });
// A new hold after a restart: it paused the automatic one before, and its record of that is gone.
using var hold = new UploadHold(() => db, () => false, () => false);
hold.Attach(engine);
await hold.ApplyAsync();
Assert.Equal(JobState.Queued, (await db.Jobs.GetAsync(automatic.Id))!.State);
// A transfer the user started and paused stays paused: its pause may be the user's.
Assert.Equal(JobState.Paused, (await db.Jobs.GetAsync(manual.Id))!.State);
Assert.True(UploadHold.Adopts(automatic with { State = JobState.Paused }));
Assert.False(UploadHold.Adopts(manual with { State = JobState.Paused }));
await body(db, engine);
}
finally
{
@@ -114,6 +98,53 @@ public sealed class UploadHoldTests
}
}
[Test]
public Task ATransferTheHoldPausedBeforeARestartResumesOnceTheConnectionIsNotMetered() => HoldScenarioAsync(async (db, engine) =>
{
var automatic = Of(JobKind.Download, $$"""{"server":"{{Server}}","mode":"Originals","automatic":true}""");
var userPaused = Of(JobKind.Download, $$"""{"server":"{{Server}}","mode":"Originals","automatic":true}""");
await db.Jobs.EnqueueAsync(automatic);
await db.Jobs.EnqueueAsync(userPaused);
// The user paused this one before the connection became metered: the hold never paused it.
await db.Jobs.SetStateAsync(userPaused.Id, JobState.Paused, null);
using (var before = new UploadHold(() => db, () => false, () => true))
{
before.Attach(engine);
await before.ApplyAsync();
Assert.Equal(JobState.Paused, (await db.Jobs.GetAsync(automatic.Id))!.State);
}
// A new hold after a restart reads the record the first one kept in the index.
using var hold = new UploadHold(() => db, () => false, () => false);
hold.Attach(engine);
await hold.ApplyAsync();
Assert.Equal(JobState.Queued, (await db.Jobs.GetAsync(automatic.Id))!.State);
// An automatic transfer the user paused stays paused: the hold resumes only what it paused.
Assert.Equal(JobState.Paused, (await db.Jobs.GetAsync(userPaused.Id))!.State);
Assert.Equal("[]", await db.Settings.GetJsonAsync(Chronos.Data.Repositories.SettingScope.App, null, UploadHold.RecordKey));
});
[Test]
public Task AJobTheUserPausesWhileHeldIsNeverResumedByTheHold() => HoldScenarioAsync(async (db, engine) =>
{
var automatic = Of(JobKind.UploadCommit, $$"""{"server":"{{Server}}","automatic":true}""");
await db.Jobs.EnqueueAsync(automatic);
var metered = true;
using var hold = new UploadHold(() => db, () => false, () => metered);
hold.Attach(engine);
await hold.ApplyAsync();
Assert.Equal(JobState.Paused, (await db.Jobs.GetAsync(automatic.Id))!.State);
// The user pauses it from Jobs (the queue tells the hold), then the connection is no longer metered.
using var queue = new Chronos.App.Jobs.EngineJobQueue(db, engine, started: false, acted: id => hold.ForgetAsync(id).GetAwaiter().GetResult());
await queue.PauseAsync(automatic.Id);
metered = false;
await hold.ApplyAsync();
Assert.Equal(JobState.Paused, (await db.Jobs.GetAsync(automatic.Id))!.State);
});
[Test]
public void TransfersWithThisPcsLibraryAndOtherJobsAreNot()
{