fix(archive): settle conversions by content and keep their aliases through trash, undo, sync and ingest

Owner review 2, phase 4b, fix round 1 (trash, undo, recovery, sync and ingest).

- Replace journal: records a phase (moving, written, undoing) and the name each swapped
  frame is filed under. Recovery decides "sidecar written" by what the sidecar lists, not
  by the frames version any writer moves; a failed rollback stays undoing and its failure
  now stops the writer (as a photo deletion's recovery does). The ingest settles restores
  and replacements first, so an upload can no longer complete a swap that never happened.
- Emptying a Replaced entry re-verifies each replacement where it is now: in the sequence
  through later conversions (a second conversion no longer strands the first originals),
  or, when the conversion was deleted, its copy in the trash. The dry run marks such
  entries "conversion deleted" (fingerprinted, shown on the desktop and the panel), and
  the confirmed emptying may then erase them instead of keeping them forever.
- Undo of a conversion takes exactly the entries its job made (the job id is recorded on
  the entry), never entries found by time window.
- Project positions translated by photo use the sidecar's photo of every frame still
  there, so positions on a converted frame stay put when another frame went meanwhile.
- Sync aliases are equivalence classes: an original converted on both sides is one photo;
  link-by-content, proxy counting and proxy upload follow aliases; a download into a
  frame missing here swaps the other encoding into that frame instead of adding a frame.
- The ingest answers a converted photo's original (a card or folder imported again, a
  download) as a duplicate of its conversion and keeps the alias tombstone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 3341a2f845753fc4c5bcba51a3b645f126c95eaf)
This commit is contained in:
Alby96 committed 2026-10-27 22:13:36 +01:00
1 parent 67a6d51cbe
commit d0bbd77c92
31 files changed
+1326 -211

No files matched your search

@@ -84,7 +84,8 @@ public sealed class SyncRulesTests
// A photo replaced by a converted file on either side is the same photo as its replacement, and so is a chain of them.
var replaced = new SyncTombstones([], [new RemovedPhotoDto("aa", "a2", "replaced", at), new RemovedPhotoDto("a2", "a3", "replaced", at)]);
Assert.Equal("a3", replaced.Canonical("AA"));
Assert.Equal(replaced.Canonical("a3"), replaced.Canonical("AA"));
Assert.Equal(replaced.Canonical("a3"), replaced.Canonical("a2"));
Assert.Equal((0, 0), SyncRules.CompareOriginals([Photo("aa"), Photo("bb")], [Photo("a3"), Photo("bb")], replaced));
Assert.False(replaced.DeletedRemotely("aa"), "a replaced photo is there as its replacement");
var replacedHere = new SyncTombstones([new FrameRemoval(localId, "bb", "b2", RemovalReason.Replaced, at)], null);
@@ -97,6 +98,43 @@ public sealed class SyncRulesTests
new FrameRemoval(localId, "bb", "b2", RemovalReason.Replaced, at)]).Select(r => r.Reason));
}
[Test]
public void APhotoEachSideConvertedOnItsOwnIsStillOnePhoto()
{
static FramePhoto Photo(string sha) => new(sha, 100, null);
var at = new DateTimeOffset(2026, 10, 27, 10, 0, 0, TimeSpan.Zero);
var localId = Guid.CreateVersion7();
// This PC converted "oo" to "aa", the server converted its copy to "bb" (another decoder, other bytes).
var both = new SyncTombstones([new FrameRemoval(localId, "OO", "aa", RemovalReason.Replaced, at)], [new RemovedPhotoDto("oo", "BB", "replaced", at)]);
Assert.Equal(both.Canonical("oo"), both.Canonical("aa"));
Assert.Equal(both.Canonical("oo"), both.Canonical("bb"));
Assert.Equal((0, 0), SyncRules.CompareOriginals([Photo("aa"), Photo("cc")], [Photo("bb"), Photo("cc")], both));
// The same whichever side's links come first, and with an undo (a link back) in the chain.
var reversed = new SyncTombstones([new FrameRemoval(localId, "bb", "oo", RemovalReason.Replaced, at)], [new RemovedPhotoDto("aa", "oo", "replaced", at)]);
Assert.Equal(both.Canonical("aa"), reversed.Canonical("bb"));
Assert.Equal("cc", both.Canonical("CC"));
// A deletion covers every encoding of the photo: the server deleted its conversion, so this PC's is not sent.
var deleted = new SyncTombstones([new FrameRemoval(localId, "oo", "aa", RemovalReason.Replaced, at)],
[new RemovedPhotoDto("oo", "bb", "replaced", at), new RemovedPhotoDto("bb", null, "deleted", at)]);
Assert.True(deleted.DeletedRemotely("aa"));
Assert.False(deleted.DeletedLocally("bb"));
Assert.False(both.DeletedRemotely("aa"));
}
[Test]
public void AProxyIsMadeFromThePhotoThisPcConverted()
{
var heif = new ImageDecoder([new NativeHeif()]);
var at = new DateTimeOffset(2026, 10, 27, 10, 0, 0, TimeSpan.Zero);
// The server holds the HEIC original "oo" and cannot decode it; this PC converted its copy to a JPEG ("dd").
List<Frame> local = [Original("dd", 100, ImageFileFormat.Jpeg)];
var manifest = new SequenceManifest(Guid.CreateVersion7(), 1, 1, null, [], [Wanted("oo", 500, "IMG_0001.HEIC")], [], new ProxySpec(1920, 90));
var tombstones = new SyncTombstones([new FrameRemoval(Local.Id, "oo", "dd", RemovalReason.Replaced, at)], null);
Assert.Equal(1, SyncRules.ProxiesToSend(manifest, local, heif, null, tombstones));
Assert.Equal(0, SyncRules.ProxiesToSend(manifest, local, heif));
}
[Test]
public void ATombstoneBesideAPhotoItsSideStillHoldsHidesNothing()
{