fix(projects): one photo merges as one, newer settings are never merged
A workspace copied before the home hashed or converted a photo named it differently from the versions the home made since, so a pull merged the same photo as two: frame edits were silently undone and Keep mine placed the library's value. Before replaying, the workspace media now learn the home's hashes (same frame id, size and capture time) and conversion aliases, so every side names each photo alike. Rebind also gives a renamed entry the occurrence a placement looks for, so positions on burst photos keep applying once hashed, and folds entries of one photo (in Rebind and in the merge's keyed form) instead of keeping one. Settings of a newer Chronos are no longer merged member by member with this one's: ProjectMerge refuses when both sides changed. A workspace pull keeps its local versions and working state untouched and records a conflict of format that only Save both settles (into a new project of this format); with nothing local it takes the newer head read-only. Main's catch-up leaves a newer head and settings written meanwhile as they are. When Main's catch-up merge overrides values another writer stored, that writer's settings are kept as an External version before the Merge one, so nothing is lost from the history. Unknown members inside Auto values, camera keyframes and curve points, and on pending entries once placed, are kept like ProjectSettings' Extra. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
50e28fd63d
commit
eac4a36a7b
12 files changed
+905
-38
No files matched your search
@@ -135,6 +135,126 @@ public sealed class ProjectContentTests
|
||||
Assert.Equal(newer, ProjectContent.Rebind(newer, now));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void APhotoOfABurstToldApartByItsOrderKeepsItsPositionOnceHashed()
|
||||
{
|
||||
// A RAW burst of one size without sub-second times: three photos alike but for their SHA-256, told apart by their
|
||||
// order while not hashed (frames 1 to 3); and a photo held twice, two copies of one file (frames 4 and 5).
|
||||
FramePhoto Burst(int n, bool hashed) => new(hashed ? (500 + n).ToString("x64", System.Globalization.CultureInfo.InvariantCulture) : null, 25_000_000, Start);
|
||||
FramePhotos Copy(bool hashed) => new([(0, Photo(1)), (1, Burst(0, hashed)), (2, Burst(1, hashed)), (3, Burst(2, hashed)), (4, Photo(2)), (5, Photo(2))]);
|
||||
var (before, after) = (Copy(hashed: false), Copy(hashed: true));
|
||||
var choices = new ProjectSettings { ExcludedFrames = [3, 5], HeroFrame = 2, Camera = new CameraSettings { Keyframes = [new CameraKey(1, 0.3, 0.5, 1.2, 0)] } };
|
||||
var saved = ProjectContent.ToPortable(choices, before);
|
||||
Assert.SequenceEqual([0, 1, 1, 2], ProjectSettings.FromJson(saved).PendingFrames!.Select(p => p.Occurrence).Order());
|
||||
|
||||
// Hashed since: each photo of the burst is the only one of its SHA-256, the copy of the photo held twice still the second.
|
||||
var rebound = ProjectContent.Rebind(saved, after);
|
||||
var named = ProjectSettings.FromJson(rebound).PendingFrames!;
|
||||
Assert.True(named.All(p => p.Sha256 is not null));
|
||||
Assert.SequenceEqual([0, 0, 0, 1], named.Select(p => p.Occurrence).Order());
|
||||
Assert.Equal(ProjectContent.ToPortable(choices, after), rebound);
|
||||
Assert.True(ProjectContent.SameChoices(saved, ProjectContent.ToPortable(choices, after), after));
|
||||
var placed = ProjectSettings.FromJson(ProjectContent.Place(rebound, after));
|
||||
Assert.SequenceEqual([3, 5], placed.ExcludedFrames);
|
||||
Assert.Equal((int?)2, placed.HeroFrame);
|
||||
Assert.Equal(1, placed.Camera.Keyframes.Single().Frame);
|
||||
Assert.Null(placed.PendingFrames);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EntriesOfOnePhotoSavedUnderTwoNamesBecomeOneWithThePositionsOfBoth()
|
||||
{
|
||||
// Photo 2 was converted into 20 (owner review 2, R7). A version holds an exclusion parked on the old encoding, and a hero, a
|
||||
// keyframe and a newer Chronos's rating parked on the new one: each copy named the photo as it held it.
|
||||
var rating = JsonSerializer.SerializeToElement(4);
|
||||
var split = new ProjectSettings
|
||||
{
|
||||
PendingFrames =
|
||||
[
|
||||
new PendingFrame { Sha256 = Photo(2).Sha256, Size = Photo(2).Size, CapturedAt = Photo(2).CapturedAt, Excluded = true },
|
||||
new PendingFrame
|
||||
{
|
||||
Sha256 = Photo(20).Sha256, Size = Photo(20).Size, CapturedAt = Photo(2).CapturedAt, Hero = true, Keyframes = [new CameraKey(0, 0.8, 0.5, 1.2, 0)],
|
||||
Extra = new Dictionary<string, JsonElement> { ["rating"] = rating },
|
||||
},
|
||||
],
|
||||
};
|
||||
var text = ProjectContent.Canonical(split.ToJson());
|
||||
var now = new FramePhotos([(0, Photo(1)), (1, Photo(20)), (2, Photo(3))], [new PhotoAlias(Photo(2).Sha256!, Photo(20).Sha256!)]);
|
||||
|
||||
var rebound = ProjectContent.Rebind(text, now);
|
||||
var entry = Assert.NotNull(ProjectSettings.FromJson(rebound).PendingFrames).Single();
|
||||
Assert.Equal(Photo(20).Sha256, entry.Sha256);
|
||||
Assert.True(entry.Excluded && entry.Hero);
|
||||
Assert.Equal(0.8, entry.Keyframes.Single().CenterX);
|
||||
Assert.Equal(4, entry.Extra!["rating"].GetInt32());
|
||||
// The same choices as the version made where the frames hold the new encoding.
|
||||
Assert.True(ProjectContent.SameChoices(text, rebound, now));
|
||||
var placed = ProjectSettings.FromJson(ProjectContent.Place(rebound, now));
|
||||
Assert.SequenceEqual([1], placed.ExcludedFrames);
|
||||
Assert.Equal((int?)1, placed.HeroFrame);
|
||||
Assert.Equal(1, placed.Camera.Keyframes.Single().Frame);
|
||||
// Two entries already named alike are one too.
|
||||
var twice = ProjectContent.Canonical((split with { PendingFrames = [.. split.PendingFrames!.Select(p => p with { Sha256 = Photo(20).Sha256 })] }).ToJson());
|
||||
Assert.Equal(rebound, ProjectContent.Rebind(twice, now));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MembersOfANewerChronosSurviveInsideParametersKeyframesAndCurvePoints()
|
||||
{
|
||||
var waiting = Photo(9).Sha256;
|
||||
var json = $$"""
|
||||
{
|
||||
"version": 1,
|
||||
"timing": { "remapCurve": [ { "x": 0, "y": 0, "handle": 0.25 }, { "x": 1, "y": 1 } ] },
|
||||
"exposure": { "deflicker": { "isAuto": true, "hasAdvice": true, "autoValue": true, "confidence": 0.8 } },
|
||||
"camera": { "keyframes": [ { "frame": 1, "centerX": 0.4, "centerY": 0.5, "zoom": 1.2, "rotation": 0, "tilt": 3 } ] },
|
||||
"pendingFrames": [ { "sha256": "{{waiting}}", "size": 1009, "keyframes": [ { "frame": 0, "centerX": 0.2, "centerY": 0.5, "zoom": 1, "rotation": 0, "tilt": 5 } ] } ]
|
||||
}
|
||||
""";
|
||||
var settings = ProjectSettings.FromJson(json);
|
||||
Assert.Equal(0.8, settings.Exposure.Deflicker.Extra!["confidence"].GetDouble());
|
||||
Assert.Equal(3, settings.Camera.Keyframes.Single().Extra!["tilt"].GetInt32());
|
||||
Assert.Equal(0.25, settings.Timing.RemapCurve[0].Extra!["handle"].GetDouble());
|
||||
// An edit of the parameter or the keyframe keeps them too.
|
||||
Assert.Equal(0.8, settings.Exposure.Deflicker.WithManual(false).Extra!["confidence"].GetDouble());
|
||||
Assert.Equal(3, (settings.Camera.Keyframes[0] with { Zoom = 2 }).Extra!["tilt"].GetInt32());
|
||||
|
||||
var frames = Frames(Photo(1), Photo(2), Photo(3));
|
||||
var portable = ProjectContent.ToPortable(json, frames);
|
||||
var placed = ProjectContent.Place(portable, frames);
|
||||
foreach (var text in new[] { settings.ToJson(), portable, placed, ProjectContent.Canonical(portable), ProjectContent.Rebind(portable, frames) })
|
||||
{
|
||||
var node = JsonNode.Parse(text)!;
|
||||
Assert.Equal(0.8, node["exposure"]!["deflicker"]!["confidence"]!.GetValue<double>());
|
||||
Assert.Equal(0.25, node["timing"]!["remapCurve"]![0]!["handle"]!.GetValue<double>());
|
||||
var waits = node["pendingFrames"]!.AsArray().Single(p => p!["sha256"]!.GetValue<string>() == waiting)!;
|
||||
Assert.Equal(5, waits["keyframes"]![0]!["tilt"]!.GetValue<int>());
|
||||
}
|
||||
// The keyframe's member goes where the keyframe goes: parked with its photo, then placed again.
|
||||
var parked = JsonNode.Parse(portable)!["pendingFrames"]!.AsArray().Single(p => p!["sha256"]!.GetValue<string>() == Photo(2).Sha256)!;
|
||||
Assert.Equal(3, parked["keyframes"]![0]!["tilt"]!.GetValue<int>());
|
||||
Assert.Equal(3, JsonNode.Parse(placed)!["camera"]!["keyframes"]![0]!["tilt"]!.GetValue<int>());
|
||||
Assert.Equal(portable, ProjectContent.ToPortable(placed, frames));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AWaitingPhotoKeepsANewerChronosMembersOnceItsPositionsArePlaced()
|
||||
{
|
||||
var frames = Frames(Photo(1), Photo(2), Photo(3));
|
||||
var portable = ProjectContent.Canonical($$"""{ "pendingFrames": [ { "sha256": "{{Photo(2).Sha256}}", "size": {{Photo(2).Size}}, "excluded": true, "rating": 5 } ] }""");
|
||||
|
||||
var placed = ProjectSettings.FromJson(ProjectContent.Place(portable, frames));
|
||||
Assert.SequenceEqual([1], placed.ExcludedFrames);
|
||||
var kept = Assert.NotNull(placed.PendingFrames).Single();
|
||||
Assert.False(kept.Excluded || kept.Hero || kept.Keyframes.Count > 0);
|
||||
Assert.Equal(5, kept.Extra!["rating"].GetInt32());
|
||||
// Parked again, the rating is still the photo's: the same text as before.
|
||||
Assert.Equal(portable, ProjectContent.ToPortable(placed, frames));
|
||||
// Nothing more to place: the settings stay as they are.
|
||||
Assert.Equal(placed.ToJson(), ProjectContent.Place(placed.ToJson(), frames));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheSameSettingsGiveTheSameTextAndHashWhateverTheFrames()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user