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

@@ -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);