fix(sync): keep project positions on their photos when settings cross copies
Settings synced between a PC and its server sequence were stored as they
came, in the other copy's frame order. When the inserted photos arrived
later (a download, an upload), the index moved those already-correct
positions a second time, so exclusions, the hero and camera keyframes
landed on other photos (V-21, CD-2).
- Settings are translated by photo (SHA-256, else size and capture time)
to the frames of the copy they go to: the server's before they are
compared or applied here, this PC's to the server's frames as its
manifest lists them before a push (SyncPositions).
- A position on a photo the receiving copy lacks waits in project.json as
a pending frame and takes its place when the photo arrives, on an
insertion or an append in step with the index; the Library's hero
frame follows. A hero chosen meanwhile wins, and advice does not fill
a hero while one waits. Old projects without the member are unchanged.
- Pushes send expectedFramesVersion; PATCH /api/v1/sequences/{id} answers
409 frames_conflict when the frames changed since, and the next
comparison translates again.
- A pulled payload equal to the local copy is settled without the
archive: an offline or read-only archive no longer fails the
comparison (V-10).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
25 files changed
+1091
-51
No files matched your search
@@ -3,6 +3,7 @@ using Titano.Core.Imaging;
|
||||
using Titano.Core.Imaging.Decoders;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Core.Project;
|
||||
using Titano.Core.Render;
|
||||
using Titano.Data.Sync;
|
||||
using Titano.Testing;
|
||||
@@ -264,6 +265,61 @@ public sealed class SyncTransferTests(TestContext context)
|
||||
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync("Harbour")).Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PositionsTakenFromTheServerStayOnTheirPhotosWhenTheOriginalsArrive()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(6);
|
||||
var local = await f.LocalAsync("Harbour", photos[1..5]);
|
||||
var remote = f.Remote.Add("Harbour", photos[1..5]);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
// Another PC sends the server an earlier and a later photo; then an editor there excludes two photos, picks the
|
||||
// hero and keys the camera, by the server's frames.
|
||||
remote.InsertFrame(0, photos[0]);
|
||||
remote.AddFrame(photos[5]);
|
||||
f.Remote.EditSettings(remote.Id, new ProjectSettings
|
||||
{
|
||||
ExcludedFrames = [0, 3],
|
||||
HeroFrame = 5,
|
||||
Camera = new CameraSettings { Keyframes = [new CameraKey(2, 0.4, 0.5, 1.5, 0)] },
|
||||
}.ToJson());
|
||||
|
||||
await f.RefreshAsync();
|
||||
var taken = await NamedAsync(f, local.Id);
|
||||
Assert.SequenceEqual([Sha(photos[3])], taken.Excluded);
|
||||
Assert.Null(taken.Hero);
|
||||
Assert.SequenceEqual([Sha(photos[2])], taken.Keyframes);
|
||||
Assert.True(taken.Pending.ToHashSet().SetEquals([Sha(photos[0]), Sha(photos[5])]), "the photos this copy lacks wait for them");
|
||||
var engine = await f.StartEngineAsync();
|
||||
|
||||
var job = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Harbour", SyncDownloadMode.Originals, null);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
// The same photos as on the server, and nothing waits any more.
|
||||
var arrived = await NamedAsync(f, local.Id);
|
||||
Assert.SequenceEqual([Sha(photos[0]), Sha(photos[3])], arrived.Excluded);
|
||||
Assert.Equal(Sha(photos[5]), arrived.Hero);
|
||||
Assert.SequenceEqual([Sha(photos[2])], arrived.Keyframes);
|
||||
Assert.Empty(arrived.Pending);
|
||||
var row = (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!;
|
||||
var frames = await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct);
|
||||
Assert.Equal(Sha(photos[5]), frames.Single(fr => fr.Id == row.HeroFrameId).Sha256);
|
||||
Assert.True(SyncRules.SameSettings(row.SettingsJson, await File.ReadAllTextAsync(f.Archive.Paths.Sequence(row.Folder).ProjectPath, f.Ct)),
|
||||
"project.json mirrors the index");
|
||||
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync("Harbour")).Status);
|
||||
|
||||
// An edit here later sends the server the same photos, by its frames.
|
||||
var edited = ProjectSettings.FromJson(row.SettingsJson!) with { Exposure = new ExposureSettings { DeflickerWindow = new Auto<int>().WithManual(41) } };
|
||||
await f.EditLocalSettingsAsync(local.Id, edited.ToJson());
|
||||
await f.RefreshAsync();
|
||||
var server = ProjectSettings.FromJson(remote.SettingsJson!);
|
||||
Assert.Equal(41, server.Exposure.DeflickerWindow.Manual);
|
||||
Assert.SequenceEqual([Sha(photos[0]), Sha(photos[3])], server.ExcludedFrames.Select(i => remote.Frames[i].Sha256));
|
||||
Assert.Equal(Sha(photos[5]), remote.Frames[server.HeroFrame!.Value].Sha256);
|
||||
Assert.SequenceEqual([Sha(photos[2])], server.Camera.Keyframes.Select(k => remote.Frames[k.Frame].Sha256));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheServersRendersAreFetchedIntoTheLocalExports()
|
||||
{
|
||||
@@ -407,4 +463,13 @@ public sealed class SyncTransferTests(TestContext context)
|
||||
}
|
||||
|
||||
private static string Sha(byte[] bytes) => Convert.ToHexStringLower(System.Security.Cryptography.SHA256.HashData(bytes));
|
||||
|
||||
/// <summary>The photos (SHA-256) the local copy's project excludes, shows as hero, keys the camera on, and waits for.</summary>
|
||||
private static async Task<(string[] Excluded, string? Hero, string[] Keyframes, string[] Pending)> NamedAsync(SyncFixture f, Guid localId)
|
||||
{
|
||||
var project = ProjectSettings.FromJson((await f.Db.Sequences.GetAsync(localId, f.Ct))!.SettingsJson!);
|
||||
var frames = await f.Db.Frames.ListBySequenceAsync(localId, cancellationToken: f.Ct);
|
||||
return ([.. project.ExcludedFrames.Select(i => frames[i].Sha256!)], project.HeroFrame is { } hero ? frames[hero].Sha256 : null,
|
||||
[.. project.Camera.Keyframes.Select(k => frames[k.Frame].Sha256!)], [.. (project.PendingFrames ?? []).Select(p => p.Sha256!)]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user