refactor(editor): the open sequence's jobs in their own type; restore undo as an object

WIP of the interrupted fix stage.

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-06 07:49:27 +00:00
1 parent 757695f037
commit 31c1a2d9c6
9 files changed
+356 -42

No files matched your search

@@ -271,6 +271,130 @@ public sealed class RemoteSequenceSourceTests(TestContext context)
}
}
[Test]
public async Task ProxiesOfOtherFramesAreNotEdited()
{
var (source, api, remote) = Open();
await using (source)
{
// A frame added on the server since the proxies were fetched: positions in the project would point elsewhere.
api.Frames = [.. remote.Frames.Select(f => f.Id), Guid.CreateVersion7()];
await Assert.ThrowsAsync<ProxiesOutdatedException>(() => source.LoadAsync(context.Cancellation));
Assert.True(source.IsOutdated);
Assert.True(source.IsReadOnly);
}
(source, api, remote) = Open();
await using (source)
{
// The same frames in another order are other frames too.
api.Frames = [.. remote.Frames.Select(f => f.Id).Reverse()];
await Assert.ThrowsAsync<ProxiesOutdatedException>(() => source.LoadAsync(context.Cancellation));
}
}
[Test]
public async Task FramesChangedOnTheServerWhileOpenStopSavesAndRenders()
{
var (source, api, remote) = Open();
await using (source)
{
var content = await source.LoadAsync(context.Cancellation);
var changes = 0;
source.ReadOnlyChanged += () => Interlocked.Increment(ref changes);
// A change that keeps the frames (settings, a new version number) changes nothing.
api.FramesVersion = 2;
api.Publish(new SequenceChangedEvent(remote.Sequence.Id, "settings", 2, api.SettingsVersion));
await Task.Delay(200);
Assert.False(source.IsOutdated, "the same frames");
api.Frames = [.. remote.Frames.Skip(1).Select(f => f.Id)];
api.FramesVersion = 3;
api.Publish(new SequenceChangedEvent(Guid.CreateVersion7(), "frames", 7, 1));
api.Publish(new SequenceChangedEvent(remote.Sequence.Id, "frames", 3, api.SettingsVersion));
await WaitAsync(() => source.IsOutdated);
Assert.True(source.IsReadOnly);
Assert.Equal(1, Volatile.Read(ref changes));
await Assert.ThrowsAsync<ProxiesOutdatedException>(() =>
source.SaveProjectAsync(content.Project with { HeroFrame = 2 }, content.Project, context.Cancellation));
await Assert.ThrowsAsync<ProxiesOutdatedException>(() =>
source.SubmitAsync(ProcessingJobs.Render(remote.Sequence, new ExportSettings(), 1920, 1080), context.Cancellation));
await source.SubmitAsync(ProcessingJobs.DeepAnalysis([remote.Sequence.Id]), context.Cancellation);
Assert.Empty(api.Edits);
Assert.SequenceEqual(["deep-analyse"], api.Posted.Select(p => p.Kind), "an analysis reads the server's own frames");
}
}
[Test]
public async Task AConflictFoundOnOtherFramesIsNotMergedOntoThem()
{
var (source, api, remote) = Open();
await using (source)
{
var content = await source.LoadAsync(context.Cancellation);
api.EditsBefore.Enqueue(json =>
{
api.Frames = [.. remote.Frames.Select(f => f.Id), Guid.CreateVersion7()];
return json ?? "{}";
});
await Assert.ThrowsAsync<ProxiesOutdatedException>(() =>
source.SaveProjectAsync(content.Project with { ExcludedFrames = [1] }, content.Project, context.Cancellation));
Assert.SequenceEqual([false], api.Edits.Select(e => e.Accepted));
Assert.True(source.IsOutdated);
}
}
[Test]
public async Task QueuedRendersKeepTheirPriorityAndJobsCanBeCancelledAndRetried()
{
var (source, api, remote) = Open();
await using (source)
{
await source.LoadAsync(context.Cancellation);
var seen = new List<Job>();
source.JobChanged += job =>
{
lock (seen) seen.Add(job);
};
var render = ProcessingJobs.Render(remote.Sequence, new ExportSettings(), 1920, 1080);
var now = await source.SubmitAsync(render, context.Cancellation);
var later = await source.SubmitAsync(render with { Priority = JobPriority.Normal }, context.Cancellation);
Assert.SequenceEqual([(later, "normal")], api.Priorities, "Render now stays at the user's priority; Add to queue waits behind it");
await source.CancelJobAsync(now, context.Cancellation);
Assert.Equal(JobState.Cancelled, Last(seen).State);
Assert.Equal("cancelled", api.Jobs[now].State);
await source.RetryJobAsync(now, context.Cancellation);
Assert.Equal((now, JobState.Queued), (Last(seen).Id, Last(seen).State));
}
}
[Test]
public async Task TheEventListenerOutlivesAFailureAndClosingReleasesTheConnection()
{
var (source, api, remote) = Open();
await using (source)
{
await source.LoadAsync(context.Cancellation);
var seen = new List<Job>();
source.JobChanged += job =>
{
lock (seen) seen.Add(job);
};
var id = await source.SubmitAsync(ProcessingJobs.DeepAnalysis([remote.Sequence.Id]), context.Cancellation);
api.Jobs[id] = api.Job(id, "deep-analyse", "running");
// A failure the listener has no special case for (a body that is not a job) does not end it.
api.FailNextJobRead = new ArgumentNullException("dto");
api.Publish(new JobStateEvent(id, "running", null));
api.Publish(new JobStateEvent(id, "running", null));
await WaitAsync(() => Last(seen).State == JobState.Running);
}
Assert.True(api.Disposed);
}
private (RemoteSequenceSource Source, FakeRemoteSequenceApi Api, RemoteSequence Remote) Open(int frames = 6, int cached = int.MaxValue,
bool readOnly = false) =>
Open(EditorFixture.Sequence(frames), cached, readOnly);