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
@@ -292,6 +292,108 @@ public sealed class SyncTransferCopyTests(TestContext context)
|
||||
Assert.Equal(1, (await f.Db.Sequences.ListAsync(new SequenceQuery(), f.Ct)).Items.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DownloadingAgainIntoTheOwnLocalCopyOfAPairAskedAgainKeepsItsDeletionsAndDetails()
|
||||
{
|
||||
await using var f = Capable(await SyncFixture.CreateAsync(context));
|
||||
var photos = f.NewPhotos(3);
|
||||
var remote = f.Remote.Add("Comet", photos);
|
||||
var engine = await f.StartEngineAsync();
|
||||
var job = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Comet", SyncDownloadMode.Originals, f.Archive.Archive.Id);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
var local = Assert.NotNull(Assert.NotNull(await f.Sync.Links.GetAsync(f.Server, remote.Id, f.Ct)).LocalId);
|
||||
await WaitIdleAsync(f, local);
|
||||
|
||||
// While linked: one photo deleted here (the server keeps it, owner Q6) and the title edited; then unlinked and
|
||||
// asked about again (Ask again, or a Keep apart undone).
|
||||
var sequence = (await f.Db.Sequences.GetAsync(local, f.Ct))!;
|
||||
var gone = (await f.Db.Frames.ListBySequenceAsync(local, cancellationToken: f.Ct))[0];
|
||||
var delete = await f.Archive.Service.FrameTrash.PlanDeleteAsync(local, [gone.Id], sequence.FramesVersion, f.Ct);
|
||||
await f.Archive.Service.FrameTrash.DeleteAsync(delete, cancellationToken: f.Ct);
|
||||
await f.Db.Sequences.EditAsync(local, new SequenceEdit { Title = "Mine" }, null, f.Ct);
|
||||
await f.Sync.UnlinkAsync(f.Server, remote.Id, local, f.Ct);
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(f.Server, f.Ct)).Single(c => c.RemoteId == remote.Id && c.LocalId == local);
|
||||
Assert.True(await f.Sync.Copies.SetStateAsync(pair.Id, CopyState.KeptApart, CopyState.Candidate, null, f.Ct));
|
||||
|
||||
// Download originals of the server sequence: it refills its own local copy, as a linked copy.
|
||||
job = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Comet", SyncDownloadMode.Originals, f.Archive.Archive.Id);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
// The photo deleted here stays deleted, and the title is not overwritten by the server's.
|
||||
Assert.Equal(local, Assert.NotNull(await f.Sync.Links.GetAsync(f.Server, remote.Id, f.Ct)).LocalId);
|
||||
Assert.Count(2, await f.Db.Frames.ListBySequenceAsync(local, cancellationToken: f.Ct));
|
||||
Assert.Contains(gone.Sha256, (await f.Db.FrameRemovals.ListBySequenceAsync(local, f.Ct)).Select(r => r.Sha256));
|
||||
Assert.Equal("Mine", (await f.Db.Sequences.GetAsync(local, f.Ct))!.Title);
|
||||
Assert.Equal("Comet", remote.Title);
|
||||
Assert.Equal(1, (await f.Db.Sequences.ListAsync(new SequenceQuery(), f.Ct)).Items.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnUploadOfASequenceAskedAboutAgainMakesANewServerSequenceAndLeavesTheOtherAlone()
|
||||
{
|
||||
await using var f = Capable(await SyncFixture.CreateAsync(context));
|
||||
var photos = f.NewPhotos(3);
|
||||
var local = await f.LocalAsync("Comet", [photos[0], photos[1]]);
|
||||
var engine = await f.StartEngineAsync();
|
||||
var job = await f.Sync.EnqueueUploadAsync(engine, f.Server, local);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
var first = Assert.NotNull(await f.Sync.Links.FindByLocalAsync(f.Server, local.Id, f.Ct)).RemoteId;
|
||||
// Unlinked, then asked about again: the pair is a Candidate and nothing links the two.
|
||||
await f.Sync.UnlinkAsync(f.Server, first, local.Id, f.Ct);
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(f.Server, f.Ct)).Single(c => c.RemoteId == first);
|
||||
Assert.True(await f.Sync.Copies.SetStateAsync(pair.Id, CopyState.KeptApart, CopyState.Candidate, null, f.Ct));
|
||||
// Renamed on the server (the web, another desktop); a new photo here.
|
||||
var server = f.Remote.Sequences[first];
|
||||
server.Title = "Comet NAS";
|
||||
server.SettingsVersion++;
|
||||
server.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
await f.AddLocalAsync(local.Id, photos[2]);
|
||||
|
||||
job = await f.Sync.EnqueueUploadAsync(engine, f.Server, (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
// The other is not joined through the key, linked unasked or overwritten: a new server sequence holds every photo.
|
||||
Assert.Equal("Comet NAS", server.Title);
|
||||
Assert.True(server.Frames.Select(fr => fr.Sha256).ToHashSet().SetEquals([Sha(photos[0]), Sha(photos[1])]));
|
||||
Assert.Equal(CopyState.Candidate, (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.State);
|
||||
Assert.Null((await f.Sync.Links.GetAsync(f.Server, first, f.Ct))!.LocalId);
|
||||
var link = Assert.NotNull(await f.Sync.Links.FindByLocalAsync(f.Server, local.Id, f.Ct));
|
||||
Assert.NotEqual(first, link.RemoteId);
|
||||
Assert.True(f.Remote.Sequences[link.RemoteId].Frames.Select(fr => fr.Sha256).ToHashSet().SetEquals(photos.Select(Sha)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnUploadThatJoinsAServerSequenceItKnowsAlreadyComparesItsDetailsInsteadOfOverwritingThem()
|
||||
{
|
||||
await using var f = Capable(await SyncFixture.CreateAsync(context));
|
||||
var photos = f.NewPhotos(3);
|
||||
var local = await f.LocalAsync("Comet", [photos[0], photos[1]]);
|
||||
var engine = await f.StartEngineAsync();
|
||||
var job = await f.Sync.EnqueueUploadAsync(engine, f.Server, local);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
var first = Assert.NotNull(await f.Sync.Links.FindByLocalAsync(f.Server, local.Id, f.Ct)).RemoteId;
|
||||
// The link and its pair were forgotten (a sweep of 404s: the server served another archive for a while); the
|
||||
// server sequence is listed again, as an observation.
|
||||
var observed = Assert.NotNull(await f.Sync.Links.GetAsync(f.Server, first, f.Ct)) with { LocalId = null };
|
||||
await f.Sync.Links.UpsertAsync(observed, f.Ct);
|
||||
await using (var session = await f.Db.Database.OpenAsync(f.Ct))
|
||||
await session.ExecuteAsync("DELETE FROM found_copies WHERE remote_id = $1", [first], f.Ct);
|
||||
var server = f.Remote.Sequences[first];
|
||||
server.Title = "Comet NAS";
|
||||
server.SettingsVersion++;
|
||||
server.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
await f.AddLocalAsync(local.Id, photos[2]);
|
||||
|
||||
job = await f.Sync.EnqueueUploadAsync(engine, f.Server, (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
// Joined through this sequence's key, not made by this upload: the server's title is not overwritten unseen.
|
||||
Assert.Equal(first, Assert.NotNull(await f.Sync.Links.FindByLocalAsync(f.Server, local.Id, f.Ct)).RemoteId);
|
||||
Assert.True(server.Frames.Select(fr => fr.Sha256).ToHashSet().SetEquals(photos.Select(Sha)));
|
||||
Assert.Equal("Comet NAS", server.Title);
|
||||
Assert.Equal("Comet", (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.Title);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnAutomaticUploadAfterTheServerCopyIsGoneFailsAndCreatesNothing()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user