fix(copies): close the ninth verification round of owner review 6

- A merge leaves each second version out of Main as it files it (Copy
  stage keep-both and SameUnhashed versions, Verify stage versions), so a
  merge abandoned before its Details stage (details changed meanwhile, a
  stale stage, a cancel) no longer leaves both versions in Main for good,
  which a new plan could not undo (owner Q3).
- A merge plan whose kept sequence has tombstones hashes the other's
  unhashed frames matched by size and time, so content the kept sequence
  deleted is listed as a last copy; a verify that still finds such content
  drops the journal and fails as a stale plan instead of failing on every
  retry.
- Download originals uses a key of the job only when the holder of the
  server sequence's key is kept apart from it or linked elsewhere: a link
  a 404 forgot (pair Candidate) refills and re-links the local copy
  instead of duplicating every photo into a new sequence.
- A 404 for a server sequence no local copy is linked to deletes its
  Candidate and Kept apart pairs, so Upload all local sends the local
  sequence again instead of skipping the only copy as a suspected one
  (owner Q8).

Refs #73

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-18 12:21:57 +01:00
1 parent aad8ae46dd
commit c1c02d8ef7
10 files changed
+286 -16

No files matched your search

@@ -263,6 +263,35 @@ public sealed class SyncTransferCopyTests(TestContext context)
Assert.True((await LocalHashesAsync(f, copy)).SetEquals(photos.Select(Sha)));
}
[Test]
public async Task DownloadingAgainAServerSequenceWhoseLinkA404ForgotRefillsAndLinksItsOwnLocalCopy()
{
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);
// A refresh's 404 forgot the link (the archive was briefly offline); listed again, the pair is asked about again.
await f.Sync.Links.DeleteAsync(f.Server, remote.Id, 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, pair.State, CopyState.Candidate, null, f.Ct));
// Download originals of the server-only sequence: it goes back into its own local copy, linked again.
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);
Assert.Equal(local, Assert.NotNull(await f.Sync.Links.GetAsync(f.Server, remote.Id, f.Ct)).LocalId);
Assert.Count(3, await f.Db.Frames.ListBySequenceAsync(local, cancellationToken: f.Ct));
Assert.True((await LocalHashesAsync(f, local)).SetEquals(photos.Select(Sha)));
var keys = await f.Db.Sequences.ListSessionKeysAsync(f.Archive.Archive.Id, SyncService.SessionKey(remote.Id) + "%", f.Ct);
Assert.True(keys.All(k => k.SequenceId == local), "no second local sequence holds a key of the server sequence");
Assert.Equal(1, (await f.Db.Sequences.ListAsync(new SequenceQuery(), f.Ct)).Items.Count);
}
[Test]
public async Task AnAutomaticUploadAfterTheServerCopyIsGoneFailsAndCreatesNothing()
{