fix(sync): keep the copies of a photo apart when positions cross copies

A server folder adopted with the same photo twice ('IMG_0001.JPG' and
'IMG_0001 (1).JPG') holds two frames where the PC keeps one. Translation
by photo sent every position of that photo to its first copy, so the
server's exclusion of the duplicate excluded the PC's only copy, a push
gave the server back one exclusion instead of two, and keyframes of both
copies piled on one frame.

FramePhotos now lists every frame holding a photo and tells them apart by
their order (Occurrence). A position on the n-th copy goes to the n-th
copy of the receiving copy, or waits as a pending frame with its
occurrence when that copy holds fewer; occurrence 0 is not written, so
older projects read the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 19:13:38 +00:00
1 parent aa36768860
commit f2ce806d56
3 files changed
+128 -24

No files matched your search

@@ -283,6 +283,69 @@ public sealed class ProjectSettingsTests
Assert.Null(cleared.PendingFrames);
}
[Test]
public void APhotoHeldTwiceKeepsEachCopysPositions()
{
// The server adopted a folder holding photo 1 twice ('IMG_0001.JPG', 'IMG_0001 (1).JPG'); this PC keeps it once.
var photos = Enumerable.Range(0, 3).Select(Photo).ToList();
var server = Frames([photos[0], photos[1], photos[1], photos[2]]);
var here = Frames(photos);
var project = new ProjectSettings
{
ExcludedFrames = [2],
HeroFrame = 2,
Camera = new CameraSettings { Keyframes = [new CameraKey(1, 0.1, 0.5, 1, 0), new CameraKey(2, 0.2, 0.5, 1, 0)] },
};
// The second copy, which the deep analysis flags as a duplicate, is excluded there: this PC still renders its only copy.
var taken = ProjectSettings.FromJson(Assert.NotNull(ProjectSettings.TranslateFramePositions(project.ToJson(), server, here)));
Assert.Empty(taken.ExcludedFrames);
Assert.Null(taken.HeroFrame);
Assert.SequenceEqual([1], taken.Camera.Keyframes.Select(k => k.Frame));
Assert.Equal(0.1, taken.Camera.Keyframes[0].CenterX);
var waiting = Assert.NotNull(taken.PendingFrames);
Assert.Count(1, waiting);
Assert.True(waiting[0] is { Excluded: true, Hero: true, Occurrence: 1 } && waiting[0].Sha256 == photos[1].Sha256);
Assert.Count(1, waiting[0].Keyframes);
Assert.Equal(0.2, waiting[0].Keyframes[0].CenterX);
Assert.Contains("\"occurrence\": 1", taken.ToJson());
// Sent back after an edit of something else, every position lands on the copy it named.
var edited = taken with { Exposure = new ExposureSettings { ExposureOffsetEv = 0.3 } };
var back = ProjectSettings.FromJson(Assert.NotNull(ProjectSettings.TranslateFramePositions(edited.ToJson(), here, server)));
Assert.SequenceEqual([2], back.ExcludedFrames);
Assert.Equal(2, back.HeroFrame);
Assert.SequenceEqual([1, 2], back.Camera.Keyframes.Select(k => k.Frame));
Assert.SequenceEqual([0.1, 0.2], back.Camera.Keyframes.Select(k => k.CenterX));
Assert.Null(back.PendingFrames);
// Both copies excluded there: this PC excludes its copy, and the server gets both back.
var both = ProjectSettings.FromJson(Assert.NotNull(ProjectSettings.TranslateFramePositions(new ProjectSettings { ExcludedFrames = [1, 2] }.ToJson(), server, here)));
Assert.SequenceEqual([1], both.ExcludedFrames);
var excluded = Assert.NotNull(both.PendingFrames);
Assert.Count(1, excluded);
Assert.True(excluded[0] is { Excluded: true, Hero: false, Occurrence: 1 });
var returned = ProjectSettings.FromJson(Assert.NotNull(ProjectSettings.TranslateFramePositions(both.ToJson(), here, server)));
Assert.SequenceEqual([1, 2], returned.ExcludedFrames);
Assert.Null(returned.PendingFrames);
}
[Test]
public void TheCopiesOfAPhotoAreToldApartByTheirOrder()
{
var time = new DateTime(2026, 9, 28, 18, 0, 0);
var hashed = new FramePhoto(new string('a', 64), 100, time);
var other = new FramePhoto(new string('b', 64), 200, time);
// The copy at 3 has not been hashed yet: it is the same photo by size and capture time.
var frames = Frames([other, hashed, other, new FramePhoto(null, 100, time), hashed]);
Assert.SequenceEqual([1, 3, 4], new[] { 0, 1, 2 }.Select(n => frames.IndexOf(hashed, n)).OfType<int>());
Assert.Null(frames.IndexOf(hashed, 3));
Assert.SequenceEqual([0, 0, 1, 1, 2], Enumerable.Range(0, 5).Select(frames.Occurrence));
Assert.Equal(0, frames.Occurrence(9));
Assert.Equal(2, frames.IndexOf(new FramePhoto(new string('B', 64), 0, null), 1));
}
[Test]
public void AProjectNamingNoFrameCrossesAsItIs()
{