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:
1 parent
2c06e7ac2b
commit
bf7701d279
159 files changed
+1759
-126
No files matched your search
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user