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:
1 parent
fe752a0a21
commit
d10577b175
18 files changed
+804
-11
No files matched your search
@@ -280,6 +280,46 @@ public sealed class IntegrateTests(TestContext context)
|
||||
Assert.False(File.Exists(IntegrateJournal.PathFor(f.Archive.Paths, job.Id)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ACorruptPhotoOnThisPcIsRepairedFromTheServersCopy()
|
||||
{
|
||||
await using var f = await FixtureAsync(context);
|
||||
var local = await LocalAsync(f, "Comet", [(1, 0, "IMG_0001.JPG"), (2, 10_000, "IMG_0002.JPG")]);
|
||||
var names = await NamesAsync(f, local.Id);
|
||||
var remote = Remote(f, "Comet", [(1, 0, names[0]), (2, 10_000, names[1])]);
|
||||
var pair = await PairAsync(f, local.Id, remote.Id);
|
||||
// A verify finds the second photo damaged on this PC (design §5c: an unusable photo the other side holds is a repair).
|
||||
var damaged = (await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct)).Single(fr => fr.Sha256 == Sha(2, 10_000));
|
||||
var file = f.Archive.Paths.FromRelative(damaged.RelativePath);
|
||||
var bytes = await File.ReadAllBytesAsync(file, f.Ct);
|
||||
bytes[^10] ^= 0xFF;
|
||||
await File.WriteAllBytesAsync(file, bytes, f.Ct);
|
||||
await f.Archive.Service.Verifier.VerifyAsync(f.Archive.Archive, [local.Id], default, (_, _, _) => ValueTask.CompletedTask, cancellationToken: f.Ct);
|
||||
Assert.Equal(FrameFlags.Corrupt, (await f.Db.Frames.GetAsync(damaged.Id, f.Ct))!.Flags);
|
||||
var (engine, _) = Engine(f);
|
||||
await using var _ = engine;
|
||||
await engine.StartAsync(f.Ct);
|
||||
|
||||
var plan = await Planner(f).PlanAsync(f.Remote, pair, await ChoicesAsync(f, local.Id, remote.Id, CopyPhotoPolicy.Union), PlanContext(), f.Ct);
|
||||
Assert.SequenceEqual([(PhotoAction.Fetch, Sha(2, 10_000))], plan.Photos.Select(p => (p.Action, p.Sha256!)));
|
||||
Assert.Equal(0, plan.LeftOut);
|
||||
var job = await CopyJobs.EnqueueIntegrateAsync(engine, f.Sync.Copies, plan, local.DisplayTitle, f.Ct);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
var frames = await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct);
|
||||
Assert.Count(2, frames);
|
||||
var repaired = frames.Single(fr => fr.Sha256 == Sha(2, 10_000));
|
||||
Assert.Equal(FrameFlags.None, repaired.Flags & (FrameFlags.Corrupt | FrameFlags.Missing));
|
||||
var repairedFile = f.Archive.Paths.FromRelative(repaired.RelativePath);
|
||||
Assert.Equal(Sha(2, 10_000), Sha(await File.ReadAllBytesAsync(repairedFile, f.Ct)));
|
||||
// The damaged file is kept beside it, never deleted.
|
||||
var aside = Directory.EnumerateFiles(Path.GetDirectoryName(repairedFile)!, Path.GetFileName(repairedFile) + ".damaged-*").ToList();
|
||||
Assert.Count(1, aside);
|
||||
Assert.True((await File.ReadAllBytesAsync(aside[0], f.Ct)).AsSpan().SequenceEqual(bytes), "the damaged file moved aside");
|
||||
Assert.Equal(0, f.Remote.IntoUploads);
|
||||
Assert.Equal(CopyState.Integrated, (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.State);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AJobWhosePlanMovedRefusesAndSetsThePairBack()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user