fix(copies): close the tenth verification round of owner review 6
- A merge verify that finds a hashed photo the plan did not copy (held by a third sequence when planned) held by nothing now drops its journal and fails as a stale plan, so the retry plans again and lists the photo as a last copy instead of failing with "did not match after copying" forever. - A comparison settles no details of a pair being integrated, and the Integrate's Details stage refuses a line decided as the server's whose server value is now this PC's own, so a background push or pull no longer reverses the user's line-by-line choice (owner Q4). - A 404 for a server sequence no local copy is linked to deletes only its Candidate pairs; a Kept apart answer counts the hit as a linked pair does (two 404s GoneRecheck apart), so a moment's 404 neither re-asks nor auto-links a pair the user kept separate (owner Q1). Upload all local sends the local sequence once the deletion is confirmed. - Download originals into a local copy the server key names and that is paired with the server sequence links it first and fills it as a linked copy: its tombstones hold and its details are compared, not overwritten. - An upload of a sequence with a Candidate pair goes under a key of the job, and one that joins a server sequence this PC already knows compares its details instead of sending them all over the server's. Refs #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c1c02d8ef7
commit
e002c583d6
12 files changed
+383
-34
No files matched your search
@@ -276,7 +276,7 @@ public abstract class FoundCopyStoreTests(TestContext context) : RepositoryTest(
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task A404OfAServerSequenceNoLocalCopyIsLinkedToDeletesItsUnlinkedMatches()
|
||||
public async Task A404OfAServerSequenceNoLocalCopyIsLinkedToDeletesItsCandidatesAndCountsOnItsKeptApartAnswers()
|
||||
{
|
||||
var (db, _, s) = await SetupAsync(4);
|
||||
var store = new FoundCopyStore(db);
|
||||
@@ -289,18 +289,35 @@ public abstract class FoundCopyStoreTests(TestContext context) : RepositoryTest(
|
||||
var elsewhere = await store.UpsertFoundAsync(Remote(s[3].Id, Guid.CreateVersion7()), Ct);
|
||||
|
||||
// An observation-only link answers 404: no local copy is linked to it.
|
||||
await store.MarkRemoteGoneAsync(Nas, remote, null, Guid.NewGuid(), TestData.Now, Ct);
|
||||
var first = Guid.NewGuid();
|
||||
await store.MarkRemoteGoneAsync(Nas, remote, null, first, TestData.Now, Ct);
|
||||
await store.MarkRemoteGoneAsync(Nas, remote, null, first, TestData.Now.AddMinutes(1), Ct);
|
||||
|
||||
// Its matches nobody linked are gone, so Upload all local reads their local sequences as local only again.
|
||||
// The unanswered match is gone; the Keep apart answer stays and counts the 404 once, not read as deleted yet.
|
||||
Assert.Null(await store.GetAsync(candidate.Id, Ct));
|
||||
Assert.Null(await store.GetAsync(apart.Id, Ct));
|
||||
var row = (await store.GetAsync(apart.Id, Ct))!;
|
||||
Assert.Equal((CopyState.KeptApart, 1, false), (row.State, row.RemoteGoneHits, row.RemoteGone));
|
||||
Assert.Equal(CopyState.Linked, (await store.GetAsync(linked.Id, Ct))!.State);
|
||||
Assert.Equal(CopyState.Candidate, (await store.GetAsync(elsewhere.Id, Ct))!.State);
|
||||
var left = await store.ListAsync(Ct);
|
||||
var entries = s[..2].Select(q => new SyncEntry(q, null, SyncStatus.LocalOnly)).ToList();
|
||||
var (upload, skipped) = UploadAllRule.Select(entries, left, new HashSet<Guid>(), new HashSet<Guid>());
|
||||
var (upload, skipped) = UploadAllRule.Select(entries, await store.ListAsync(Ct), new HashSet<Guid>(), new HashSet<Guid>());
|
||||
Assert.Equal(s[0].Id, upload.Single().Local!.Id);
|
||||
Assert.Equal((s[1].Id, UploadSkip.DeletedOnServer), (skipped.Single().Entry.Local!.Id, skipped.Single().Why));
|
||||
|
||||
// A second 404 within the re-check is the same moment; one after it confirms the deletion.
|
||||
await store.MarkRemoteGoneAsync(Nas, remote, null, Guid.NewGuid(), TestData.Now.AddMinutes(5), Ct);
|
||||
Assert.Equal(1, (await store.GetAsync(apart.Id, Ct))!.RemoteGoneHits);
|
||||
await store.MarkRemoteGoneAsync(Nas, remote, null, Guid.NewGuid(), TestData.Now.AddHours(1), Ct);
|
||||
row = (await store.GetAsync(apart.Id, Ct))!;
|
||||
Assert.Equal((CopyState.KeptApart, true), (row.State, row.RemoteGone));
|
||||
(upload, skipped) = UploadAllRule.Select(entries, await store.ListAsync(Ct), new HashSet<Guid>(), new HashSet<Guid>());
|
||||
Assert.Empty(skipped);
|
||||
Assert.Count(2, upload);
|
||||
|
||||
// Listed again: the count clears and the answer is the user's as before.
|
||||
await store.ClearRemoteGoneAsync(Nas, remote, Ct);
|
||||
row = (await store.GetAsync(apart.Id, Ct))!;
|
||||
Assert.Equal((CopyState.KeptApart, 0), (row.State, row.RemoteGoneHits));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -800,6 +800,73 @@ public sealed class IntegrateTests(TestContext context)
|
||||
Assert.Equal("Comet (night)", remote.Title);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A linked pair whose details were agreed, then edited on this PC (Window41, not sent yet), with every detail line
|
||||
/// decided as the server's (Window33): the plan of an Integrate the user confirmed.
|
||||
/// </summary>
|
||||
private static async Task<(Sequence Local, FakeSequence Remote, FoundCopy Pair, IntegratePlan Plan)> EditedHereServerChosenAsync(SyncFixture f)
|
||||
{
|
||||
var photos = f.NewPhotos(3);
|
||||
var local = await f.LocalAsync("Comet", photos.Take(2).ToList(), SyncFixture.Window33);
|
||||
var remote = f.Remote.Add("Comet", [photos[0], photos[2]], SyncFixture.Window33);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.Sync.RefreshSequencesAsync(f.Remote, [remote.Id], new SyncPolicy(AutoSyncSettings: false), f.Ct);
|
||||
Assert.Equal(local.SettingsVersion, (await f.Sync.Links.GetAsync(f.Server, remote.Id, f.Ct))!.BaseLocalSettings);
|
||||
local = await f.EditLocalSettingsAsync(local.Id, SyncFixture.Window41);
|
||||
var pair = (await f.Sync.Copies.FindRemoteAsync(local.Id, f.Server, remote.Id, f.Ct))!;
|
||||
var choices = await ChoicesAsync(f, local.Id, remote.Id, CopyPhotoPolicy.Union);
|
||||
Assert.NotEmpty(choices.Details);
|
||||
choices = choices with { Details = choices.Details.ToDictionary(d => d.Key, _ => CopySide.Other) };
|
||||
var plan = await Planner(f).PlanAsync(f.Remote, pair, choices, PlanContext(), f.Ct);
|
||||
return (local, remote, pair, plan);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ABackgroundSyncDuringTheIntegrateLeavesTheDetailsToTheUsersChoice()
|
||||
{
|
||||
await using var f = await FixtureAsync(context);
|
||||
var (engine, handler) = Engine(f);
|
||||
await using var _ = engine;
|
||||
await engine.StartAsync(f.Ct);
|
||||
var (local, remote, _, plan) = await EditedHereServerChosenAsync(f);
|
||||
// The server fires sequenceChanged as the photos land (or the periodic refresh runs): the agent compares the pair.
|
||||
handler.BeforeStage = async stage =>
|
||||
{
|
||||
if (stage == IntegrateStage.Details) await f.Sync.RefreshSequencesAsync(f.Remote, [remote.Id], new SyncPolicy(), f.Ct);
|
||||
};
|
||||
|
||||
var job = await CopyJobs.EnqueueIntegrateAsync(engine, f.Sync.Copies, plan, local.DisplayTitle, f.Ct);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
// The server's settings the user kept are on both sides: this PC's edit was not pushed over them meanwhile.
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window33, remote.SettingsJson), remote.SettingsJson);
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window33, (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.SettingsJson));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AServerValueThatIsThisPcsOwnOverALineDecidedAsTheServersStopsTheDetails()
|
||||
{
|
||||
await using var f = await FixtureAsync(context);
|
||||
var (engine, handler) = Engine(f);
|
||||
await using var _ = engine;
|
||||
await engine.StartAsync(f.Ct);
|
||||
var (local, remote, pair, plan) = await EditedHereServerChosenAsync(f);
|
||||
// This PC's planned value reaches the server while the photos travel (a push the job did not make).
|
||||
handler.BeforeStage = stage =>
|
||||
{
|
||||
if (stage == IntegrateStage.Photos) f.Remote.EditSettings(remote.Id, SyncFixture.Window41);
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
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 as a newer edit, which would reverse the user's choice on both sides: the details stop, the photos stay.
|
||||
Assert.Equal(Loc.L("Errors.Copies.DetailsChanged"), failed.Error);
|
||||
Assert.Equal(CopyState.Linked, (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.State);
|
||||
Assert.Equal(3, RemoteHashes(remote).Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ACancelledQueuedJobSetsThePairBack()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user