fix(copies): close the third verification round and add the match baselines

Integrate trashes a server photo only for the sequence's owner or an admin, a
Details stage stops instead of overwriting a server change the user had kept
this PC's value against, a merge retried after a stop plans again when work
reached the other sequence, detection keeps pairs answered while it ran, and a
sync row whose match the server deleted offers Keep here, Upload again and To
trash. The Integrate and merge logs say in the UI language why a version was
kept.

The edit-picker-twins capture scene showed no Twin chip, since a capture has no
workspace: it now lists sample workspace projects of the sample matches. The
screenshot baselines gain the 38 Matches screens and take the Matches chip,
the three Settings > Server rows, the longer priority list and 1.2.0.

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 18:01:37 +01:00
1 parent 3e6110d329
commit 3c99badcfe
96 files changed
+910 -147

No files matched your search

@@ -497,6 +497,96 @@ public abstract class SequenceMergerTests(TestContext context) : DatabaseTest(co
Assert.DoesNotContain(CopyBlock.DamagedPhotos, (await merger.PlanAsync(copy.Id, keep.Id, drop.Id, choices, NoContext, Ct)).Blocks);
}
[Test]
public async Task APhotoFlaggedMissingWhoseFileIsThereBlocksTheMerge()
{
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")]);
// Flagged Missing by an earlier verify (a drive away then), its file back now: the merge would not copy it.
var missing = (await fx.Db.Frames.ListBySequenceAsync(drop.Id)).First(f => f.Sha256 == Sha(2, 10_000));
await fx.Db.Frames.UpdateFlagsAsync([missing.Id], FrameFlags.Missing, FrameFlags.None, Ct);
var copy = await PairAsync(fx, keep.Id, drop.Id);
var plan = await Merger(fx).PlanAsync(copy.Id, keep.Id, drop.Id, await ChoicesAsync(fx, keep.Id, drop.Id, CopyPhotoPolicy.Union), NoContext, Ct);
Assert.Contains(CopyBlock.DamagedPhotos, plan.Blocks);
Assert.False(plan.CanApply);
}
[Test]
public async Task WorkSentHomeIntoTheOtherAfterAStoppedTrashAsksForANewPlan()
{
var fx = await FixtureAsync();
var merger = Merger(fx);
var workspace = new FakeWorkspace();
var (engine, handler) = Engine(fx, merger, new FakeProjects(), workspace);
await engine.StartAsync(Ct);
var store = new FoundCopyStore(fx.Db);
// Details sent home (a settings version), then a project made in the other (a new head), each after the stop.
Func<Sequence, Task>[] sends =
[
drop => fx.Db.Sequences.SetTagsAsync(drop.Id, ["sent"], Ct),
drop => fx.Service.Projects.CreateAsync(drop.Id, "Sent cut", cancellationToken: fx.Ct),
];
for (var i = 0; i < sends.Length; i++)
{
var keep = await SequenceAsync(fx, $"keep-{i}", [(10 * i + 1, 0, "IMG_0001.JPG")]);
var drop = await SequenceAsync(fx, $"drop-{i}", [(10 * i + 1, 0, "IMG_0001.JPG"), (10 * i + 2, 10_000, "IMG_0002.JPG")]);
var copy = await PairAsync(fx, keep.Id, drop.Id);
handler.BeforeStage = stage =>
{
if (stage == MergeStage.Trash) workspace.Unsent.Add(drop.Id);
return Task.CompletedTask;
};
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, store, plan, keep.DisplayTitle, Ct);
await fx.WaitForAsync(job.Id, JobState.Failed);
// The workspace sends its work home into the other, then Retry.
await sends[i](drop);
handler.BeforeStage = null;
workspace.Unsent.Clear();
await engine.ResumeAsync(job.Id, Ct);
var failed = await fx.WaitForAsync(job.Id, JobState.Failed);
Assert.Equal(Chronos.Core.Localization.Loc.L("Errors.Copies.Changed", drop.DisplayTitle), failed.Error);
Assert.NotNull(await fx.Db.Sequences.GetAsync(drop.Id));
Assert.False(File.Exists(MergeJournal.PathFor(fx.Paths, job.Id)), "the next run plans again");
}
}
[Test]
public async Task APhotoSettledThroughAThirdSequenceThatIsGoneByTheTrashKeepsTheOther()
{
var fx = await FixtureAsync();
var keep = await SequenceAsync(fx, "keep", [(1, 0, "IMG_0001.JPG"), (4, 30_250, "IMG_0004.JPG")]);
var drop = await SequenceAsync(fx, "drop", [(1, 0, "IMG_0001.JPG"), (5, 30_250, "IMG_0004.JPG")]);
// A third sequence holds the other's losing version: not a last copy when planned.
var third = await SequenceAsync(fx, "third", [(5, 30_250, "IMG_0004.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 plan = await merger.PlanAsync(copy.Id, keep.Id, drop.Id, await ChoicesAsync(fx, keep.Id, drop.Id, CopyPhotoPolicy.ThisPcWins), NoContext, Ct);
Assert.Empty(plan.LastCopies);
handler.BeforeStage = async stage =>
{
if (stage == MergeStage.Trash) await fx.Db.Sequences.DeleteAsync(third.Id, Ct);
};
var job = await merger.EnqueueAsync(engine, new FoundCopyStore(fx.Db), plan, keep.DisplayTitle, Ct);
var failed = await fx.WaitForAsync(job.Id, JobState.Failed);
// Now the other holds its only copy: nothing goes to the trash, and the next plan lists it as a last copy.
Assert.Equal(Chronos.Core.Localization.Loc.L("Errors.Copies.Changed", drop.DisplayTitle), failed.Error);
Assert.Contains(Sha(5, 30_250), await HashesAsync(fx, drop.Id));
Assert.False(File.Exists(MergeJournal.PathFor(fx.Paths, job.Id)));
var again = await merger.PlanAsync(copy.Id, keep.Id, drop.Id, await ChoicesAsync(fx, keep.Id, drop.Id, CopyPhotoPolicy.ThisPcWins), NoContext, Ct);
Assert.Contains(again.LastCopies, l => l.Key == Sha(5, 30_250));
}
[Test]
public async Task APhotoAddedToTheOtherOrDeletedFromTheKeptOneMeanwhileKeepsTheOtherOutOfTheTrash()
{
@@ -70,6 +70,23 @@ public abstract class FoundCopyStoreTests(TestContext context) : RepositoryTest(
return job;
}
[Test]
public async Task ThePruneOfAStaleCandidateLeavesARowAnsweredMeanwhile()
{
var (db, _, s) = await SetupAsync(2);
var store = new FoundCopyStore(db);
var stale = await store.UpsertFoundAsync(Remote(s[0].Id, Guid.CreateVersion7()), Ct);
var answered = await store.UpsertFoundAsync(Remote(s[1].Id, Guid.CreateVersion7()), Ct);
// Detection read both as candidates; the user keeps one apart before the prune runs.
Assert.True(await store.SetStateAsync(answered.Id, CopyState.Candidate, CopyState.KeptApart, Answer(), Ct));
Assert.True(await store.DeleteCandidateAsync(stale.Id, Ct));
Assert.False(await store.DeleteCandidateAsync(answered.Id, Ct));
Assert.Null(await store.GetAsync(stale.Id, Ct));
Assert.Equal(CopyState.KeptApart, (await store.GetAsync(answered.Id, Ct))!.State);
}
[Test]
public async Task AnUpsertUpdatesScoresAndKeepsTheStateAndTheStrongerEvidence()
{
@@ -261,6 +261,58 @@ public sealed class IntegrateTests(TestContext context)
Assert.Contains(CopyBlock.NoDeleteRight, plan.Blocks);
}
[Test]
public async Task AnEditorMayNotTrashTheVersionOfASequenceSomeoneElseOwns()
{
await using var f = await FixtureAsync(context);
var local = await LocalAsync(f, "Comet", [(1, 0, "IMG_0001.JPG"), (4, 30_250, "IMG_0004.JPG")]);
var names = await NamesAsync(f, local.Id);
var remote = Remote(f, "Comet", [(1, 0, names[0]), (5, 30_250, names[1])]);
remote.OwnerUserId = Guid.NewGuid();
var pair = await PairAsync(f, local.Id, remote.Id);
var choices = await ChoicesAsync(f, local.Id, remote.Id, CopyPhotoPolicy.ThisPcWins);
// An Editor: the Delete right, but not the admin role, and the server sequence is someone else's.
var editor = PlanContext() with { OwnsOrAdmin = false, UserId = Guid.NewGuid() };
var plan = await Planner(f).PlanAsync(f.Remote, pair, choices, editor, f.Ct);
Assert.False(plan.Photos.Any(p => p.Action == PhotoAction.TrashThere), "no trash step on the server");
// It stays, out of the server's Main, which uses this PC's version instead.
Assert.Equal((1, 1, 1), (plan.LeftOut, plan.StaysForDelete, plan.ServerUsesOurs));
Assert.Contains(CopyBlock.NoDeleteRight, plan.Blocks);
Assert.False(plan.Destructive);
// The owner may: the same plan trashes the server's version, and the server uses this PC's.
var owner = editor with { UserId = remote.OwnerUserId };
var owned = await Planner(f).PlanAsync(f.Remote, pair, choices, owner, f.Ct);
Assert.Contains(owned.Photos, p => p.Action == PhotoAction.TrashThere);
Assert.Equal((0, 1), (owned.StaysForDelete, owned.ServerUsesOurs));
// Compare offers Delete on server only where the server would allow it.
var builder = new CopyReviewBuilder(f.Db, f.Archive.Service.Projects, new CopySides(f.Db));
Assert.False((await builder.BuildAsync(pair, f.Remote, editor, f.Ct)).Can.DeleteThere);
Assert.True((await builder.BuildAsync(pair, f.Remote, owner, f.Ct)).Can.DeleteThere);
}
[Test]
public async Task WithoutTheDeleteRightTheServersVersionStaysOutOfItsMainAndTheRestRuns()
{
await using var f = await FixtureAsync(context);
var (local, remote, pair) = await ScenarioAsync(f);
var choices = await ChoicesAsync(f, local.Id, remote.Id, CopyPhotoPolicy.ThisPcWins);
var plan = await Planner(f).PlanAsync(f.Remote, pair, choices, PlanContext(canDelete: false), f.Ct);
// The server's losing version stays (it needs the Delete right), but its Main uses this PC's version.
Assert.False(plan.Photos.Any(p => p.Action == PhotoAction.TrashThere), "no trash step on the server");
Assert.Equal((1, 1), (plan.StaysForDelete, plan.ServerUsesOurs));
var pending = ProjectSettings.FromJson(SyncRules.NormalizeSettings(Assert.NotNull(plan.Payload).SettingsJson)).PendingFrames ?? [];
Assert.Contains(pending, p => p.Sha256 == Sha(5, 30_250) && p.Excluded);
// Other steps remain: the plan runs, only the delete waits.
Assert.DoesNotContain(CopyBlock.NoDeleteRight, plan.Blocks);
Assert.True(plan.CanApply);
}
[Test]
public async Task UnionBringsEveryPhotoBothWaysAndIntegratesThePair()
{
@@ -476,6 +528,11 @@ public sealed class IntegrateTests(TestContext context)
var failed = await f.Archive.WaitForAsync(job.Id, JobState.Failed);
Assert.Equal(Loc.Plural("Errors.Copies.Kept", 1), failed.Error);
// The log says why in the UI language: "IMG_0004.JPG: older version kept, the server refused it (…)".
var log = Assert.NotNull(failed.LogTail);
Assert.Contains(Between(Loc.L("Archive.Log.CopyKept", "\u0001", "\u0002"), '\u0001', '\u0002'), log);
var refused = Loc.L("Archive.Log.KeptReason.Refused", "\u0001");
Assert.Contains(refused[..refused.IndexOf('\u0001', StringComparison.Ordinal)], log);
Assert.Contains(Sha(5, 30_250), RemoteHashes(remote));
Assert.Contains(Sha(4, 30_250), RemoteHashes(remote));
Assert.Contains(Sha(3, 20_000), await LocalHashesAsync(f, local.Id));
@@ -536,6 +593,39 @@ public sealed class IntegrateTests(TestContext context)
Assert.Equal(CopyState.Linked, (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.State);
}
[Test]
public async Task AServerTitleEditMeanwhileOverAPlannedLineThisPcWinsStopsTheDetails()
{
await using var f = await FixtureAsync(context);
var (engine, handler) = Engine(f);
await using var _ = engine;
await engine.StartAsync(f.Ct);
var photos = f.NewPhotos(3);
var local = await f.LocalAsync("Comet", photos.Take(2).ToList(), SyncFixture.Window33);
var remote = f.Remote.Add("Comet NAS", [photos[0], photos[2]], SyncFixture.Window33);
var pair = await PairAsync(f, local.Id, remote.Id);
// The title differs and the user keeps this PC's; someone renames the server's while the photos travel.
handler.BeforeStage = stage =>
{
if (stage == IntegrateStage.Photos)
{
remote.Title = "Comet (night)";
remote.SettingsVersion++;
remote.UpdatedAt = DateTimeOffset.UtcNow;
}
return Task.CompletedTask;
};
var plan = await Planner(f).PlanAsync(f.Remote, pair, await ChoicesAsync(f, local.Id, remote.Id, CopyPhotoPolicy.Union), PlanContext(), f.Ct);
var job = await CopyJobs.EnqueueIntegrateAsync(engine, f.Sync.Copies, plan, local.DisplayTitle, f.Ct);
var failed = await f.Archive.WaitForAsync(job.Id, JobState.Failed);
// Not absorbed over the user's choice: the Details stage stops and neither title is overwritten.
Assert.Equal(Loc.L("Errors.Copies.DetailsChanged"), failed.Error);
Assert.Equal("Comet", (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.Title);
Assert.Equal("Comet (night)", remote.Title);
}
[Test]
public async Task ACancelledQueuedJobSetsThePairBack()
{
@@ -744,6 +834,13 @@ public sealed class IntegrateTests(TestContext context)
}
/// <summary>Waits until no job works on <paramref name="sequenceId"/> (the passes an Integrate queues after its photos).</summary>
/// <summary>The fixed text of a localized line between two placeholders' markers.</summary>
private static string Between(string text, char from, char to)
{
var start = text.IndexOf(from, StringComparison.Ordinal) + 1;
return text[start..text.IndexOf(to, start)];
}
private static async Task WaitIdleAsync(SyncFixture f, Guid sequenceId)
{
var until = DateTime.UtcNow.AddSeconds(30);