feat(editor): settings both sides changed on the server ask before anything is overwritten
BRIEF §14.5 asks for an explicit conflict prompt when both sides changed. A save of a server sequence that meets settings someone changed to other values on the server now stops (the change stays pending) and the editor asks: Keep mine saves the editor's values over the server's, Take server (the safe default) shows the server's values as one undoable step, so Ctrl+Z brings the editor's back. Both first take in what only the server changed. Settings changed on one side only still merge silently; a reload after an analysis never merges over a conflicting pending change. The Export "Sync" box moves under Save to so neither is cut in longer languages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
13 files changed
+311
-32
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using Titano.App.Editor;
|
||||
using Titano.Core.Codecs.Jpeg;
|
||||
using Titano.Core.Diagnostics.Synthetic;
|
||||
@@ -113,6 +114,105 @@ public sealed class RemoteSequenceSourceTests(TestContext context)
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ASettingBothChangedWaitsForTheUsersChoice()
|
||||
{
|
||||
var (source, api, _) = Open();
|
||||
await using (source)
|
||||
{
|
||||
var content = await source.LoadAsync(context.Cancellation);
|
||||
api.EditsBefore.Enqueue(json =>
|
||||
{
|
||||
var theirs = ProjectSettings.FromJson(json ?? "{}");
|
||||
return (theirs with { Exposure = theirs.Exposure with { ExposureOffsetEv = 0.3 } }).ToJson();
|
||||
});
|
||||
var mine = content.Project with { Exposure = content.Project.Exposure with { ExposureOffsetEv = 0.5 } };
|
||||
var conflict = await Assert.ThrowsAsync<ProjectConflictException>(() => source.SaveProjectAsync(mine, content.Project, context.Cancellation));
|
||||
|
||||
var difference = Assert.Contains(conflict.Differences, _ => true);
|
||||
Assert.Equal(("exposure.exposureOffsetEv", "0.5", "0.3"), (difference.Path, difference.Mine, difference.Theirs));
|
||||
Assert.Equal(0.3, conflict.Server.Exposure.ExposureOffsetEv);
|
||||
// Asked again without overwriting anything until the editor names the server's settings as its basis.
|
||||
await Assert.ThrowsAsync<ProjectConflictException>(() => source.SaveProjectAsync(mine, content.Project, context.Cancellation));
|
||||
Assert.SequenceEqual([false], api.Edits.Select(e => e.Accepted));
|
||||
Assert.Equal(0.3, ProjectSettings.FromJson(api.SettingsJson!).Exposure.ExposureOffsetEv);
|
||||
|
||||
var kept = await source.SaveProjectAsync(mine, conflict.Server, context.Cancellation);
|
||||
Assert.Equal(0.5, kept.Exposure.ExposureOffsetEv);
|
||||
Assert.Equal(0.5, ProjectSettings.FromJson(api.SettingsJson!).Exposure.ExposureOffsetEv);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task KeepMineSavesTheEditorsValuesWithTheServersOtherChanges()
|
||||
{
|
||||
var (source, api, _) = Open();
|
||||
var content = await source.LoadAsync(context.Cancellation);
|
||||
await using var session = new EditorSession(source, content, [], TimeSpan.FromMilliseconds(20));
|
||||
var found = new TaskCompletionSource<ProjectConflictException>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
session.ConflictFound += conflict => found.TrySetResult(conflict);
|
||||
api.EditsBefore.Enqueue(ChangedOnTheServer);
|
||||
session.Edit(p => p with { Exposure = p.Exposure with { ExposureOffsetEv = 0.5 } });
|
||||
|
||||
var conflict = await found.Task.WaitAsync(TimeSpan.FromSeconds(10));
|
||||
Assert.Same(conflict, session.Conflict);
|
||||
Assert.False(await session.FlushAsync(), "the change waits for the choice");
|
||||
Assert.True(session.ResolveConflict(keepMine: true));
|
||||
Assert.True(await session.FlushAsync());
|
||||
|
||||
Assert.Null(session.Conflict);
|
||||
var stored = ProjectSettings.FromJson(api.SettingsJson!);
|
||||
Assert.Equal((0.5, -0.2), (stored.Exposure.ExposureOffsetEv, stored.Camera.OffsetY), "the editor's offset and the server's framing");
|
||||
Assert.True(ProjectMerge.SameValues(stored, session.Project));
|
||||
Assert.False(session.ResolveConflict(keepMine: false), "settled once");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TakeServerShowsTheServersValuesAndCtrlZBringsTheEditorsBack()
|
||||
{
|
||||
var (source, api, _) = Open();
|
||||
var content = await source.LoadAsync(context.Cancellation);
|
||||
await using var session = new EditorSession(source, content, [], TimeSpan.FromMilliseconds(20));
|
||||
var found = new TaskCompletionSource<ProjectConflictException>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
session.ConflictFound += conflict => found.TrySetResult(conflict);
|
||||
api.EditsBefore.Enqueue(ChangedOnTheServer);
|
||||
session.Edit(p => p with { Exposure = p.Exposure with { ExposureOffsetEv = 0.5 }, HeroFrame = 2 });
|
||||
await found.Task.WaitAsync(TimeSpan.FromSeconds(10));
|
||||
|
||||
Assert.True(session.ResolveConflict(keepMine: false));
|
||||
Assert.True(await session.FlushAsync());
|
||||
var stored = ProjectSettings.FromJson(api.SettingsJson!);
|
||||
Assert.Equal((0.3, -0.2, (int?)2), (stored.Exposure.ExposureOffsetEv, stored.Camera.OffsetY, stored.HeroFrame),
|
||||
"the server's values where both changed; the editor's other change is saved");
|
||||
Assert.True(ProjectMerge.SameValues(stored, session.Project));
|
||||
|
||||
Assert.True(session.Undo());
|
||||
Assert.True(await session.FlushAsync());
|
||||
stored = ProjectSettings.FromJson(api.SettingsJson!);
|
||||
Assert.Equal((0.5, -0.2), (stored.Exposure.ExposureOffsetEv, stored.Camera.OffsetY), "undo brings the editor's value back, the server's framing stays");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AReloadDoesNotMergeOverAConflictingChange()
|
||||
{
|
||||
var (source, api, _) = Open();
|
||||
var content = await source.LoadAsync(context.Cancellation);
|
||||
await using var session = new EditorSession(source, content, [], TimeSpan.FromHours(1));
|
||||
session.Edit(p => p with { Exposure = p.Exposure with { ExposureOffsetEv = 0.5 } });
|
||||
// An analysis ends on the server while someone there set the same setting; this editor's change was not sent yet.
|
||||
api.SettingsJson = ChangedOnTheServer(api.SettingsJson);
|
||||
api.SettingsVersion++;
|
||||
api.FailNextEdit = new HttpRequestException("offline");
|
||||
var found = 0;
|
||||
session.ConflictFound += _ => Interlocked.Increment(ref found);
|
||||
|
||||
await session.ReloadAsync(context.Cancellation);
|
||||
Assert.Equal(0.5, session.Project.Exposure.ExposureOffsetEv, "not merged over");
|
||||
Assert.False(await session.FlushAsync(), "the retry meets the server's change and asks");
|
||||
Assert.Equal(1, Volatile.Read(ref found));
|
||||
Assert.Equal(0.3, ProjectSettings.FromJson(api.SettingsJson!).Exposure.ExposureOffsetEv);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ConflictsThatKeepComingAreReported()
|
||||
{
|
||||
@@ -428,6 +528,13 @@ public sealed class RemoteSequenceSourceTests(TestContext context)
|
||||
return (new RemoteSequenceSource(remote, api, DecoderFactory.CreateClient(null), readOnly), api, remote);
|
||||
}
|
||||
|
||||
/// <summary>Someone on the server sets the exposure offset to 0.3 and moves the framing.</summary>
|
||||
private static string ChangedOnTheServer(string? json)
|
||||
{
|
||||
var theirs = ProjectSettings.FromJson(json ?? "{}");
|
||||
return (theirs with { Exposure = theirs.Exposure with { ExposureOffsetEv = 0.3 }, Camera = theirs.Camera with { OffsetY = -0.2 } }).ToJson();
|
||||
}
|
||||
|
||||
private static Job Last(List<Job> seen)
|
||||
{
|
||||
lock (seen) return seen[^1];
|
||||
|
||||
Reference in new issue
Block a user