fix(editor): move a local editor's positions with frames inserted under it

An editor open on a sequence of this PC while earlier photos arrived (a
sync download, an import, a scan) kept its frames and positions in the old
order, while the index moved the stored positions with their frames. The
next edit of exclusions, the hero or keyframes was merged as the editor's
own value and stored in the old order, so other photos were excluded and
the Library's hero and the project's named different frames.

LocalSequenceSource records the frames version it read the frames at (row
and frames read as one state) and refuses a save under the sequence lease
when the row's frames version moved (FramesChangedException); the index
edit also names that version. EditorSession then reads the sequence again
and moves its project, its basis and every undo and redo step the way the
index moved the stored copy (ProjectSettings.FollowFrames: by frame id when
frames were only inserted, otherwise unchanged; waiting photos placed),
and saves in the new order. A read after a job follows the frames the same
way, and saves wait for a read under way.

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:55 +00:00
1 parent f2ce806d56
commit 31dea66270
9 files changed
+357 -33

No files matched your search

@@ -138,6 +138,63 @@ public sealed class ProjectStoreTests(TestContext context)
}
}
[Test]
public async Task AnEditorOpenWhileEarlierPhotosArriveSavesOnTheFramesTheUserChose()
{
var (db, sequenceId, root) = await ArchiveAsync(10);
await using (db)
{
var options = new ArchiveServiceOptions { Owner = "test", LeaseWait = TimeSpan.FromSeconds(20) };
await using var source = new LocalSequenceSource(db, sequenceId, DecoderFactory.CreateClient(null), null, options);
var content = await source.LoadAsync(context.Cancellation);
var session = new EditorSession(source, content, [], TimeSpan.FromMilliseconds(20));
await using (session)
{
Assert.True(session.SetExcluded([5], true));
Assert.True(session.SetHero(6));
Assert.True(await session.FlushAsync());
// Three photos taken before the others are found in the folder (a sync download, an import or a scan
// inserts them the same way): the index moves the stored positions with their frames.
var sequence = EditorFixture.Sequence(3);
var first = content.Frames[0].CapturedAt!.Value;
for (var i = 0; i < 3; i++)
{
using var image = sequence.Render(i);
var exif = ExifWriter.BuildJpegApp1(sequence.Metadata[i] with { CapturedAt = first.AddMinutes(i - 3) });
File.WriteAllBytes(Path.Combine(root, "Synthetic", $"EARLY_{i + 1}.JPG"),
JpegEncoder.Encode(image, new JpegEncodeOptions { Quality = 90, App1Segments = [exif[4..]] }));
}
var archive = (await db.Archives.GetAsync(content.Sequence.ArchiveId, context.Cancellation))!;
await new ArchiveService(db, options).Indexer.ScanAsync(archive, ScanMode.Full, null, _ => ValueTask.CompletedTask, context.Cancellation);
var moved = ProjectSettings.FromJson((await db.Sequences.GetAsync(sequenceId))!.SettingsJson!);
Assert.SequenceEqual([8], moved.ExcludedFrames);
Assert.Equal(9, moved.HeroFrame);
// The editor still shows the ten frames it read; the user excludes the eighth of them.
Assert.Equal(10, session.Content.Count);
Assert.True(session.SetExcluded([7], true));
Assert.True(await session.FlushAsync());
Assert.Equal(13, session.Content.Count, "the frames were read again before the save");
Assert.SequenceEqual([8, 10], session.Project.ExcludedFrames);
Assert.Equal(9, session.Project.HeroFrame);
var row = (await db.Sequences.GetAsync(sequenceId))!;
var stored = ProjectSettings.FromJson(row.SettingsJson!);
var frames = session.Content.Frames;
Assert.SequenceEqual([content.Frames[5].Id, content.Frames[7].Id], stored.ExcludedFrames.Select(i => frames[i].Id), "the photos the user chose");
Assert.Equal(content.Frames[6].Id, frames[stored.HeroFrame!.Value].Id);
Assert.Equal(content.Frames[6].Id, row.HeroFrameId);
Assert.Equal(row.SettingsJson, File.ReadAllText(Path.Combine(root, "Synthetic", ".titano", "project.json")));
// Undo takes back the user's last step on the new frames too.
Assert.True(session.Undo());
Assert.True(await session.FlushAsync());
Assert.SequenceEqual([8], ProjectSettings.FromJson((await db.Sequences.GetAsync(sequenceId))!.SettingsJson!).ExcludedFrames);
}
}
}
[Test]
public async Task ASaveThatDoesNotReachTheIndexThrows()
{