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>
No files matched your search
@@ -0,0 +1,81 @@
|
||||
using System.Reflection;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Library;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.App.Tests.Library;
|
||||
|
||||
/// <summary>Two versions… (owner Q3, #73): a drop whose dry run cannot go says why and asks nothing.</summary>
|
||||
[Serial]
|
||||
public sealed class VersionsDialogTests
|
||||
{
|
||||
private static readonly Sequence Comet = new()
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
ArchiveId = Guid.CreateVersion7(),
|
||||
Title = "Comet",
|
||||
Folder = "2026/comet",
|
||||
};
|
||||
|
||||
[Test]
|
||||
public async Task ABlockedDropSaysWhyAndNeverAsksOrDrops()
|
||||
{
|
||||
foreach (var (block, expected) in new[]
|
||||
{
|
||||
(FrameDeleteBlock.Offline, Loc.L("Errors.Copies.TrashBlocked", "IMG_0002.JPG", Loc.L("Archive.Delete.Reason.Offline"))),
|
||||
(FrameDeleteBlock.Busy, Loc.L("Errors.Copies.TrashBlocked", "IMG_0002.JPG", Loc.L("Archive.Delete.Reason.Busy"))),
|
||||
(FrameDeleteBlock.FramesChanged, Loc.L("Archive.Convert.Blocked.FramesChanged")),
|
||||
})
|
||||
{
|
||||
var engine = FakeEngine.Create(new OwnVersionDropPlan(new FrameDeletePlan(Comet, [], 0, [block]), Guid.NewGuid(), "IMG_0003.JPG", "b", []));
|
||||
var asked = 0;
|
||||
var dialog = new VersionsDialogViewModel((ICopyEngine)engine, Comet.Id, Comet.DisplayTitle, _ =>
|
||||
{
|
||||
asked++;
|
||||
return true;
|
||||
}, _ => { });
|
||||
var row = new VersionRow(dialog, new PhotoVersions(Guid.NewGuid(), "IMG_0002.JPG", "a", Guid.NewGuid(), "IMG_0003.JPG", "b"), Guid.NewGuid(), "IMG_0002.JPG", 10, "IMG_0003.JPG", inMain: true);
|
||||
|
||||
await dialog.DropAsync(row);
|
||||
|
||||
Assert.Equal(0, asked);
|
||||
Assert.Equal(0, ((FakeEngine)engine).Dropped);
|
||||
Assert.Equal(expected, dialog.ErrorText);
|
||||
Assert.True(row.InMain);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>An <see cref="ICopyEngine"/> that plans <see cref="Plan"/> for every drop and counts the drops applied.</summary>
|
||||
public class FakeEngine : DispatchProxy
|
||||
{
|
||||
internal OwnVersionDropPlan? Plan { get; set; }
|
||||
|
||||
internal int Dropped { get; private set; }
|
||||
|
||||
internal static object Create(OwnVersionDropPlan plan)
|
||||
{
|
||||
var proxy = Create<ICopyEngine, FakeEngine>();
|
||||
((FakeEngine)(object)proxy).Plan = plan;
|
||||
return proxy;
|
||||
}
|
||||
|
||||
protected override object? Invoke(MethodInfo? targetMethod, object?[]? args) => targetMethod?.Name switch
|
||||
{
|
||||
nameof(ICopyEngine.PlanDropOwnVersionAsync) => Task.FromResult(Plan!),
|
||||
nameof(ICopyEngine.DropOwnVersionAsync) => Drop(),
|
||||
nameof(ICopyEngine.VersionsAsync) => Task.FromResult<IReadOnlyList<PhotoVersions>>([]),
|
||||
nameof(IDisposable.Dispose) => null,
|
||||
_ => throw new NotSupportedException(targetMethod?.Name),
|
||||
};
|
||||
|
||||
private Task<int> Drop()
|
||||
{
|
||||
Dropped++;
|
||||
return Task.FromResult(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -195,9 +195,12 @@ public abstract class SequenceMergerTests(TestContext context) : DatabaseTest(co
|
||||
var merger = Merger(fx);
|
||||
var (only, theirs, mine) = (Sha(3, 20_000), Sha(5, 30_250), Sha(4, 30_250));
|
||||
|
||||
// Choose each with nothing chosen: the only-there photo still comes; the other's different version is a last copy.
|
||||
// Choose each with nothing chosen: the plan waits for a choice (a merge offers no Leave, owner review 6); the only-there
|
||||
// photo still comes; the other's different version is a last copy.
|
||||
var plan = await merger.PlanAsync(copy.Id, keep.Id, drop.Id, await ChoicesAsync(fx, keep.Id, drop.Id, CopyPhotoPolicy.ChoosePerPhoto), NoContext, Ct);
|
||||
Assert.Empty(plan.Blocks);
|
||||
Assert.SequenceEqual([CopyBlock.PhotosUnchosen], plan.Blocks);
|
||||
Assert.Equal(1, plan.PhotosUnchosen);
|
||||
Assert.False(plan.CanApply);
|
||||
Assert.SequenceEqual([(PhotoAction.Fetch, only)], plan.Photos.Select(p => (p.Action, p.Sha256!)));
|
||||
Assert.SequenceEqual([(CopySide.Other, theirs)], plan.LastCopies.Select(l => (l.Side, l.Key)));
|
||||
|
||||
@@ -514,6 +517,133 @@ public abstract class SequenceMergerTests(TestContext context) : DatabaseTest(co
|
||||
Assert.False(plan.CanApply);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task APlanMadeAgainHashesNoPhotoThatDidNotChange()
|
||||
{
|
||||
var fx = await FixtureAsync();
|
||||
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")]);
|
||||
// The other's photos not hashed yet (an older import): the plan hashes those only it holds, to compare them by content.
|
||||
await new DbAccess(fx.Db.Database).ExecuteAsync("UPDATE frames SET sha256 = NULL WHERE sequence_id = $1", [drop.Id], Ct);
|
||||
var copy = await PairAsync(fx, keep.Id, drop.Id);
|
||||
var merger = Merger(fx);
|
||||
var choices = await ChoicesAsync(fx, keep.Id, drop.Id, CopyPhotoPolicy.Union);
|
||||
|
||||
await merger.PlanAsync(copy.Id, keep.Id, drop.Id, choices, NoContext, Ct);
|
||||
var first = merger.FilesHashed;
|
||||
Assert.True(first >= 2, $"{first} files hashed");
|
||||
// Each choice in the dialog plans again: the photos read before are not read again.
|
||||
await merger.PlanAsync(copy.Id, keep.Id, drop.Id, choices, NoContext, Ct);
|
||||
await merger.PlanAsync(copy.Id, keep.Id, drop.Id, choices, NoContext, Ct);
|
||||
Assert.Equal(first, merger.FilesHashed);
|
||||
|
||||
// A photo whose file changed is read again.
|
||||
var changed = (await fx.Db.Frames.ListBySequenceAsync(drop.Id))[^1]; // in capture order: photo 3
|
||||
var file = fx.Paths.FromRelative(changed.RelativePath);
|
||||
File.WriteAllBytes(file, Photos.Jpeg(Start.AddMilliseconds(20_000), 99));
|
||||
File.SetLastWriteTimeUtc(file, DateTime.UtcNow.AddMinutes(1));
|
||||
await merger.PlanAsync(copy.Id, keep.Id, drop.Id, choices, NoContext, Ct);
|
||||
Assert.Equal(first + 1, merger.FilesHashed);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PhotosTheIndexHasNotReadInTheOtherBlockThePlan()
|
||||
{
|
||||
var fx = await FixtureAsync();
|
||||
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")]);
|
||||
await fx.ScanAsync();
|
||||
var copy = await PairAsync(fx, keep.Id, drop.Id);
|
||||
var merger = Merger(fx);
|
||||
var choices = await ChoicesAsync(fx, keep.Id, drop.Id, CopyPhotoPolicy.Union);
|
||||
Assert.DoesNotContain(CopyBlock.FolderChanged, (await merger.PlanAsync(copy.Id, keep.Id, drop.Id, choices, NoContext, Ct)).Blocks);
|
||||
|
||||
// A photo copied into the other's folder by hand: the index has not read it, so the trash would take it unseen.
|
||||
var folder = fx.Paths.Sequence(drop.Folder);
|
||||
var extra = Path.Combine(ArchiveScanner.PhotoDirectory(folder), "IMG_0099.JPG");
|
||||
File.WriteAllBytes(extra, Photos.Jpeg(Start.AddMilliseconds(99_000), 99));
|
||||
var plan = await merger.PlanAsync(copy.Id, keep.Id, drop.Id, choices, NoContext, Ct);
|
||||
Assert.Contains(CopyBlock.FolderChanged, plan.Blocks);
|
||||
Assert.False(plan.CanApply);
|
||||
Assert.Equal(Chronos.Core.Localization.Loc.L("Errors.Copies.FolderChanged", "Drop"), SequenceMerger.BlockText(plan, CopyBlock.FolderChanged, "Keep", "Drop"));
|
||||
|
||||
// Read by a scan: the plan may go again.
|
||||
await fx.ScanAsync();
|
||||
Assert.DoesNotContain(CopyBlock.FolderChanged, (await merger.PlanAsync(copy.Id, keep.Id, drop.Id, choices, NoContext, Ct)).Blocks);
|
||||
|
||||
// A sidecar another index wrote past this one's frames version blocks too.
|
||||
var manifest = ManifestStore.ReadSequence(folder.ManifestPath);
|
||||
ManifestStore.WriteSequence(folder.ManifestPath, manifest with { Versions = manifest.Versions with { Frames = manifest.Versions.Frames + 1 } });
|
||||
Assert.Contains(CopyBlock.FolderChanged, (await merger.PlanAsync(copy.Id, keep.Id, drop.Id, choices, NoContext, Ct)).Blocks);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AResumedMergeStopsBeforeTheTrashWhenTheOtherFolderGotPhotosMeanwhile()
|
||||
{
|
||||
var fx = await FixtureAsync();
|
||||
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")]);
|
||||
await fx.ScanAsync();
|
||||
var copy = await PairAsync(fx, keep.Id, drop.Id);
|
||||
var merger = Merger(fx);
|
||||
var (engine, handler) = Engine(fx, merger, new FakeProjects(), new FakeWorkspace());
|
||||
await engine.StartAsync(Ct);
|
||||
var crashed = false;
|
||||
handler.BeforeStage = stage =>
|
||||
{
|
||||
if (stage != MergeStage.Links || crashed) return Task.CompletedTask;
|
||||
crashed = true;
|
||||
throw new IOException("crash before the links");
|
||||
};
|
||||
var plan = await merger.PlanAsync(copy.Id, keep.Id, drop.Id, await ChoicesAsync(fx, keep.Id, drop.Id, CopyPhotoPolicy.Union), NoContext, Ct);
|
||||
Assert.Empty(plan.Blocks);
|
||||
var job = await merger.EnqueueAsync(engine, new FoundCopyStore(fx.Db), plan, keep.DisplayTitle, Ct);
|
||||
await fx.WaitForAsync(job.Id, JobState.Failed);
|
||||
|
||||
// While it waits, a photo lands in the other's folder outside the index.
|
||||
var extra = Path.Combine(ArchiveScanner.PhotoDirectory(fx.Paths.Sequence(drop.Folder)), "IMG_0099.JPG");
|
||||
File.WriteAllBytes(extra, Photos.Jpeg(Start.AddMilliseconds(99_000), 99));
|
||||
await engine.ResumeAsync(job.Id, Ct);
|
||||
var failed = await fx.WaitForAsync(job.Id, JobState.Failed);
|
||||
|
||||
Assert.Equal(Chronos.Core.Localization.Loc.L("Errors.Copies.FolderChanged", drop.DisplayTitle), failed.Error);
|
||||
Assert.NotNull(await fx.Db.Sequences.GetAsync(drop.Id));
|
||||
Assert.True(File.Exists(extra));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task APhotoOfTheOtherFlaggedDamagedWhileTheMergeWaitedIsCheckedOnResume()
|
||||
{
|
||||
var fx = await FixtureAsync();
|
||||
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")]);
|
||||
var copy = await PairAsync(fx, keep.Id, drop.Id);
|
||||
var merger = Merger(fx);
|
||||
var (engine, handler) = Engine(fx, merger, new FakeProjects(), new FakeWorkspace());
|
||||
await engine.StartAsync(Ct);
|
||||
var crashed = false;
|
||||
handler.BeforeStage = stage =>
|
||||
{
|
||||
if (stage != MergeStage.Verify || crashed) return Task.CompletedTask;
|
||||
crashed = true;
|
||||
throw new IOException("crash after the copy");
|
||||
};
|
||||
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);
|
||||
|
||||
// A verify meanwhile: the other's photo 2 was edited after the copy, its file the only copy of those bytes.
|
||||
var edited = (await fx.Db.Frames.ListBySequenceAsync(drop.Id)).First(f => f.Sha256 == Sha(2, 10_000));
|
||||
File.WriteAllBytes(fx.Paths.FromRelative(edited.RelativePath), Photos.Jpeg(Start.AddMilliseconds(10_000), 88));
|
||||
await fx.Db.Frames.UpdateFlagsAsync([edited.Id], FrameFlags.Corrupt, FrameFlags.None, Ct);
|
||||
await engine.ResumeAsync(job.Id, Ct);
|
||||
var failed = await fx.WaitForAsync(job.Id, JobState.Failed);
|
||||
|
||||
Assert.Equal(Chronos.Core.Localization.Loc.L("Errors.Copies.DamagedPhotos", drop.DisplayTitle), failed.Error);
|
||||
Assert.NotNull(await fx.Db.Sequences.GetAsync(drop.Id));
|
||||
Assert.Count(2, await fx.Db.Frames.ListBySequenceAsync(drop.Id));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task WorkSentHomeIntoTheOtherAfterAStoppedTrashAsksForANewPlan()
|
||||
{
|
||||
|
||||
@@ -320,6 +320,92 @@ public sealed class CopyEngineTests(TestContext context)
|
||||
Assert.True((await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct)).Any(fr => fr.Sha256 == Sha(a)));
|
||||
}
|
||||
|
||||
/// <summary>The photos Main leaves out of <paramref name="sequenceId"/>, by content.</summary>
|
||||
private static async Task<IReadOnlySet<string>> ExcludedAsync(SyncFixture f, Guid sequenceId)
|
||||
{
|
||||
var row = (await f.Db.Sequences.GetAsync(sequenceId))!;
|
||||
return CopyPayload.ExcludedKeys(CopyPayload.Portable(SyncPayload.Of(row), await SequencePayloadWriter.PhotosAsync(f.Db, sequenceId, null, f.Ct)));
|
||||
}
|
||||
|
||||
/// <summary>Main of <paramref name="sequenceId"/> leaves out <paramref name="key"/>, as a Union keep-both leaves the incoming version.</summary>
|
||||
private static async Task ExcludeAsync(SyncFixture f, Guid sequenceId, string key)
|
||||
{
|
||||
var row = (await f.Db.Sequences.GetAsync(sequenceId))!;
|
||||
var portable = CopyPayload.Portable(SyncPayload.Of(row), await SequencePayloadWriter.PhotosAsync(f.Db, sequenceId, null, f.Ct));
|
||||
await new SequencePayloadWriter(f.Db, f.Archive.Service).ApplyAsync(sequenceId, CopyPayload.ExcludeVersions(portable, [key]), row.SettingsVersion, f.Ct);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DroppingTheVersionMainUsesLetsMainUseTheOneThatStays()
|
||||
{
|
||||
// A Union keep-both excluded version B in Main; the user drops A, the one Main used: Main must not be left without
|
||||
// the photo (owner review 6, verification round 5).
|
||||
await using var f = await FixtureAsync(context);
|
||||
var (local, _, a, b) = await VersionsAsync(f);
|
||||
await ExcludeAsync(f, local.Id, Sha(b));
|
||||
Assert.SequenceEqual([Sha(b)], await ExcludedAsync(f, local.Id));
|
||||
using var engine = Engine(f);
|
||||
var photo = (await engine.VersionsAsync(local.Id, f.Ct)).Single();
|
||||
var (frameA, aExcluded, bExcluded) = photo.FirstSha256 == Sha(a)
|
||||
? (photo.FirstFrameId, photo.FirstExcluded, photo.SecondExcluded)
|
||||
: (photo.SecondFrameId, photo.SecondExcluded, photo.FirstExcluded);
|
||||
Assert.Equal((false, true), (aExcluded, bExcluded));
|
||||
|
||||
var plan = await engine.PlanDropOwnVersionAsync(local.Id, frameA, f.Ct);
|
||||
Assert.Equal(1, await engine.DropOwnVersionAsync(plan, f.Ct));
|
||||
|
||||
Assert.Empty(await ExcludedAsync(f, local.Id));
|
||||
Assert.True((await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct)).Any(fr => fr.Sha256 == Sha(b)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task KeepVersionMovesTheExclusionHeroAndKeyframesToTheVersionThatStays()
|
||||
{
|
||||
await using var f = await FixtureAsync(context);
|
||||
var (local, _, a, b) = await VersionsAsync(f);
|
||||
await ExcludeAsync(f, local.Id, Sha(b));
|
||||
var row = (await f.Db.Sequences.GetAsync(local.Id))!;
|
||||
var portable = CopyPayload.Portable(SyncPayload.Of(row), await SequencePayloadWriter.PhotosAsync(f.Db, local.Id, null, f.Ct));
|
||||
|
||||
// Main used A and left B out: once A goes, B is used.
|
||||
var kept = CopyPayload.KeepVersion(portable, Sha(b), Sha(a));
|
||||
Assert.NotNull(kept);
|
||||
Assert.Empty(CopyPayload.ExcludedKeys(kept!));
|
||||
// Dropping the excluded one changes nothing in Main.
|
||||
Assert.Null(CopyPayload.KeepVersion(portable, Sha(a), Sha(b)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DropVersionOfTwoLocalSequencesCountsAPhotoOnEachSide()
|
||||
{
|
||||
// Finding 9 said a pair of this PC's sequences listed "0 photos": the plan counts each local side's version.
|
||||
await using var f = await FixtureAsync(context);
|
||||
var (local, _, a, b) = await VersionsAsync(f);
|
||||
var at = ArchiveFixture.Start.AddSeconds(5).AddMilliseconds(250);
|
||||
var plainAt = ArchiveFixture.Start;
|
||||
var other = await f.LocalAsync("Comet copy", [Photos.Jpeg(plainAt, 7001), a, b], capturedAt: [plainAt, at, at]);
|
||||
var pair = await f.Sync.Copies.UpsertFoundAsync(new FoundCopy
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Kind = CopyKind.LocalLocal,
|
||||
LocalId = local.Id,
|
||||
OtherId = other.Id,
|
||||
Evidence = CopyEvidence.Hashes,
|
||||
Fingerprint = "f",
|
||||
}, f.Ct);
|
||||
await ExcludeAsync(f, local.Id, Sha(b));
|
||||
await ExcludeAsync(f, other.Id, Sha(b));
|
||||
using var engine = Engine(f);
|
||||
|
||||
var plan = await engine.PlanDropVersionAsync(pair.Id, Sha(a), null, f.Ct);
|
||||
Assert.Equal((Sha(b), 2), (plan.PartnerKey, plan.Photos));
|
||||
Assert.Equal(2, await engine.DropVersionAsync(plan, null, f.Ct));
|
||||
|
||||
// Both sides' Main now use the version that stays.
|
||||
Assert.Empty(await ExcludedAsync(f, local.Id));
|
||||
Assert.Empty(await ExcludedAsync(f, other.Id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A pair holding one photo in two versions (a Union keep-both): two files of one sub-second capture time, on both sides,
|
||||
/// besides one plain photo.
|
||||
|
||||
|
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: 75 KiB After Width: | Height: | Size: 75 KiB |
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 89 KiB |
|
After Width: | Height: | Size: 87 KiB |
|
Before Width: | Height: | Size: 9.6 KiB After Width: | Height: | Size: 9.9 KiB |
|
Before Width: | Height: | Size: 9.1 KiB After Width: | Height: | Size: 9.4 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: 77 KiB |
|
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 77 KiB |