fix: phase 5a fix round 3, desktop: newer copies, readable discard, working-state conflicts, edits kept aside
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>
This commit is contained in:
1 parent
488b588ad9
commit
e8ea858021
21 files changed
+696
-54
No files matched your search
@@ -6,6 +6,7 @@ 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;
|
||||
@@ -156,6 +157,8 @@ public sealed class WorkspaceFallbackTests(TestContext context)
|
||||
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);
|
||||
@@ -168,13 +171,27 @@ public sealed class WorkspaceFallbackTests(TestContext context)
|
||||
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);
|
||||
@@ -185,10 +202,59 @@ public sealed class WorkspaceFallbackTests(TestContext context)
|
||||
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()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user