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:
Claude committed 2026-10-12 16:20:11 +00:00
1 parent 32a0e9bbc1
commit ea6e1a69e0
25 files changed
+1091 -51

No files matched your search

@@ -60,6 +60,32 @@ public sealed class SequenceTests(TestContext context)
await invalid.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_settings");
}
[Test]
public async Task SettingsWrittenAgainstFramesThatChangedAreRefused()
{
await using var server = await TestServer.StartAsync(context);
var (editor, _, _) = await server.UserAsync("alberto", "editor");
var first = await Uploads.UploadAsync(editor, Uploads.Photo(2000, 41), "a.CR3", sessionKey: "k");
using var read = await editor.GetAsync($"/api/v1/sequences/{first.SequenceId}");
var sequence = await read.ReadAsync(ProtocolJson.Default.SequenceDto);
// Another photo arrives after this client read the frames its positions name.
await Uploads.UploadAsync(editor, Uploads.Photo(2000, 42), "b.CR3", sessionKey: "k");
using (var stale = await editor.PatchAsJsonAsync($"/api/v1/sequences/{sequence.Id}",
new UpdateSequenceRequest(null, null, null, null, """{"excludedFrames":[0]}""", sequence.SettingsVersion, ExpectedFramesVersion: sequence.FramesVersion),
ProtocolJson.Default.UpdateSequenceRequest))
{
var error = await stale.ExpectErrorAsync(HttpStatusCode.Conflict, "frames_conflict");
Assert.Equal((sequence.FramesVersion + 1).ToString(System.Globalization.CultureInfo.InvariantCulture), error.Details);
}
using var fresh = await editor.PatchAsJsonAsync($"/api/v1/sequences/{sequence.Id}",
new UpdateSequenceRequest(null, null, null, null, """{"excludedFrames":[1]}""", sequence.SettingsVersion, ExpectedFramesVersion: sequence.FramesVersion + 1),
ProtocolJson.Default.UpdateSequenceRequest);
await fresh.ExpectAsync(HttpStatusCode.OK);
Assert.Equal(sequence.SettingsVersion + 1, (await fresh.ReadAsync(ProtocolJson.Default.SequenceDto)).SettingsVersion);
}
[Test]
public async Task TheManifestCarriesHashesAndAnEtag()
{