Merge branch 'review2-p5a-fix2-desktop' into review2-p5a-int2

# Conflicts:
#	i18n/en/Editor.resx
#	i18n/en/Tooltips.resx
#	i18n/it/Tooltips.it.resx
#	src/Chronos.Data/Workspaces/WorkspaceSync.cs
#	tests/Chronos.Data.Tests/Workspaces/WorkspaceRecoveryTests.cs
This commit is contained in:
Alby96 committed 2026-11-03 12:15:27 +01:00
commit 47c660735f
30 files changed
+1021 -110

No files matched your search

@@ -153,6 +153,27 @@ public sealed class SyncTextTests
Assert.Equal(0, rows.Count(r => SyncText.Matches(r, SyncFilter.Conflicts, "comet")));
}
[Test]
public void ASettingDifferingOnSeveralPhotosIsOneLineWithTheirCount()
{
var keyframes = new SettingsDifference("pendingFrames.sha:ab12#0.keyframes", "[]", "[{\"x\":1}]");
var lines = SyncText.Differences(
[
new SettingsDifference("pendingFrames.sha:ab12#0.excluded", "true", "false"),
keyframes,
new SettingsDifference("pendingFrames.sha:cd34#0.excluded", "true", "false"),
new SettingsDifference("pendingFrames.sha:ef56#1.excluded", "false", "true"),
new SettingsDifference("pendingFrames.sha:ab12#0.excluded", "true", "false"),
], 10);
// Counted by photo, in the order the settings were met; a setting on one photo keeps its values.
Assert.SequenceEqual(
[Loc.L("Server.Conflict.Count", Loc.L("Server.Setting.ExcludedFrames"), Chronos.App.Infrastructure.Formatting.Count(3)), SyncText.Differences([keyframes], 1)[0]],
lines);
Assert.Contains(Loc.L("Server.Setting.Keyframes"), lines[1]);
Assert.Count(1, SyncText.Differences([new SettingsDifference("pendingFrames.sha:ab12#0.excluded", "true", "false")], 10));
Assert.Contains(Loc.L("Server.Setting.ExcludedFrames"), SyncText.Differences([new SettingsDifference("pendingFrames.sha:ab12#0.excluded", "true", "false")], 10)[0]);
}
[Test]
public void ATransferCountsWhereItsOriginalsAre()
{
@@ -0,0 +1,319 @@
using System.Globalization;
using System.IO;
using Chronos.App.Archiving;
using Chronos.App.Infrastructure;
using Chronos.App.Settings;
using Chronos.App.Workspace;
using Chronos.Core.Archiving;
using Chronos.Core.Localization;
using Chronos.Data.Projects;
using Chronos.Data.Sync;
using Chronos.Data.Workspaces;
using Chronos.Testing;
using Chronos.Ui.Controls;
namespace Chronos.App.Tests.Workspace;
/// <summary>
/// The ways on that review 2's phase 5a fix round 2 gave the workspace (owner review 2, R8): another workspace folder when
/// the one in use is refused, a copy whose working state cannot be read listed as damaged and removed only after a plan,
/// the half media of a cancelled first copy, the copy's size and the drive's free space before it starts, a conflict of
/// format that offers only Save both, a read-only library named as such, and pruning that keeps a version the library
/// cannot give back.
/// </summary>
[Category("workspace")]
public sealed class WorkspaceFallbackTests(TestContext context)
{
static WorkspaceFallbackTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
[Test]
public async Task AnotherWorkspaceFolderIsUsedAfterItsPlanAndNothingIsMoved()
{
await using var bed = await WorkspaceTestBed.CreateAsync(context, frames: 4);
var settings = new AppSettings();
var saves = 0;
var host = new WorkspaceHost(bed.Environment, settings, () => saves++, () => bed.Db, () => bed.Archives, () => bed.Engine)
{
LockWait = TimeSpan.FromSeconds(TestTiming.Budget(10)),
};
var mainId = await bed.CheckoutAsync(host);
var first = host.Root;
var before = saves;
var row = await bed.RowAsync();
var library = (await bed.Db.Archives.GetAsync(row.ArchiveId))!.RootPath;
// A folder inside a library is refused, and nothing changes.
var inside = Path.Combine(library, "workspace");
Assert.True((await host.PlanFolderAsync(inside)).InsideLibrary);
var refused = await Assert.ThrowsAsync<WorkspaceException>(() => host.UseFolderAsync(inside));
Assert.True(refused.FolderRefused);
Assert.Equal(Loc.L("Errors.Workspace.InsideLibraryFolder", Path.GetFullPath(inside)), refused.Message);
Assert.Equal(((string?)null, before, first), (settings.WorkspaceFolder, saves, host.Root));
Assert.False(Directory.Exists(inside), "nothing was written there");
// The plan counts what stays and what is found; using the folder names it in the settings and lists its projects.
var other = Path.Combine(bed.Directory, "other workspace");
var plan = await host.PlanFolderAsync(other);
Assert.Equal(new WorkspaceFolderPlan(first, Path.GetFullPath(other), 1, 0, false), plan);
Assert.False(plan.IsSame);
Assert.True((await host.PlanFolderAsync(first + Path.DirectorySeparatorChar)).IsSame);
await host.UseFolderAsync(other);
Assert.Equal((Path.GetFullPath(other), before + 1), (settings.WorkspaceFolder, saves));
Assert.Equal(Path.GetFullPath(other), host.Root);
Assert.Empty(await host.ListAsync());
Assert.FileExists(Path.Combine(first, mainId.ToString("N"), WorkspaceProject.BundleFile));
// Chosen back, the default is named by no setting and its project is listed again.
Assert.Equal(new WorkspaceFolderPlan(Path.GetFullPath(other), first, 0, 1, false), await host.PlanFolderAsync(first));
await host.UseFolderAsync(first);
Assert.Equal(((string?)null, before + 2), (settings.WorkspaceFolder, saves));
Assert.Equal(mainId, (await host.ListAsync()).Single().ProjectId);
}
[Test]
public async Task ChoosingAFolderAsksItsPlanAndClosesTheProjectFirst()
{
await using var bed = await WorkspaceTestBed.CreateAsync(context, frames: 4);
var settings = new AppSettings();
var host = bed.Host(settings);
await bed.CheckoutAsync(host);
var first = host.Root;
var library = (await bed.Db.Archives.GetAsync((await bed.RowAsync()).ArchiveId))!.RootPath;
var failures = new List<string>();
var closes = 0;
var close = true;
Task<bool> CloseProject()
{
closes++;
return Task.FromResult(close);
}
// Nothing picked, or the folder in use: nothing asked.
var dialogs = new ScriptedDialogs { Folder = null };
Assert.False(await WorkspaceFolderChange.ChooseAsync(host, dialogs, CloseProject, failures.Add));
dialogs.Folder = first;
Assert.False(await WorkspaceFolderChange.ChooseAsync(host, dialogs, CloseProject, failures.Add));
Assert.Empty(dialogs.Asked);
// Inside a library: refused with why, without asking.
dialogs.Folder = Path.Combine(library, "inside");
Assert.False(await WorkspaceFolderChange.ChooseAsync(host, dialogs, CloseProject, failures.Add));
Assert.SequenceEqual([Loc.L("Errors.Workspace.InsideLibraryFolder", Path.GetFullPath(dialogs.Folder!))], failures);
Assert.Empty(dialogs.Asked);
// Declined, or the open project kept open: the folder stays.
var other = Path.Combine(bed.Directory, "elsewhere");
dialogs.Folder = other;
dialogs.Answer = false;
Assert.False(await WorkspaceFolderChange.ChooseAsync(host, dialogs, CloseProject, failures.Add));
Assert.Count(1, dialogs.Asked);
var asked = dialogs.Asked[0];
Assert.Equal(Loc.L("Settings.Workspace.ChangeMessage", Path.GetFullPath(other), first), asked.Message);
Assert.Contains(Loc.L("Settings.Workspace.ProjectsLeft", Formatting.Count(1)), asked.Detail);
Assert.Contains(Loc.L("Settings.Workspace.ProjectsFound", Formatting.Count(0)), asked.Detail);
Assert.True(asked is { IsDestructive: false, ActionText.Length: > 0, ActionToolTip.Length: > 0, SafeToolTip.Length: > 0 });
Assert.Equal(0, closes, "nothing closed before the plan is confirmed");
dialogs.Answer = true;
close = false;
Assert.False(await WorkspaceFolderChange.ChooseAsync(host, dialogs, CloseProject, failures.Add));
Assert.Equal((1, first), (closes, host.Root));
close = true;
Assert.True(await WorkspaceFolderChange.ChooseAsync(host, dialogs, CloseProject, failures.Add));
Assert.Equal((Path.GetFullPath(other), 2), (host.Root, closes));
Assert.Count(1, failures);
}
[Test]
public void SettingsWorkspaceChangesTheFolderOnlyWhereItCan()
{
var settings = new AppSettings();
var changes = 0;
var rows = new WorkspaceSettingsRows(settings, () => { }, () => @"D:\Workspace", () => { }, () =>
{
changes++;
return Task.CompletedTask;
});
Assert.True(rows.CanChange && rows.ChangeCommand.CanExecute(null));
rows.ChangeCommand.Execute(null);
Assert.Equal(1, changes);
var capture = new WorkspaceSettingsRows(settings, () => { }, () => @"D:\Workspace", () => { });
Assert.False(capture.CanChange || capture.ChangeCommand.CanExecute(null));
}
[Test]
public async Task ACopyWhoseWorkingStateCannotBeReadIsListedAsDamagedAndGoesOnlyByDiscard()
{
await using var bed = await WorkspaceTestBed.CreateAsync(context, frames: 4);
var host = bed.Host(new AppSettings { WorkspaceAutoSync = false });
var mainId = await bed.CheckoutAsync(host);
var (_, session) = await bed.OpenAsync(host, mainId);
await using (session)
{
session.Edit(p => p with { HeroFrame = 2 });
Assert.True(await session.FlushAsync());
}
var unsent = (await host.SaveVersionAsync(mainId, "Not sent")).Version!;
var project = host.Store.Find(mainId)!;
await File.WriteAllTextAsync(project.BundlePath, "{ this is not a project", bed.Ct);
var all = await host.ListAsync();
Assert.Count(1, all);
var listed = all[0];
Assert.True(listed is { Damaged: true, HasMedia: false });
Assert.Equal(mainId, listed.ProjectId);
Assert.True((await host.FindAsync(mainId))!.Damaged);
Assert.Empty(await host.ProjectsOfAsync(bed.SequenceId), "a copy that cannot say its sequence is not one of it");
var item = new WorkspaceProjectItem(listed, null);
Assert.Equal((Loc.L("Editor.Workspace.State.Damaged"), StatusKind.Error, Loc.L("Tooltips.Editor.Workspace.State.DamagedCopy")),
(item.StateText, item.StateKind, item.StateToolTip));
var plan = await host.PlanRemovalAsync(mainId);
Assert.True(plan is { Damaged: true, IsSafe: false, Unsent: 1 });
Assert.Greater(plan.Files, 0);
var dialog = new RemoveCopyDialogViewModel(plan, _ => Task.CompletedTask, () => Task.CompletedTask, () => false, _ => { });
Assert.False(dialog.RemoveCommand.CanExecute(null) || dialog.SendFirstCommand.CanExecute(null));
Assert.True(dialog.DiscardCommand.CanExecute(null));
Assert.Equal((Loc.L("Errors.Workspace.Damaged"), Loc.L("Errors.Workspace.Damaged")), (dialog.RemoveToolTip, dialog.SendFirstToolTip));
var refused = await Assert.ThrowsAsync<WorkspaceException>(() => host.RemoveLocalCopyAsync(mainId, discard: false));
Assert.Equal(Loc.L("Errors.Workspace.Damaged"), refused.Message);
Assert.NotNull(host.Store.Find(mainId), "nothing was removed");
await host.RemoveLocalCopyAsync(mainId, discard: true);
Assert.Null(host.Store.Find(mainId));
var aside = Assert.Contains(Directory.EnumerateDirectories(Path.Combine(host.Root, WorkspaceHost.TrashFolder)),
d => Path.GetFileName(d).StartsWith(mainId.ToString("N"), StringComparison.Ordinal));
Assert.Equal("{ this is not a project", await File.ReadAllTextAsync(Path.Combine(aside, WorkspaceProject.BundleFile), bed.Ct), "kept as it was");
Assert.True(Directory.EnumerateFiles(Path.Combine(aside, WorkspaceProject.VersionsFolder)).Any(f => f.Contains(unsent.Id.ToString(), StringComparison.OrdinalIgnoreCase)
|| f.Contains(unsent.Id.ToString("N"), StringComparison.OrdinalIgnoreCase)), "the version never sent is kept");
}
[Test]
public async Task ACancelledFirstCopyLeavesNoHalfMedia()
{
await using var bed = await WorkspaceTestBed.CreateAsync(context, frames: 4);
var host = bed.Host();
var mainId = await bed.CheckoutAsync(host);
var project = host.Store.Find(mainId)!;
Assert.False(await host.RemovePartialMediaAsync(mainId), "a copy that ended keeps its media");
Assert.FileExists(project.MediaIndexPath);
// A first copy stopped before its index was written: what it wrote goes, the working state stays.
File.Delete(project.MediaIndexPath);
Assert.NotEmpty(Directory.EnumerateFiles(project.MediaDirectory, "*", SearchOption.AllDirectories));
Assert.True(await host.RemovePartialMediaAsync(mainId));
Assert.False(Directory.Exists(project.MediaDirectory));
Assert.FileExists(project.BundlePath);
Assert.False(await host.RemovePartialMediaAsync(mainId), "nothing left to remove");
Assert.False(await host.RemovePartialMediaAsync(Guid.NewGuid()));
}
[Test]
public async Task OpenInWorkspaceShowsTheCopysSizeAndTheFreeSpace()
{
await using var bed = await WorkspaceTestBed.CreateAsync(context, frames: 4);
var host = bed.Host();
var facts = await host.CopyFactsAsync(bed.SequenceId);
Assert.Greater(facts.Bytes, 0);
Assert.NotNull(facts.Free);
Assert.False(facts.TooLittleSpace, "the test drive has room for four small proxies");
var dialog = new OpenInWorkspaceDialogViewModel("Synthetic", await host.HomeProjectsAsync(bed.SequenceId), _ => { }, copy: facts);
Assert.SequenceEqual([Loc.L("Editor.OpenWorkspace.Size"), Loc.L("Editor.OpenWorkspace.Free")], dialog.CopyFacts.Select(f => f.Label));
Assert.Equal(Formatting.Bytes(facts.Bytes), dialog.CopyFacts[0].Value);
Assert.False(dialog.IsShortOfSpace);
var short_ = new OpenInWorkspaceDialogViewModel("Synthetic", [], _ => { }, copy: new WorkspaceCopyFacts(1_000_000, 1_000_000));
Assert.True(short_.IsShortOfSpace);
Assert.Equal(Loc.L("Errors.Workspace.NoRoom"), short_.CopyFacts[1].Reason);
var unknown = new OpenInWorkspaceDialogViewModel("Synthetic", [], _ => { }, copy: new WorkspaceCopyFacts(1_000_000, null));
Assert.Equal((false, Loc.L("Server.Sync.None")), (unknown.IsShortOfSpace, unknown.CopyFacts[1].Value));
Assert.Empty(new OpenInWorkspaceDialogViewModel("Synthetic", [], _ => { }).CopyFacts);
Assert.False(new WorkspaceCopyFacts(1_000, 1_000 + WorkspaceJobs.CopySpaceReserve).TooLittleSpace);
Assert.True(new WorkspaceCopyFacts(1_000, 999 + WorkspaceJobs.CopySpaceReserve).TooLittleSpace);
}
[Test]
public void AConflictOfFormatOffersOnlySaveBothAndSaysWhy()
{
var newer = new ConflictDialogViewModel("Main", "Main (STUDIO-PC)", ["Version 1 here, 2 in the library"], _ => Task.CompletedTask, _ => { },
newerFormat: true);
Assert.False(newer.CanMerge || newer.KeepMineCommand.CanExecute(null) || newer.TakeHomeCommand.CanExecute(null));
Assert.True(newer.SaveBothCommand.CanExecute(null));
Assert.SequenceEqual([Loc.L("Editor.Workspace.Conflict.NewerFormat")], newer.Differences);
Assert.Equal(Loc.L("Editor.Workspace.Conflict.NewerMessage", "Main"), newer.Message);
Assert.Equal(Loc.L("Tooltips.Editor.Workspace.NewerFormat"), newer.DifferencesToolTip);
Assert.Equal(Loc.L("Tooltips.Editor.Workspace.SaveBothNewer", "Main (STUDIO-PC)"), newer.SaveBothToolTip);
var merge = new ConflictDialogViewModel("Main", "Main (STUDIO-PC)", ["Hero frame 2 here, 3 in the library"], _ => Task.CompletedTask, _ => { });
Assert.True(merge.CanMerge && merge.KeepMineCommand.CanExecute(null) && merge.TakeHomeCommand.CanExecute(null));
Assert.Equal(Loc.L("Tooltips.Editor.Workspace.SaveBoth", "Main (STUDIO-PC)"), merge.SaveBothToolTip);
// The format's numbers never reach the lines: one line names the cause.
var lines = WorkspaceText.ConflictLines([new SettingsDifference(ProjectMerge.FormatPath, "1", "2"), new SettingsDifference("hero", "2", "3")], 10);
Assert.SequenceEqual([Loc.L("Editor.Workspace.Conflict.NewerFormat")], lines);
}
[Test]
public void AReadOnlyLibraryIsNamedAsSuchNotAsOffline()
{
var readOnly = new ArchiveOfflineException(@"E:\Library", ArchiveAvailability.ReadOnly);
Assert.Equal(Loc.L("Errors.Workspace.ReadOnlyHome"), WorkspaceText.Failure(new HomeUnavailableException(readOnly.Message, readOnly)));
Assert.Equal(Loc.L("Errors.Workspace.ReadOnlyHome"), WorkspaceText.Failure(readOnly));
var offline = new ArchiveOfflineException(@"E:\Library", ArchiveAvailability.Offline);
Assert.Equal(Loc.L("Errors.Workspace.Offline"), WorkspaceText.Failure(new HomeUnavailableException(offline.Message, offline)));
Assert.Equal(Loc.L("Errors.Workspace.Offline"), WorkspaceText.Failure(new HomeUnavailableException("The project's home cannot be reached from this PC.")));
}
[Test]
public async Task PruningKeepsAVersionTheLibraryCannotGiveBack()
{
await using var bed = await WorkspaceTestBed.CreateAsync(context, frames: 4);
var settings = new AppSettings { WorkspaceKeptVersions = 100 };
var host = bed.Host(settings);
var mainId = await bed.CheckoutAsync(host);
var (_, session) = await bed.OpenAsync(host, mainId);
await using (session)
{
for (var i = 1; i <= 5; i++)
{
session.Edit(p => p with { Exposure = p.Exposure with { ExposureOffsetEv = i / 10.0 } });
Assert.True(await session.FlushAsync());
await host.SaveVersionAsync(mainId, $"Step {i}");
}
}
var project = host.Store.Find(mainId)!;
Assert.SequenceEqual([1, 2, 3, 4, 5, 6], project.Versions().Where(v => v.StoredAt is not null).Select(v => v.Number).Order());
// The library's file of version 2 is damaged: the workspace's copy is the only good one left, so it stays.
var second = project.Versions().Single(v => v.Number == 2);
var row = await bed.RowAsync();
var library = (await bed.Db.Archives.GetAsync(row.ArchiveId))!.RootPath;
var damaged = new ArchivePaths(library).Sequence(row.Folder).VersionPath(mainId, 2, second.Id);
Assert.FileExists(damaged);
await File.WriteAllTextAsync(damaged, "{ damaged", bed.Ct);
settings.WorkspaceKeptVersions = 2;
Assert.Equal(3, await host.PruneAsync(mainId, host.HomeOfSequence(bed.SequenceId)));
Assert.SequenceEqual([2, 5, 6], project.Versions().Where(v => v.StoredAt is not null).Select(v => v.Number).Order());
}
/// <summary>Dialogs that pick <see cref="Folder"/> and answer every confirmation with <see cref="Answer"/>, recording what they were asked.</summary>
private sealed class ScriptedDialogs : IAppDialogs
{
public string? Folder { get; set; }
public bool Answer { get; set; }
public List<ConfirmRequest> Asked { get; } = [];
public string? PickFolder(string title, string? initialFolder = null) => Folder;
public string? PickJsonFile(string title) => null;
public bool Confirm(ConfirmRequest request)
{
Asked.Add(request);
return Answer;
}
public bool SignIn(string server, string? username, Func<string, string, Task<string?>> signIn) => false;
}
}
@@ -78,6 +78,80 @@ public abstract class WorkspaceConflictTests(TestContext context) : DatabaseTest
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 TakingTheLibrarysValuesOverUnsavedChangesSendsNoVersion()
{
var (fx, _, two, id, shown) = await AskedAsync(await FixtureAsync());
// Unsaved too: a setting only this side changed.
await EditAsync(two, id, s => s with { Motion = s.Motion with { TargetShutterAngle = s.Motion.TargetShutterAngle.WithManual(90) } }, fx.Ct);
var history = await fx.Home.HistoryAsync(id, null, 10, fx.Ct);
var settled = await two.ResolveAsync(id, fx.Home, ConflictChoice.TakeServer, shown: shown, cancellationToken: fx.Ct);
Assert.Null(settled.Status.Conflict);
Assert.Empty(two.Unpushed(id), "no version of the working state is made, so none repeating the head is sent");
Assert.Equal(WorkspaceState.Modified, settled.Status.State, "the change only this side made waits, unsaved as it was");
var working = (await two.OpenAsync(id, fx.Ct)).Working;
Assert.Equal((0.5, StackSetting.Median, 90.0), (working.Exposure.ExposureOffsetEv, working.Stack.Mode, working.Motion.TargetShutterAngle.Resolve(0)));
Assert.Equal(1.0, Assert.NotNull(settled.Kept).Exposure.ExposureOffsetEv);
Assert.Empty((await two.PushAsync(id, fx.Home, fx.Ct)).Pushed);
Assert.Equal(history.Count, (await fx.Home.HistoryAsync(id, null, 10, fx.Ct)).Count, "the library's history holds no empty version");
// The value taken over stays in a version file set aside, outside the versions to send.
var replaced = Path.Combine(two.Store.Find(id)!.VersionsDirectory, WorkspaceProject.ReplacedFolder);
Assert.Contains(Directory.GetFiles(replaced).Select(ProjectSidecars.ReadVersion), v => ProjectSettings.FromJson(v.SettingsJson).Exposure.ExposureOffsetEv == 1.0);
}
[Test]
public async Task AConflictListsTheWorkingStatesValueAndOneAnswerSettlesIt()
{
var fx = await FixtureAsync();
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 => Offset(s, 0.5), fx.Ct);
await one.CommitAsync(id, cancellationToken: fx.Ct);
await one.PushAsync(id, fx.Home, fx.Ct);
// This side saved 0.8 as a version, then went on to 1 without saving.
await EditAsync(two, id, s => Offset(s, 0.8), fx.Ct);
await two.CommitAsync(id, "warmer", cancellationToken: fx.Ct);
await EditAsync(two, id, s => Offset(s, 1.0), fx.Ct);
var shown = Assert.NotNull((await two.PullAsync(id, fx.Home, fx.Ct)).Status.Conflict);
var difference = shown.Differences.Single();
Assert.Equal(("exposure.exposureOffsetEv", 1.0, 0.5), (difference.Path, Number(difference.Mine), Number(difference.Theirs)),
"this side's value is the one the editor shows");
var settled = await two.ResolveAsync(id, fx.Home, ConflictChoice.TakeServer, shown: shown, cancellationToken: fx.Ct);
Assert.Null(settled.Status.Conflict, "one answer settles what was shown");
Assert.Equal(0.5, (await two.OpenAsync(id, fx.Ct)).Working.Exposure.ExposureOffsetEv);
Assert.Equal(1.0, Assert.NotNull(settled.Kept).Exposure.ExposureOffsetEv);
Assert.Equal("warmer", two.Unpushed(id).Single().Note, "the saved version is replayed, nothing more");
}
[Test]
public async Task KeepMineKeepsTheWorkingStatesValueItListed()
{
var fx = await FixtureAsync();
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 => Offset(s, 0.5), fx.Ct);
await one.CommitAsync(id, cancellationToken: fx.Ct);
await one.PushAsync(id, fx.Home, fx.Ct);
await EditAsync(two, id, s => Offset(s, 0.8), fx.Ct);
await two.CommitAsync(id, cancellationToken: fx.Ct);
await EditAsync(two, id, s => Offset(s, 1.0), fx.Ct);
var shown = Assert.NotNull((await two.PullAsync(id, fx.Home, fx.Ct)).Status.Conflict);
var settled = await two.ResolveAsync(id, fx.Home, ConflictChoice.KeepMine, shown: shown, cancellationToken: fx.Ct);
Assert.Null(settled.Status.Conflict);
Assert.Equal(1.0, (await two.OpenAsync(id, fx.Ct)).Working.Exposure.ExposureOffsetEv, "the value listed as this side's is kept");
}
private static double? Number(string? json) => json is null ? null : double.Parse(json, System.Globalization.CultureInfo.InvariantCulture);
[Test]
public async Task KeepMineIsAskedAgainWhenTheLibraryMovedOnASettingThisSideChanged()
{
@@ -159,8 +159,7 @@ public abstract class WorkspaceRecoveryTests(TestContext context) : DatabaseTest
Assert.Equal(WorkspaceState.InSync, (await one.PushAsync(id, fx.Home, fx.Ct)).Status.State);
var head = Settings(await fx.Home.HeadAsync(id, fx.Ct));
Assert.Equal((1.0, StackSetting.Mean), (head.Exposure.ExposureOffsetEv, head.Stack.Mode));
// Taking the server's first saves the unsaved offset as a version, kept aside for its undo: replayed it holds the
// server's values only, so it is not sent.
// The unsaved offset taken over is kept aside, never sent: the home holds exactly these versions, in order.
Assert.SequenceEqual(["first", "other", "second"], (await NotesAsync(fx, id)).Skip(1));
Assert.Contains(Directory.GetFiles(Path.Combine(one.Store.Project(id).VersionsDirectory, WorkspaceProject.ReplacedFolder)),
f => ProjectSidecars.ReadVersion(f) is { Note: null } saved && Settings(saved).Exposure.ExposureOffsetEv == 2.0);