Review 2, phase 5a, fix round 1 (desktop and the engine side of Resolve and Restore). - Resolve applies Keep mine / Take the library's only to the conflict the dialog listed: when the head or what differs moved since, the new conflict is recorded and asked again; Sync re-works a pending conflict instead of re-showing a stale list. Take the library's first saves uncommitted changes as a version, and the editor takes it as one undo step (toast Undo, Ctrl+Z) that brings back only the settings both changed. - Restore saves unsaved changes as a version also while a conflict waits; a restore that changed nothing, or was undone, no longer marks the next version as a Restore. - The editor's saves and merges of a workspace project merge positions photo by photo (portable form) and ask where both sides changed a setting, never deciding for ours. - Read-only after a pull is signalled, and no save that can never be stored is left behind. - The chip is read again after edits; a background conflict waits for the open dialog; Send first and Delete show the conflict they met; Discard changes needs the typed name. - Open project... reaches the library's other projects (Save both's sibling, also from its toast); copies whose project or sequence is gone read Not in library and can be removed from the picker's Workspace rows; a delete whose local copy stays says so. - A workspace folder inside a library is refused before anything is written. - Conflict and Compare lines name heroes, exclusions and keyframes; History shows the PC name alone, never the program's prefixes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
189 lines
11 KiB
C#
189 lines
11 KiB
C#
using Chronos.Core.Model;
|
||
using Chronos.Core.Project;
|
||
using Chronos.Data.Projects;
|
||
using Chronos.Data.Tests.Archiving;
|
||
using Chronos.Data.Tests.Infrastructure;
|
||
using Chronos.Data.Workspaces;
|
||
using Chronos.Testing;
|
||
|
||
namespace Chronos.Data.Tests.Workspaces;
|
||
|
||
/// <summary>
|
||
/// Settling a workspace conflict and restoring a version (owner review 2, R8): a choice applies only to the conflicts the
|
||
/// user was shown, what a choice replaces stays in a version, a restore loses nothing while a conflict waits, and only a
|
||
/// restore the working state still shows makes a "restore" version.
|
||
/// </summary>
|
||
[Category("workspace")]
|
||
public abstract class WorkspaceConflictTests(TestContext context) : DatabaseTest(context)
|
||
{
|
||
private async Task<WorkspaceFixture> FixtureAsync(int frames = 5)
|
||
{
|
||
var archive = Own(await ArchiveFixture.CreateAsync(Context, database: await NewOptionsAsync(multiConnection: true)));
|
||
return Own(await WorkspaceFixture.CreateAsync(Context, archive, frames));
|
||
}
|
||
|
||
/// <summary>The working state edited as the editor does: read, changed, stored.</summary>
|
||
private static async Task EditAsync(WorkspaceSync sync, Guid projectId, Func<ProjectSettings, ProjectSettings> edit, CancellationToken ct)
|
||
{
|
||
var session = await sync.OpenAsync(projectId, ct);
|
||
await sync.SaveAsync(projectId, edit(session.Working), ct);
|
||
}
|
||
|
||
private static ProjectSettings Offset(ProjectSettings s, double ev) => s with { Exposure = s.Exposure with { ExposureOffsetEv = ev } };
|
||
|
||
private static ProjectSettings Stack(ProjectSettings s, StackSetting mode) => s with { Stack = new StackSettings { Mode = mode } };
|
||
|
||
/// <summary>Two workspaces of Main; the first has sent an offset of 0.5 and a Median stack, the second changed the offset to 1 and was asked.</summary>
|
||
private static async Task<(WorkspaceFixture Fx, WorkspaceSync One, WorkspaceSync Two, Guid Id, WorkspaceConflict Shown)> AskedAsync(WorkspaceFixture fx)
|
||
{
|
||
var (_, one) = fx.Workspace("one");
|
||
var (_, two) = fx.Workspace("two");
|
||
var id = (await fx.CheckoutAsync(one)).ProjectId;
|
||
await fx.CheckoutAsync(two, id);
|
||
await EditAsync(one, id, s => Stack(Offset(s, 0.5), StackSetting.Median), fx.Ct);
|
||
await one.CommitAsync(id, cancellationToken: fx.Ct);
|
||
await one.PushAsync(id, fx.Home, fx.Ct);
|
||
await EditAsync(two, id, s => Offset(s, 1.0), fx.Ct);
|
||
var pulled = await two.PullAsync(id, fx.Home, fx.Ct);
|
||
var shown = Assert.NotNull(pulled.Status.Conflict);
|
||
Assert.Equal("exposure.exposureOffsetEv", shown.Differences.Single().Path, "the stack only one side changed merges");
|
||
return (fx, one, two, id, shown);
|
||
}
|
||
|
||
[Test]
|
||
public async Task AChoiceSettlesOnlyTheConflictsTheUserWasShown()
|
||
{
|
||
var (fx, _, two, id, shown) = await AskedAsync(await FixtureAsync());
|
||
|
||
// Later: editing goes on, and the stack, which the library changed too, is set here. Nobody was shown that one.
|
||
await EditAsync(two, id, s => Stack(s, StackSetting.StarTrails), fx.Ct);
|
||
var asked = await two.ResolveAsync(id, fx.Home, ConflictChoice.TakeServer, shown: shown, cancellationToken: fx.Ct);
|
||
Assert.Equal(WorkspaceState.Conflict, asked.Status.State);
|
||
var again = Assert.NotNull(asked.Status.Conflict);
|
||
Assert.SequenceEqual(["exposure.exposureOffsetEv", "stack.mode"], again.Differences.Select(d => d.Path).Order(StringComparer.Ordinal));
|
||
var working = (await two.OpenAsync(id, fx.Ct)).Working;
|
||
Assert.Equal((1.0, StackSetting.StarTrails), (working.Exposure.ExposureOffsetEv, working.Stack.Mode), "nothing was settled");
|
||
|
||
// Asked again with both, take the library's: its values; this side's are kept in a version all the same.
|
||
Assert.Null(asked.Kept, "nothing settled, nothing to take back");
|
||
var settled = await two.ResolveAsync(id, fx.Home, ConflictChoice.TakeServer, shown: again, cancellationToken: fx.Ct);
|
||
Assert.Null(settled.Status.Conflict);
|
||
working = (await two.OpenAsync(id, fx.Ct)).Working;
|
||
Assert.Equal((0.5, StackSetting.Median), (working.Exposure.ExposureOffsetEv, working.Stack.Mode));
|
||
// What keeping this side's values would have left, for the editor's undo of the take.
|
||
var kept = Assert.NotNull(settled.Kept);
|
||
Assert.Equal((1.0, StackSetting.StarTrails), (kept.Exposure.ExposureOffsetEv, kept.Stack.Mode));
|
||
var replaced = Path.Combine(two.Store.Find(id)!.VersionsDirectory, WorkspaceProject.ReplacedFolder);
|
||
Assert.True(Directory.GetFiles(replaced).Select(ProjectSidecars.ReadVersion).Any(v =>
|
||
ProjectSettings.FromJson(v.SettingsJson) is { Stack.Mode: StackSetting.StarTrails, Exposure.ExposureOffsetEv: 1.0 }), "the values taken over stay in a version");
|
||
}
|
||
|
||
[Test]
|
||
public async Task KeepMineIsAskedAgainWhenTheLibraryMovedOnASettingThisSideChanged()
|
||
{
|
||
var (fx, one, two, id, shown) = await AskedAsync(await FixtureAsync());
|
||
await EditAsync(two, id, s => s with { Motion = s.Motion with { TargetShutterAngle = s.Motion.TargetShutterAngle.WithManual(90) } }, fx.Ct);
|
||
|
||
// Meanwhile the other workspace sends a change of that same setting.
|
||
await one.PullAsync(id, fx.Home, fx.Ct);
|
||
await EditAsync(one, id, s => s with { Motion = s.Motion with { TargetShutterAngle = s.Motion.TargetShutterAngle.WithManual(270) } }, fx.Ct);
|
||
await one.CommitAsync(id, cancellationToken: fx.Ct);
|
||
await one.PushAsync(id, fx.Home, fx.Ct);
|
||
|
||
var asked = await two.ResolveAsync(id, fx.Home, ConflictChoice.KeepMine, shown: shown, cancellationToken: fx.Ct);
|
||
var again = Assert.NotNull(asked.Status.Conflict, "the library's newer change is asked about, not overwritten");
|
||
Assert.Equal(2, again.Differences.Count);
|
||
Assert.Contains(again.Differences, d => d.Path.StartsWith("motion.targetShutterAngle", StringComparison.Ordinal));
|
||
Assert.Equal(270.0, ProjectSettings.FromJson((await fx.Home.HeadAsync(id, fx.Ct)).SettingsJson).Motion.TargetShutterAngle.Resolve(0));
|
||
|
||
var settled = await two.ResolveAsync(id, fx.Home, ConflictChoice.KeepMine, shown: again, cancellationToken: fx.Ct);
|
||
Assert.Equal(WorkspaceState.Modified, settled.Status.State, "this side's values are the working state, on the library's head");
|
||
Assert.Null(settled.Kept, "keeping mine replaces nothing of this side's");
|
||
await two.CommitAsync(id, cancellationToken: fx.Ct);
|
||
await two.PushAsync(id, fx.Home, fx.Ct);
|
||
var head = ProjectSettings.FromJson((await fx.Home.HeadAsync(id, fx.Ct)).SettingsJson);
|
||
Assert.Equal((1.0, 90.0, StackSetting.Median), (head.Exposure.ExposureOffsetEv, head.Motion.TargetShutterAngle.Resolve(0), head.Stack.Mode));
|
||
}
|
||
|
||
[Test]
|
||
public async Task SyncAsksAboutWhatDiffersNowWhileAConflictWaits()
|
||
{
|
||
var (fx, _, two, id, _) = await AskedAsync(await FixtureAsync());
|
||
|
||
// Edited during Later: the next pull lists the stack too.
|
||
await EditAsync(two, id, s => Stack(s, StackSetting.Mean), fx.Ct);
|
||
var refreshed = Assert.NotNull((await two.PullAsync(id, fx.Home, fx.Ct)).Status.Conflict);
|
||
Assert.SequenceEqual(["exposure.exposureOffsetEv", "stack.mode"], refreshed.Differences.Select(d => d.Path).Order(StringComparer.Ordinal));
|
||
|
||
// This side takes the library's values by hand: nothing conflicts any more, and the pull settles it.
|
||
await EditAsync(two, id, s => Stack(Offset(s, 0.5), StackSetting.Median), fx.Ct);
|
||
var pulled = await two.PullAsync(id, fx.Home, fx.Ct);
|
||
Assert.Null(pulled.Status.Conflict);
|
||
Assert.Equal(WorkspaceState.InSync, pulled.Status.State);
|
||
Assert.Null(await two.CommitAsync(id, cancellationToken: fx.Ct), "nothing new to save, and no conflict refuses a version");
|
||
}
|
||
|
||
[Test]
|
||
public async Task ARestoreWhileAConflictWaitsKeepsTheUnsavedChangesAsAVersion()
|
||
{
|
||
var (fx, _, two, id, _) = await AskedAsync(await FixtureAsync());
|
||
var first = (await fx.Home.HistoryAsync(id, null, 10, fx.Ct)).Single(v => v.Number == 1);
|
||
|
||
// Later, then an edit stored but saved as no version, then History › Restore.
|
||
await EditAsync(two, id, s => Stack(s, StackSetting.Mean), fx.Ct);
|
||
var restored = await two.RestoreAsync(id, first.Id, fx.Home, fx.Ct);
|
||
Assert.Equal((0.0, StackSetting.None), (restored.Exposure.ExposureOffsetEv, restored.Stack.Mode));
|
||
var kept = Assert.Contains(two.Unpushed(id), v => ProjectSettings.FromJson(v.SettingsJson) is { Stack.Mode: StackSetting.Mean, Exposure.ExposureOffsetEv: 1.0 });
|
||
Assert.Equal(ProjectVersionKind.Commit, kept.Kind);
|
||
Assert.NotNull((await two.StatusAsync(id, fx.Home, fx.Ct)).Conflict, "the conflict still waits");
|
||
|
||
// Settled for this side, the saved edit reaches the library under the restore.
|
||
var asked = Assert.NotNull((await two.PullAsync(id, fx.Home, fx.Ct)).Status.Conflict);
|
||
await two.ResolveAsync(id, fx.Home, ConflictChoice.KeepMine, shown: asked, cancellationToken: fx.Ct);
|
||
await two.PushAsync(id, fx.Home, fx.Ct);
|
||
Assert.Contains(await fx.Home.HistoryAsync(id, null, 10, fx.Ct), v => ProjectSettings.FromJson(v.SettingsJson).Stack.Mode == StackSetting.Mean);
|
||
}
|
||
|
||
[Test]
|
||
public async Task OnlyARestoreTheWorkingStateStillShowsMakesARestoreVersion()
|
||
{
|
||
var fx = await FixtureAsync();
|
||
var (_, sync) = fx.Workspace();
|
||
var id = (await fx.CheckoutAsync(sync)).ProjectId;
|
||
var original = await fx.Home.HeadAsync(id, fx.Ct);
|
||
await EditAsync(sync, id, s => Offset(s, 0.3), fx.Ct);
|
||
var warm = Assert.NotNull(await sync.CommitAsync(id, cancellationToken: fx.Ct));
|
||
|
||
// Restoring the version the project is changes nothing: the next version is a plain one.
|
||
await sync.RestoreAsync(id, warm.Id, fx.Home, fx.Ct);
|
||
await EditAsync(sync, id, s => Stack(s, StackSetting.Mean), fx.Ct);
|
||
var next = Assert.NotNull(await sync.CommitAsync(id, cancellationToken: fx.Ct));
|
||
Assert.Equal((ProjectVersionKind.Commit, (Guid?)null), (next.Kind, next.RestoredFrom));
|
||
|
||
// A restore taken back (the editor's Undo writes the state from before it again), then another edit: no restore either.
|
||
var before = (await sync.OpenAsync(id, fx.Ct)).Working;
|
||
await sync.RestoreAsync(id, original.Id, fx.Home, fx.Ct);
|
||
await sync.SaveAsync(id, before, fx.Ct);
|
||
await EditAsync(sync, id, s => s with { ExcludedFrames = [1] }, fx.Ct);
|
||
var after = Assert.NotNull(await sync.CommitAsync(id, cancellationToken: fx.Ct));
|
||
Assert.Equal((ProjectVersionKind.Commit, (Guid?)null), (after.Kind, after.RestoredFrom));
|
||
|
||
// A restore the working state still shows, edited further: a restore of it.
|
||
await sync.RestoreAsync(id, original.Id, fx.Home, fx.Ct);
|
||
await EditAsync(sync, id, s => s with { HeroFrame = 2 }, fx.Ct);
|
||
var restore = Assert.NotNull(await sync.CommitAsync(id, cancellationToken: fx.Ct));
|
||
Assert.Equal((ProjectVersionKind.Restore, (Guid?)original.Id), (restore.Kind, restore.RestoredFrom));
|
||
}
|
||
}
|
||
|
||
public sealed class SqliteWorkspaceConflictTests(TestContext context) : WorkspaceConflictTests(context)
|
||
{
|
||
protected override Backend Backend => Backend.SqliteFile;
|
||
}
|
||
|
||
[RequiresEnvironment(PgTestServer.Variable)]
|
||
public sealed class PostgresWorkspaceConflictTests(TestContext context) : WorkspaceConflictTests(context)
|
||
{
|
||
protected override Backend Backend => Backend.Postgres;
|
||
}
|