fix(editor): name the frames version in the remote editor's saves
The desktop editor of a server sequence relied on the server's sequenceChanged event to go read-only when frames changed. Scans publish none, and an event missed while the socket reconnected was never noticed, so a save made meanwhile passed the settings-version check and wrote positions in the old order over the ones the server had moved. The PATCH now carries expectedFramesVersion, the frames version of the proxies the editor holds. On 409 the editor reads the manifest: other frames make it outdated (read-only, Get proxies; the edit stays pending), the same frames at a new version retry at that version. After a lost event socket the frames are compared again. Servers that predate the field ignore it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
3 files changed
+73
-10
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Channels;
|
||||
@@ -17,7 +18,7 @@ namespace Titano.App.Tests.Editor;
|
||||
internal sealed class FakeRemoteSequenceApi(Sequence sequence, IReadOnlyList<Guid> frames) : IRemoteSequenceApi
|
||||
{
|
||||
private readonly Lock _gate = new();
|
||||
private readonly Channel<ServerEvent> _events = Channel.CreateUnbounded<ServerEvent>();
|
||||
private Channel<ServerEvent> _events = Channel.CreateUnbounded<ServerEvent>();
|
||||
|
||||
/// <summary>The server's frames in order (another list when frames are added or removed on the server).</summary>
|
||||
public IReadOnlyList<Guid> Frames { get; set; } = frames;
|
||||
@@ -59,7 +60,10 @@ internal sealed class FakeRemoteSequenceApi(Sequence sequence, IReadOnlyList<Gui
|
||||
new(id, kind, [target ?? sequence.Id], sequence.DisplayTitle, state, "user", done, total, null, null, null, null, 0, null, DateTimeOffset.UtcNow,
|
||||
state == "queued" ? null : DateTimeOffset.UtcNow, state is "done" or "failed" ? DateTimeOffset.UtcNow : null);
|
||||
|
||||
public void Publish(ServerEvent e) => _events.Writer.TryWrite(e);
|
||||
public void Publish(ServerEvent e) => Volatile.Read(ref _events).Writer.TryWrite(e);
|
||||
|
||||
/// <summary>The event socket drops: the stream open now fails, and the next one starts empty.</summary>
|
||||
public void DropEvents() => Interlocked.Exchange(ref _events, Channel.CreateUnbounded<ServerEvent>()).Writer.TryComplete(new IOException("connection lost"));
|
||||
|
||||
public Task<SequenceDto> GetSequenceAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -98,6 +102,11 @@ internal sealed class FakeRemoteSequenceApi(Sequence sequence, IReadOnlyList<Gui
|
||||
Edits.Add((request, false));
|
||||
throw new TitanoApiException(HttpStatusCode.Conflict, new ApiError("settings_conflict", "changed", SettingsVersion.ToString()));
|
||||
}
|
||||
if (request.ExpectedFramesVersion is { } frames && frames != FramesVersion)
|
||||
{
|
||||
Edits.Add((request, false));
|
||||
throw new TitanoApiException(HttpStatusCode.Conflict, new ApiError("frames_conflict", "frames changed", FramesVersion.ToString()));
|
||||
}
|
||||
Edits.Add((request, true));
|
||||
SettingsJson = request.SettingsJson ?? SettingsJson;
|
||||
SettingsVersion++;
|
||||
@@ -158,9 +167,10 @@ internal sealed class FakeRemoteSequenceApi(Sequence sequence, IReadOnlyList<Gui
|
||||
|
||||
public async IAsyncEnumerable<ServerEvent> EventsAsync([EnumeratorCancellation] CancellationToken cancellationToken)
|
||||
{
|
||||
while (await _events.Reader.WaitToReadAsync(cancellationToken))
|
||||
var events = Volatile.Read(ref _events).Reader;
|
||||
while (await events.WaitToReadAsync(cancellationToken))
|
||||
{
|
||||
while (_events.Reader.TryRead(out var e)) yield return e;
|
||||
while (events.TryRead(out var e)) yield return e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user