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,12 +1,13 @@
|
||||
using Titano.App.Editor;
|
||||
using Titano.Core.Advice;
|
||||
using Titano.Core.Imaging;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Project;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.App.Tests.Editor;
|
||||
|
||||
/// <summary>Composed texts of the editor, crop margins and the waveform monitor.</summary>
|
||||
/// <summary>Composed texts of the editor (the conflict prompt among them), crop margins and the waveform monitor.</summary>
|
||||
public sealed class EditorTextTests
|
||||
{
|
||||
static EditorTextTests() => _ = EditorFixture.Sunset;
|
||||
@@ -67,4 +68,21 @@ public sealed class EditorTextTests
|
||||
Assert.LessOrEqual(Math.Abs(lit[0] - (LumaWaveform.Levels - 1) / 2.0), 1.0, "half grey sits halfway up");
|
||||
Assert.Equal(255, waveform.Density[lit[0] * waveform.Columns], "every pixel of the column there");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheConflictPromptSaysWhatDiffersAndTakesTheServersValuesUnlessAsked()
|
||||
{
|
||||
var basis = new ProjectSettings();
|
||||
var mine = basis with { Exposure = basis.Exposure with { ExposureOffsetEv = 0.5 }, HeroFrame = 3 };
|
||||
var theirs = basis with { Exposure = basis.Exposure with { ExposureOffsetEv = 0.3 } };
|
||||
var conflict = new ProjectConflictException("changed", theirs, ProjectMerge.Conflicts(basis, mine, theirs));
|
||||
var request = EditorViewModel.ConflictRequest(conflict, "Harbour sunset", "Studio NAS");
|
||||
|
||||
Assert.Equal(Loc.L("Server.Conflict.Difference", Loc.L("Server.Setting.ExposureOffset"), 0.5.ToString("0.###", Loc.Culture),
|
||||
0.3.ToString("0.###", Loc.Culture)), request.Detail, "only the setting both changed; the editor's value first");
|
||||
Assert.Equal(Loc.L("Server.Sync.Action.TakeServer"), request.SafeText, "the safe default loses nothing: Ctrl+Z brings the editor's values back");
|
||||
Assert.Equal(Loc.L("Server.Sync.Action.KeepMine"), request.ActionText);
|
||||
Assert.True(request.IsDestructive, "Keep mine overwrites the server's values");
|
||||
Assert.Contains("Studio NAS", request.Heading);
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,9 @@ internal sealed class FakeRemoteSequenceApi(Sequence sequence, IReadOnlyList<Gui
|
||||
/// <summary>Thrown by the next read of a job (a failure the editor's event listener does not expect).</summary>
|
||||
public Exception? FailNextJobRead { get; set; }
|
||||
|
||||
/// <summary>Thrown by the next edit before it reaches the server (the connection dropped).</summary>
|
||||
public Exception? FailNextEdit { get; set; }
|
||||
|
||||
/// <summary>Someone else edits the settings before each of the next edits reaches the server (it is refused with 409).</summary>
|
||||
public Queue<Func<string?, string>> EditsBefore { get; } = new();
|
||||
|
||||
@@ -78,6 +81,11 @@ internal sealed class FakeRemoteSequenceApi(Sequence sequence, IReadOnlyList<Gui
|
||||
lock (_gate)
|
||||
{
|
||||
Check(id);
|
||||
if (FailNextEdit is { } failure)
|
||||
{
|
||||
FailNextEdit = null;
|
||||
throw failure;
|
||||
}
|
||||
if (EditsBefore.TryDequeue(out var theirs))
|
||||
{
|
||||
SettingsJson = theirs(SettingsJson);
|
||||
|
||||
@@ -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