merge: review2-p5a-fix-desktop into phase 5a fix round 1 integration
# Conflicts: # src/Chronos.Data/Workspaces/WorkspaceSync.cs
This commit is contained in:
commit
1a35fcdb27
28 files changed
+1328
-139
No files matched your search
@@ -273,6 +273,9 @@ public sealed class WorkspaceEditorTests(TestContext context)
|
||||
var head = await there.HomeOfSequence(bed.SequenceId).HeadAsync(sibling.Id, bed.Ct);
|
||||
Assert.Equal(0.8, ProjectSettings.FromJson(head.SettingsJson).Exposure.ExposureOffsetEv, "nothing is lost: the sibling holds this side's values");
|
||||
Assert.Equal(Loc.L("Editor.Workspace.SavedAs", sibling.Name), uiB.Toasts[^1].Title);
|
||||
// The toast opens the sibling, which no other way lists while this project is the sequence's here.
|
||||
uiB.Toasts[^1].Action!();
|
||||
Assert.Equal((bed.SequenceId, sibling.Id), uiB.Opened[^1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -255,10 +255,25 @@ public sealed class WorkspaceHostTests(TestContext context)
|
||||
Assert.True(plan is { Modified: true, Unsent: 0, Conflict: false, Offline: false, IsSafe: false });
|
||||
Assert.True(plan.Files >= 4 + 2, "the proxies, the media index and the working state");
|
||||
Assert.Greater(plan.Bytes, 0);
|
||||
var dialog = new RemoveCopyDialogViewModel(plan, _ => Task.CompletedTask, () => Task.CompletedTask, _ => { });
|
||||
var discards = new List<bool>();
|
||||
var asked = 0;
|
||||
var dialog = new RemoveCopyDialogViewModel(plan, d =>
|
||||
{
|
||||
discards.Add(d);
|
||||
return Task.CompletedTask;
|
||||
}, () => Task.CompletedTask, () => ++asked > 1, _ => { });
|
||||
Assert.False(dialog.RemoveCommand.CanExecute(null), "not while work is not in the library");
|
||||
Assert.Equal(Loc.L("Errors.Workspace.Unsent"), dialog.RemoveToolTip);
|
||||
Assert.True(dialog.SendFirstCommand.CanExecute(null) && dialog.DiscardCommand.CanExecute(null));
|
||||
// Discard changes asks for the typed confirmation first: refused, nothing is removed; confirmed, it is.
|
||||
dialog.DiscardCommand.Execute(null);
|
||||
await WorkspaceTestBed.UntilAsync(() => asked == 1 && dialog.DiscardCommand.CanExecute(null), "the confirmation is asked");
|
||||
Assert.Empty(discards, "refused: nothing discarded");
|
||||
dialog.DiscardCommand.Execute(null);
|
||||
await WorkspaceTestBed.UntilAsync(() => discards.Count == 1, "confirmed: discarded");
|
||||
Assert.True(discards[0]);
|
||||
var request = RemoveCopyDialogViewModel.DiscardRequest("Main");
|
||||
Assert.True(request is { IsDestructive: true, TypedConfirmation: "Main" } && request.TypedPrompt is { Length: > 0 });
|
||||
var refused = await Assert.ThrowsAsync<WorkspaceException>(() => host.RemoveLocalCopyAsync(mainId, discard: false));
|
||||
Assert.Equal(Loc.L("Errors.Workspace.Unsent"), refused.Message);
|
||||
Assert.NotNull(host.Store.Find(mainId), "nothing was removed");
|
||||
|
||||
@@ -0,0 +1,313 @@
|
||||
using System.IO;
|
||||
using Chronos.App.Editor;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Workspace;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Data.Workspaces;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.App.Tests.Workspace;
|
||||
|
||||
/// <summary>
|
||||
/// The editor and the project menu of a workspace project as review 2's phase 5a found them wanting (owner review 2, R8):
|
||||
/// saves that merge positions photo by photo and ask where both changed a setting, Take the library's as one undo step,
|
||||
/// the chip read again after edits, conflicts that wait for the open dialog, Send first that shows the conflict it met,
|
||||
/// Open project, read-only after a pull, a workspace inside a library, and how differences and authors read.
|
||||
/// </summary>
|
||||
[Category("workspace")]
|
||||
public sealed class WorkspaceMenuTests(TestContext context)
|
||||
{
|
||||
private static ProjectSettings Exposure(ProjectSettings p, double ev) => p with { Exposure = p.Exposure with { ExposureOffsetEv = ev } };
|
||||
|
||||
[Test]
|
||||
public async Task SavesMergeExclusionsPhotoByPhotoAndAskWhereBothChangedASetting()
|
||||
{
|
||||
await using var bed = await WorkspaceTestBed.CreateAsync(context);
|
||||
var host = bed.Host();
|
||||
var projectId = await bed.CheckoutAsync(host);
|
||||
var (_, session) = await bed.OpenAsync(host, projectId);
|
||||
var conflicts = new List<ProjectConflictException>();
|
||||
session.ConflictFound += conflicts.Add;
|
||||
await using (session)
|
||||
{
|
||||
var folder = host.Store.Find(projectId)!;
|
||||
// A sync wrote another PC's exclusion of frame 5 while the editor's exclusion of frame 2 waited for its save.
|
||||
var stored = folder.ReadBundle();
|
||||
folder.WriteBundle(stored with { Project = stored.Project with { ExcludedFrames = [5] } });
|
||||
Assert.True(session.SetExcluded([2], excluded: true));
|
||||
Assert.True(await session.FlushAsync());
|
||||
Assert.SequenceEqual([2, 5], folder.ReadBundle().Project.ExcludedFrames, "both exclusions are kept");
|
||||
Assert.SequenceEqual([2, 5], session.Project.ExcludedFrames, "the editor shows the other one too");
|
||||
Assert.Empty(conflicts);
|
||||
|
||||
// The same setting to another value meanwhile: asked, never decided for the editor.
|
||||
stored = folder.ReadBundle();
|
||||
folder.WriteBundle(stored with { Project = Exposure(stored.Project, 0.5) });
|
||||
Assert.True(session.Edit(p => Exposure(p, 0.9)));
|
||||
Assert.False(await session.FlushAsync(), "nothing is stored until the user chooses");
|
||||
Assert.Count(1, conflicts);
|
||||
var conflict = conflicts[0];
|
||||
Assert.Contains(conflict.Differences, d => d.Path == "exposure.exposureOffsetEv");
|
||||
Assert.Equal(0.5, folder.ReadBundle().Project.Exposure.ExposureOffsetEv);
|
||||
var request = EditorViewModel.LibraryConflictRequest(conflict, "Harbour");
|
||||
Assert.Equal(Loc.L("Editor.Workspace.Conflict.TakeHome"), request.SafeText);
|
||||
Assert.Contains("0.9", request.Detail!);
|
||||
Assert.True(session.ResolveConflict(keepMine: true));
|
||||
Assert.True(await session.FlushAsync());
|
||||
Assert.Equal(0.9, folder.ReadBundle().Project.Exposure.ExposureOffsetEv);
|
||||
Assert.SequenceEqual([2, 5], folder.ReadBundle().Project.ExcludedFrames);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TakingTheLibrarysValuesIsOneUndoStepThatKeepsItsOtherChanges()
|
||||
{
|
||||
await using var bed = await WorkspaceTestBed.CreateAsync(context);
|
||||
var here = bed.Host();
|
||||
var there = bed.Host(name: "other-pc");
|
||||
var mainId = await bed.CheckoutAsync(here);
|
||||
await bed.CheckoutAsync(there);
|
||||
var (sourceA, sessionA) = await bed.OpenAsync(there, mainId);
|
||||
var (sourceB, sessionB) = await bed.OpenAsync(here, mainId);
|
||||
var (uiA, uiB) = (new RecordingUi(), new RecordingUi());
|
||||
await using (sessionA)
|
||||
await using (sessionB)
|
||||
using (var a = new ProjectMenuViewModel(there, sourceA, sessionA, uiA))
|
||||
using (var b = new ProjectMenuViewModel(here, sourceB, sessionB, uiB))
|
||||
{
|
||||
// The other PC changes the exposure and the camera; this one the exposure only.
|
||||
sessionA.Edit(p => Exposure(p, 0.1) with { Camera = p.Camera with { OffsetY = 0.2 } });
|
||||
await a.SaveVersionAsync(null);
|
||||
sessionB.Edit(p => Exposure(p, 0.7));
|
||||
await b.SyncAsync();
|
||||
var dialog = Assert.NotNull(uiB.Open as ConflictDialogViewModel);
|
||||
Assert.Count(1, dialog.Differences);
|
||||
|
||||
dialog.TakeHomeCommand.Execute(null);
|
||||
await WorkspaceTestBed.UntilAsync(() => uiB.Open is null, "take the library's settles it");
|
||||
Assert.Equal((0.1, 0.2), (sessionB.Project.Exposure.ExposureOffsetEv, sessionB.Project.Camera.OffsetY));
|
||||
var toast = uiB.Toasts[^1];
|
||||
Assert.Equal(Loc.L("Editor.Workspace.TookLibrary"), toast.Title);
|
||||
|
||||
// Its Undo brings this PC's exposure back, not the camera the library alone changed; Ctrl+Z takes the take back alike.
|
||||
toast.Action!();
|
||||
Assert.Equal((0.7, 0.2), (sessionB.Project.Exposure.ExposureOffsetEv, sessionB.Project.Camera.OffsetY));
|
||||
Assert.True(sessionB.Undo());
|
||||
Assert.Equal(0.1, sessionB.Project.Exposure.ExposureOffsetEv);
|
||||
Assert.True(sessionB.Undo());
|
||||
Assert.Equal((0.7, 0.2), (sessionB.Project.Exposure.ExposureOffsetEv, sessionB.Project.Camera.OffsetY));
|
||||
Assert.True(await sessionB.FlushAsync());
|
||||
var working = here.Store.Find(mainId)!.ReadBundle().Project;
|
||||
Assert.Equal((0.7, 0.2), (working.Exposure.ExposureOffsetEv, working.Camera.OffsetY), "the values brought back are stored");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheChipFollowsEditsAndABackgroundConflictWaitsForTheOpenDialog()
|
||||
{
|
||||
await using var bed = await WorkspaceTestBed.CreateAsync(context);
|
||||
var here = bed.Host();
|
||||
var there = bed.Host(name: "other-pc");
|
||||
var mainId = await bed.CheckoutAsync(here);
|
||||
await bed.CheckoutAsync(there);
|
||||
var (sourceA, sessionA) = await bed.OpenAsync(there, mainId);
|
||||
var (sourceB, sessionB) = await bed.OpenAsync(here, mainId);
|
||||
var (uiA, uiB) = (new RecordingUi(), new RecordingUi());
|
||||
await using (sessionA)
|
||||
await using (sessionB)
|
||||
using (var a = new ProjectMenuViewModel(there, sourceA, sessionA, uiA))
|
||||
using (var b = new ProjectMenuViewModel(here, sourceB, sessionB, uiB))
|
||||
{
|
||||
await b.RefreshAsync();
|
||||
Assert.Equal(Loc.L("Editor.Workspace.State.InSync"), b.StateText);
|
||||
sessionB.Edit(p => Exposure(p, 0.7));
|
||||
await WorkspaceTestBed.UntilAsync(() => b.StateText == Loc.L("Editor.Workspace.State.Modified"), "the chip says the work is not saved as a version");
|
||||
|
||||
sessionA.Edit(p => Exposure(p, 0.1));
|
||||
await a.SaveVersionAsync(null);
|
||||
// The user types a note in Save version when an automatic sync (after an analysis) meets the conflict.
|
||||
b.SaveVersionCommand.Execute(null);
|
||||
var saving = Assert.NotNull(uiB.Open as SaveVersionDialogViewModel);
|
||||
saving.Note = "Warmer";
|
||||
await b.SyncAsync(quiet: true);
|
||||
Assert.Same(saving, uiB.Open, "the open dialog stays");
|
||||
Assert.Equal("Warmer", saving.Note);
|
||||
Assert.Equal(WorkspaceState.Conflict, b.Status!.State);
|
||||
await b.SyncAsync(quiet: true);
|
||||
Assert.Count(1, uiB.Waiting, "asked once");
|
||||
uiB.CloseDialog(saving);
|
||||
Assert.NotNull(uiB.Open as ConflictDialogViewModel, "asked once the dialog closed");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SendFirstShowsTheConflictItMeetsAndRemovesNothing()
|
||||
{
|
||||
await using var bed = await WorkspaceTestBed.CreateAsync(context);
|
||||
var here = bed.Host();
|
||||
var there = bed.Host(name: "other-pc");
|
||||
var mainId = await bed.CheckoutAsync(here);
|
||||
await bed.CheckoutAsync(there);
|
||||
var (sourceA, sessionA) = await bed.OpenAsync(there, mainId);
|
||||
var (sourceB, sessionB) = await bed.OpenAsync(here, mainId);
|
||||
var (uiA, uiB) = (new RecordingUi(), new RecordingUi());
|
||||
await using (sessionA)
|
||||
await using (sessionB)
|
||||
using (var a = new ProjectMenuViewModel(there, sourceA, sessionA, uiA))
|
||||
using (var b = new ProjectMenuViewModel(here, sourceB, sessionB, uiB))
|
||||
{
|
||||
sessionA.Edit(p => Exposure(p, 0.1));
|
||||
await a.SaveVersionAsync(null);
|
||||
sessionB.Edit(p => Exposure(p, 0.7));
|
||||
Assert.True(await sessionB.FlushAsync());
|
||||
|
||||
b.RemoveCopyCommand.Execute(null);
|
||||
await WorkspaceTestBed.UntilAsync(() => uiB.Open is RemoveCopyDialogViewModel, "the plan shows");
|
||||
var removing = (RemoveCopyDialogViewModel)uiB.Open!;
|
||||
removing.SendFirstCommand.Execute(null);
|
||||
await WorkspaceTestBed.UntilAsync(() => uiB.Open is ConflictDialogViewModel, "the conflict is asked, not hidden behind Discard");
|
||||
Assert.Equal(0, uiB.Closed, "the editor stays open");
|
||||
Assert.NotNull(here.Store.Find(mainId), "nothing was removed");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task OpenProjectOffersTheLibrarysOtherProjects()
|
||||
{
|
||||
await using var bed = await WorkspaceTestBed.CreateAsync(context);
|
||||
var host = bed.Host();
|
||||
var mainId = await bed.CheckoutAsync(host);
|
||||
var vertical = await host.CreateProjectAsync(bed.SequenceId, "Vertical", null);
|
||||
var (source, session) = await bed.OpenAsync(host, mainId);
|
||||
var ui = new RecordingUi();
|
||||
await using (session)
|
||||
using (var menu = new ProjectMenuViewModel(host, source, session, ui))
|
||||
{
|
||||
menu.OpenProjectCommand.Execute(null);
|
||||
await WorkspaceTestBed.UntilAsync(() => ui.Open is OpenInWorkspaceDialogViewModel, "the projects are listed");
|
||||
var dialog = (OpenInWorkspaceDialogViewModel)ui.Open!;
|
||||
Assert.SequenceEqual(["Vertical"], dialog.Projects.Select(p => p.Project.Name), "the open project is not offered");
|
||||
dialog.IsNew = true;
|
||||
dialog.NewName.Text = "Main";
|
||||
Assert.False(dialog.CanOpen, "the open project's name is taken");
|
||||
dialog.IsExisting = true;
|
||||
dialog.SelectedProject = dialog.Projects[0];
|
||||
dialog.OpenCommand.Execute(null);
|
||||
await WorkspaceTestBed.UntilAsync(() => ui.Opened.Count == 1, "the project opens");
|
||||
Assert.Equal((bed.SequenceId, vertical.Id), ui.Opened[0]);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task APullOfANewerChronossSettingsTurnsTheEditorReadOnly()
|
||||
{
|
||||
await using var bed = await WorkspaceTestBed.CreateAsync(context);
|
||||
var host = bed.Host();
|
||||
var projectId = await bed.CheckoutAsync(host);
|
||||
var (source, session) = await bed.OpenAsync(host, projectId);
|
||||
var raised = 0;
|
||||
source.ReadOnlyChanged += () => raised++;
|
||||
await using (session)
|
||||
{
|
||||
Assert.False(session.IsReadOnly);
|
||||
var folder = host.Store.Find(projectId)!;
|
||||
var stored = folder.ReadBundle();
|
||||
folder.WriteBundle(stored with { Project = stored.Project with { Version = ProjectSettings.CurrentVersion + 1 } });
|
||||
await session.ReloadAsync();
|
||||
Assert.True(session.IsReadOnly);
|
||||
Assert.Equal(1, raised, "the editor is told, and shows it");
|
||||
Assert.False(session.HasPendingSave, "no save that could never be stored waits");
|
||||
Assert.False(session.Edit(p => Exposure(p, 0.4)));
|
||||
Assert.True(await session.FlushAsync(), "operations that store the last edit go on");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AWorkspaceInsideALibraryIsRefusedBeforeAnythingIsWritten()
|
||||
{
|
||||
await using var bed = await WorkspaceTestBed.CreateAsync(context);
|
||||
var row = await bed.RowAsync();
|
||||
var root = (await bed.Db.Archives.GetAsync(row.ArchiveId))!.RootPath;
|
||||
var inside = Path.Combine(root, "Chronos", "data", "workspace");
|
||||
var host = bed.Host(new AppSettings { WorkspaceFolder = inside });
|
||||
Assert.Empty(await host.ListAsync());
|
||||
Assert.Null(await host.FindAsync(Guid.NewGuid()));
|
||||
var refused = await Assert.ThrowsAsync<WorkspaceException>(() => host.CheckoutAsync(bed.SequenceId, null, null));
|
||||
Assert.Equal(Loc.L("Errors.Workspace.InsideLibraryEdit", inside), refused.Message);
|
||||
Assert.False(Directory.Exists(inside), "nothing was written there");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ACopyTheLibraryNoLongerHasCanOnlyBeDiscarded()
|
||||
{
|
||||
var plan = new WorkspaceRemovalPlan(Guid.NewGuid(), "Vertical", 3, 100, 0, false, false, true, Gone: true);
|
||||
var dialog = new RemoveCopyDialogViewModel(plan, _ => Task.CompletedTask, () => Task.CompletedTask, () => false, _ => { });
|
||||
Assert.False(dialog.RemoveCommand.CanExecute(null) || dialog.SendFirstCommand.CanExecute(null));
|
||||
Assert.True(dialog.HasUnsent && dialog.DiscardCommand.CanExecute(null));
|
||||
Assert.Equal(Loc.L("Errors.Workspace.ProjectGone"), dialog.RemoveToolTip);
|
||||
|
||||
// The chip keeps what the library said last when the working state is read again after an edit.
|
||||
var basis = new BundleBase(Guid.NewGuid(), 2, new string('a', 64));
|
||||
var gone = new WorkspaceStatus(WorkspaceState.Gone, false, 0, 0, true, false, false, null, basis, null);
|
||||
var edited = new WorkspaceStatus(WorkspaceState.Modified, true, 0, 0, false, false, false, null, basis, null);
|
||||
Assert.Equal(WorkspaceState.Gone, ProjectMenuViewModel.WithLocal(gone, edited).State);
|
||||
var behind = gone with { State = WorkspaceState.Behind, Behind = 2, Offline = false };
|
||||
Assert.Equal((WorkspaceState.Behind, 2), (ProjectMenuViewModel.WithLocal(behind, edited).State, ProjectMenuViewModel.WithLocal(behind, edited).Behind));
|
||||
Assert.Equal(WorkspaceState.Modified, ProjectMenuViewModel.WithLocal(behind, edited with { Base = basis with { VersionId = Guid.NewGuid() } }).State,
|
||||
"a base that moved since says nothing of how far the library is ahead");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DifferencesNameTheirSettingsAndAuthorsReadAsThePc()
|
||||
{
|
||||
var lines = WorkspaceText.ConflictLines(
|
||||
[
|
||||
new SettingsDifference("hero", "{\"hero\":true}", "{\"hero\":true}"),
|
||||
new SettingsDifference("pendingFrames.sha:ab12#0.keyframes", "[]", "[{\"x\":1}]"),
|
||||
new SettingsDifference("pendingFrames.sha:cd34#0.excluded", "true", "false"),
|
||||
], 10);
|
||||
Assert.Count(3, lines);
|
||||
Assert.Contains(lines, l => l.Contains(Loc.L("Server.Setting.HeroFrame"), StringComparison.Ordinal));
|
||||
Assert.Contains(lines, l => l.Contains(Loc.L("Server.Setting.Keyframes"), StringComparison.Ordinal));
|
||||
Assert.Contains(lines, l => l.Contains(Loc.L("Server.Setting.ExcludedFrames"), StringComparison.Ordinal));
|
||||
Assert.False(lines.Any(l => l.Contains(Loc.L("Server.Setting.Other"), StringComparison.Ordinal)), "every line names its setting");
|
||||
|
||||
ProjectVersion Made(string? client, string? author = null) => new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
ProjectId = Guid.NewGuid(),
|
||||
Number = 1,
|
||||
SettingsJson = "{}",
|
||||
ContentHash = new string('0', 64),
|
||||
ClientName = client,
|
||||
Author = author,
|
||||
};
|
||||
Assert.Equal("STUDIO-PC", WorkspaceText.Author(Made("chronos@STUDIO-PC")));
|
||||
Assert.Equal("STUDIO-PC", WorkspaceText.Author(Made("Chronos on STUDIO-PC")));
|
||||
Assert.Equal("STUDIO-PC", WorkspaceText.Author(Made("STUDIO-PC")));
|
||||
Assert.Equal("Alberto", WorkspaceText.Author(Made("STUDIO-PC", "Alberto")));
|
||||
Assert.Equal(Environment.MachineName, WorkspaceHost.ClientName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task CompareNamesExclusionsAsTheSettingTheyAre()
|
||||
{
|
||||
await using var bed = await WorkspaceTestBed.CreateAsync(context);
|
||||
var host = bed.Host();
|
||||
var projectId = await bed.CheckoutAsync(host);
|
||||
var (source, session) = await bed.OpenAsync(host, projectId);
|
||||
var ui = new RecordingUi();
|
||||
await using (session)
|
||||
using (var menu = new ProjectMenuViewModel(host, source, session, ui))
|
||||
{
|
||||
var head = (await host.HistoryAsync(projectId)).Versions[0];
|
||||
Assert.True(session.SetExcluded([1, 3], excluded: true));
|
||||
var lines = menu.Compare(head);
|
||||
Assert.Count(1, lines);
|
||||
Assert.Contains(Loc.L("Server.Setting.ExcludedFrames"), lines[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -180,6 +180,11 @@ internal sealed class RecordingUi : IWorkspaceUi
|
||||
|
||||
public List<Guid> SequencesChanged { get; } = [];
|
||||
|
||||
/// <summary>Dialogs waiting for the open one to close (<see cref="ShowDialogWhenFree"/>).</summary>
|
||||
public Queue<ArchiveDialogViewModel> Waiting { get; } = new();
|
||||
|
||||
public ArchiveDialogViewModel? Dialog => Open;
|
||||
|
||||
public void ShowDialog(ArchiveDialogViewModel dialog)
|
||||
{
|
||||
Open?.Dispose();
|
||||
@@ -187,11 +192,23 @@ internal sealed class RecordingUi : IWorkspaceUi
|
||||
Open = dialog;
|
||||
}
|
||||
|
||||
public void ShowDialogWhenFree(ArchiveDialogViewModel dialog)
|
||||
{
|
||||
if (Open is null) ShowDialog(dialog);
|
||||
else Waiting.Enqueue(dialog);
|
||||
}
|
||||
|
||||
public void CloseDialog(ArchiveDialogViewModel dialog)
|
||||
{
|
||||
if (!ReferenceEquals(Open, dialog)) return;
|
||||
dialog.Dispose();
|
||||
Open = null;
|
||||
while (Waiting.TryDequeue(out var next))
|
||||
{
|
||||
if (next.IsClosed) continue;
|
||||
ShowDialog(next);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Confirm(ConfirmRequest request)
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
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;
|
||||
}
|
||||
Reference in new issue
Block a user