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:
Alby96andClaude Opus 5.5 committed 2026-11-18 13:17:23 +01:00
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]