Owner review 2, R8. Round 2's checkers left five desktop problems: - A workspace copy whose project.chronos a newer Chronos wrote (a format this one does not know) was listed as damaged and offered for Discard. It is now listed as "Newer Chronos" with its own tooltip, named from what of its file still reads. It never opens, is never checked out over, and Remove local copy refuses it with a sentence that says why. - Discard of any copy moved only the files Chronos knows. It now moves every file and folder of the copy aside (only the media are deleted) and removes the folder only when nothing else came into it. - Discarding a damaged copy asked to type its folder's GUID. It now asks for the name the copy is still known by (its file, else the library's index; the project's name, else the sequence's title), else for the number of its files. The heading never shows the id. - A conflict at a path where the working state had gone back to the base value listed the local version's value. The conflict now lists the working state's value in every case. Where the working state already holds the library's value there is nothing to ask: that path takes the library's value in the replayed versions too, so they agree. - EditorSession.ReloadAsync, ResolveConflict and TakeOverAsync threw NewerSettingsException on every reload when an edit was not stored yet and the stored project became a newer Chronos's. The edit is now kept in versions/.replaced (outside the chain, never sent), a toast says so, the pending save is dropped and the newer settings are shown read-only. When the edit cannot be kept aside, the editor stays as it is and nothing is dropped. The SequenceViewModel wiring now has a view-model test: the copy's facts in Open in workspace, the refused-folder toast and its Choose folder action, and the picker for a newer copy and a damaged one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
386 lines
23 KiB
C#
386 lines
23 KiB
C#
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.Core.Project;
|
|
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);
|
|
// A file this Chronos does not know (a newer one's, the user's own): Discard keeps it too.
|
|
await File.WriteAllTextAsync(Path.Combine(project.Folder, "notes.txt"), "kept", 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));
|
|
|
|
Assert.Equal(Loc.L("Editor.Project.Main"), listed.KnownName, "named as the library's index knows it, not by its folder's id");
|
|
var plan = await host.PlanRemovalAsync(mainId);
|
|
Assert.True(plan is { Damaged: true, IsSafe: false, Unsent: 1 });
|
|
Assert.Greater(plan.Files, 0);
|
|
Assert.Equal(Loc.L("Editor.Project.Main"), plan.KnownName);
|
|
var typed = RemoveCopyDialogViewModel.DiscardRequest(plan);
|
|
Assert.Equal((Loc.L("Editor.RemoveCopy.DiscardTitle", Loc.L("Editor.Project.Main")), Loc.L("Editor.Project.Main")), (typed.Heading, typed.TypedConfirmation),
|
|
"a readable name is typed");
|
|
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));
|
|
Assert.Equal(Loc.L("Editor.RemoveCopy.Title", Loc.L("Editor.Project.Main")), dialog.Heading);
|
|
|
|
// Known by no name at all: the number of its files is typed instead, and the heading names no id.
|
|
var unnamed = plan with { KnownName = null };
|
|
var counted = RemoveCopyDialogViewModel.DiscardRequest(unnamed);
|
|
Assert.Equal((Loc.L("Editor.RemoveCopy.DamagedDiscard"), Formatting.Count(plan.Files), Loc.L("Editor.RemoveCopy.TypeFiles", Formatting.Count(plan.Files))),
|
|
(counted.Heading, counted.TypedConfirmation, counted.TypedPrompt));
|
|
Assert.True(counted.IsDestructive);
|
|
Assert.Equal(Loc.L("Editor.RemoveCopy.DamagedTitle"), new RemoveCopyDialogViewModel(unnamed, _ => Task.CompletedTask, () => Task.CompletedTask, () => false, _ => { }).Heading);
|
|
|
|
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.Equal("kept", await File.ReadAllTextAsync(Path.Combine(aside, "notes.txt"), bed.Ct), "every file of the folder is kept, not only the known ones");
|
|
Assert.False(Directory.Exists(Path.Combine(aside, WorkspaceProject.MediaFolder)), "the media, which the library makes again, are not kept");
|
|
Assert.False(Directory.Exists(project.Folder));
|
|
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 ACopyANewerChronosSavedIsListedAsSuchAndNeitherOpensNorGoes()
|
|
{
|
|
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 project = host.Store.Find(mainId)!;
|
|
// A newer Chronos on this PC rewrote the working state in a format this one does not know (a downgrade since).
|
|
var json = System.Text.Json.Nodes.JsonNode.Parse(await File.ReadAllTextAsync(project.BundlePath, bed.Ct))!.AsObject();
|
|
json["formatVersion"] = ProjectBundle.CurrentFormatVersion + 1;
|
|
json["somethingNew"] = "of a newer Chronos";
|
|
var newer = json.ToJsonString();
|
|
await File.WriteAllTextAsync(project.BundlePath, newer, bed.Ct);
|
|
await File.WriteAllTextAsync(Path.Combine(project.Folder, "newer.dat"), "a newer Chronos's", bed.Ct);
|
|
Assert.Throws<InvalidDataException>(() => project.ReadBundle());
|
|
|
|
var listed = (await host.ListAsync()).Single();
|
|
Assert.True(listed is { Newer: true, Damaged: false, IsReadable: false, HasMedia: false });
|
|
Assert.Equal((mainId, ProjectService.MainName, true, Loc.L("Editor.Project.Main")), (listed.ProjectId, listed.Name, listed.IsMain, listed.KnownName),
|
|
"named from what of its file reads");
|
|
Assert.Equal("Synthetic", listed.SequenceTitle);
|
|
Assert.True((await host.FindAsync(mainId))!.Newer);
|
|
Assert.Empty(await host.ProjectsOfAsync(bed.SequenceId), "never taken as the sequence's project to open");
|
|
Assert.Null(await host.LastUsedAsync(bed.SequenceId));
|
|
var item = new WorkspaceProjectItem(listed, null);
|
|
Assert.Equal((Loc.L("Editor.Workspace.State.NewerCopy"), StatusKind.Warning, Loc.L("Tooltips.Editor.Workspace.State.NewerCopy")),
|
|
(item.StateText, item.StateKind, item.StateToolTip));
|
|
Assert.True(item is { IsNewer: true, IsDamaged: false, IsReadable: false });
|
|
|
|
// Not offered as damaged: no plan, no discard, and nothing checked out over it.
|
|
var planned = await Assert.ThrowsAsync<WorkspaceException>(() => host.PlanRemovalAsync(mainId));
|
|
Assert.Equal(Loc.L("Errors.Workspace.NewerCopy"), planned.Message);
|
|
var discarded = await Assert.ThrowsAsync<WorkspaceException>(() => host.RemoveLocalCopyAsync(mainId, discard: true));
|
|
Assert.Equal(Loc.L("Errors.Workspace.NewerCopy"), discarded.Message);
|
|
var checkedOut = await Assert.ThrowsAsync<WorkspaceException>(() => host.CheckoutAsync(bed.SequenceId, mainId, null));
|
|
Assert.Equal(Loc.L("Errors.Workspace.NewerCopy"), checkedOut.Message);
|
|
await Assert.ThrowsAsync<WorkspaceException>(() => host.CheckoutAsync(bed.SequenceId, null, null));
|
|
Assert.Equal(newer, await File.ReadAllTextAsync(project.BundlePath, bed.Ct), "left exactly as the newer Chronos wrote it");
|
|
Assert.FileExists(Path.Combine(project.Folder, "newer.dat"));
|
|
Assert.True(Directory.Exists(project.MediaDirectory), "its media stay too");
|
|
|
|
// A damaged file is still damaged, not newer: a format number alone never makes one.
|
|
await File.WriteAllTextAsync(project.BundlePath, "{ \"format\": \"chronos-project\", \"formatVersion\": 9, ", bed.Ct);
|
|
Assert.True((await host.FindAsync(mainId)) is { Damaged: true, Newer: false });
|
|
}
|
|
|
|
[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;
|
|
}
|
|
}
|