Merge branch 'review2-p5a-fix3-desktop' into review2-p5a-int3
Conflict in WorkspaceFallbackTests: keeps desktop's new newer-copy test and drops ACancelledFirstCopyLeavesNoHalfMedia, which the sync branch removed along with WorkspaceHost.RemovePartialMediaAsync (the cancelled first copy's clean-up now runs in the copy job, tested in Data). ReplayAsync auto-merged with both intents: desktop's working-state conflicts and silent paths, and sync's skip of no-change versions, Settles journal flag and PruneReplaced. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
c5ed31bced
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 OpenInWorkspaceShowsTheCopysSizeAndTheFreeSpace()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user