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:
Alby96andClaude Opus 5.5 committed 2026-11-03 13:33:34 +01:00
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()
{
@@ -1,4 +1,7 @@
using System.IO;
using Chronos.Core.Project;
using Chronos.Data.Projects;
using Chronos.Data.Workspaces;
using Chronos.Testing;
namespace Chronos.App.Tests.Workspace;
@@ -46,4 +49,50 @@ public sealed class WorkspaceNewerFormatTests(TestContext context)
Assert.Equal(1.5, session.Project.Exposure.ExposureOffsetEv);
}
}
[Test]
public async Task AnEditNotStoredYetIsKeptAsideWhenANewerChronossSettingsArrive()
{
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);
await using (session)
{
var kept = new List<string>();
session.EditSetAside += kept.Add;
Assert.True(session.Edit(p => Exposure(p, 0.4)));
Assert.True(await session.FlushAsync());
Assert.NotNull(await host.CommitAsync(projectId, bed.Ct));
var folder = host.Store.Find(projectId)!;
var stored = folder.ReadBundle();
// A sync took a newer Chronos's settings while one more edit waited for its save (made during the sync).
folder.WriteBundle(stored with { Project = Exposure(stored.Project, 1.5) with { Version = ProjectSettings.CurrentVersion + 1 } });
Assert.True(session.Edit(p => p with { ExcludedFrames = [2] }));
Assert.False(await session.FlushAsync(), "the working state no longer takes it");
await session.ReloadAsync();
Assert.True(session.IsReadOnly);
Assert.True(session.Project.IsNewerFormat, "the newer settings are taken");
Assert.Equal(1.5, session.Project.Exposure.ExposureOffsetEv);
Assert.True(await session.FlushAsync(), "nothing retried that could never be stored");
Assert.False(session.HasPendingSave);
Assert.Null(session.LastSaveError);
var path = Assert.NotNull(kept.SingleOrDefault(), "the edit is kept aside, and said");
Assert.Equal(Path.Combine(folder.VersionsDirectory, WorkspaceProject.ReplacedFolder), Path.GetDirectoryName(path));
var aside = ProjectSidecars.ReadVersion(path);
var placed = ProjectSettings.FromJson(ProjectContent.Place(aside.SettingsJson, source.Photos));
Assert.Equal(0.4, placed.Exposure.ExposureOffsetEv);
Assert.SequenceEqual([2], placed.ExcludedFrames, "the edit as it was, by photo");
Assert.False(folder.Versions().Any(v => v.Id == aside.Id), "outside the chain: never sent");
Assert.Empty(host.Sync.Unpushed(projectId).Where(v => v.Id == aside.Id));
// Read again: no throw, nothing more kept aside, the editor as it is.
await session.ReloadAsync();
Assert.Count(1, kept);
Assert.Equal(1.5, session.Project.Exposure.ExposureOffsetEv);
Assert.True(await session.FlushAsync());
}
}
}
@@ -15,6 +15,7 @@ using Chronos.Data;
using Chronos.Data.Archiving;
using Chronos.Data.Workspaces;
using Chronos.Testing;
using Chronos.Ui.Controls;
namespace Chronos.App.Tests.Workspace;
@@ -115,6 +116,91 @@ public sealed class WorkspaceSectionTests(TestContext context)
}
});
[Test]
public Task ARefusedFolderOffersAnotherFromItsToastAndCopiesThisChronosCannotReadAreNeverOpened() => ScreenHost.RunAsync(async () =>
{
var directory = context.CreateTempDirectory("workspace-refused");
var environment = AppEnvironment.From(AppPaths.Resolve(Directory.CreateDirectory(Path.Combine(directory, "app")).FullName,
Directory.CreateDirectory(Path.Combine(directory, "local")).FullName, []));
UiLanguage.Apply("en");
var settings = new AppSettings { Language = "en", FirstRunCompleted = true, CheckForUpdates = false };
var outside = Path.Combine(directory, "outside");
var dialogs = new ScriptedDialogs { Folder = outside };
var services = new AppServices(environment, settings, () => { }, dialogs);
await services.AttachAsync(await ChronosDatabase.OpenAsync(DatabaseOptions.Sqlite(environment.DatabasePath)), startEngine: true);
var shell = new ShellViewModel(services);
var toasts = new List<Toast>();
shell.PendingToasts.CollectionChanged += (_, e) => toasts.AddRange(e.NewItems?.OfType<Toast>() ?? []);
try
{
var library = Path.Combine(directory, "archive");
var sequenceId = await SequenceAsync(services, library);
var inside = Path.Combine(library, "workspace");
settings.WorkspaceFolder = inside;
var section = shell.Sequence;
// Open in workspace shows what the copy writes and the room there is, then the folder is refused with a way on.
shell.OpenSequence(sequenceId);
await WorkspaceTestBed.UntilAsync(() => section.Dialog is OpenInWorkspaceDialogViewModel, "Open in workspace asks the first time");
var ask = (OpenInWorkspaceDialogViewModel)section.Dialog!;
Assert.SequenceEqual([Loc.L("Editor.OpenWorkspace.Size"), Loc.L("Editor.OpenWorkspace.Free")], ask.CopyFacts.Select(f => f.Label), "the copy's facts reach the dialog");
ask.OpenCommand.Execute(null);
await WorkspaceTestBed.UntilAsync(() => toasts.Any(t => t.Title == Loc.L("Editor.Workspace.OpenFailed")), "the refusal is said");
var refused = toasts.Single(t => t.Title == Loc.L("Editor.Workspace.OpenFailed"));
Assert.True(refused is { IsError: true, ActionCommand: not null }, "an error with its action");
Assert.Equal((Loc.L("Errors.Workspace.InsideLibraryEdit", Path.GetFullPath(inside)), Loc.L("Editor.Workspace.ChooseFolder"), Loc.L("Tooltips.Editor.Workspace.ChooseFolder")),
(refused.Message, refused.ActionText, refused.ActionToolTip));
Assert.False(Directory.Exists(inside), "nothing was written inside the library");
Assert.Null(section.Editor);
// Its action picks another folder, shows the plan and uses it.
refused.ActionCommand!.Execute(null);
await WorkspaceTestBed.UntilAsync(() => string.Equals(services.Workspace.Root, Path.GetFullPath(outside), StringComparison.OrdinalIgnoreCase), "the folder chosen is used");
Assert.Count(1, dialogs.Asked);
Assert.Equal(Loc.L("Settings.Workspace.ChangeTitle"), dialogs.Asked[0].Heading);
// That workspace holds a copy a newer Chronos saved and a damaged one: listed, never opened.
var newerId = Guid.CreateVersion7();
var newer = Directory.CreateDirectory(Path.Combine(outside, newerId.ToString("N"))).FullName;
await File.WriteAllTextAsync(Path.Combine(newer, WorkspaceProject.BundleFile),
$$"""{ "format": "chronos-project", "formatVersion": 9, "sequence": { "title": "Harbour" }, "workspace": { "projectId": "{{newerId}}", "name": "Vertical" } }""");
var damagedId = Guid.CreateVersion7();
var damaged = Directory.CreateDirectory(Path.Combine(outside, damagedId.ToString("N"))).FullName;
await File.WriteAllTextAsync(Path.Combine(damaged, WorkspaceProject.BundleFile), "{ not a project");
await File.WriteAllTextAsync(Path.Combine(damaged, "notes.txt"), "kept");
await section.Picker.ReloadAsync();
await section.Picker.WorkspaceLoadedAsync();
var newerItem = Assert.Contains(section.Picker.WorkspaceItems, i => i.ProjectId == newerId);
Assert.True(newerItem is { IsNewer: true, IsDamaged: false, IsReadable: false, Name: "Vertical", SequenceTitle: "Harbour" });
Assert.Null(newerItem.Status, "no state is asked of it");
await section.PickProjectAsync(newerItem);
Assert.Contains(toasts, t => t.Message == Loc.L("Errors.Workspace.NewerCopy") && t.IsError);
Assert.Null(section.Dialog, "nothing is offered over it");
Assert.FileExists(Path.Combine(newer, WorkspaceProject.BundleFile));
// The damaged one offers its removal, named as a damaged copy; Discard asks its files' number and keeps every file aside.
var damagedItem = Assert.Contains(section.Picker.WorkspaceItems, i => i.ProjectId == damagedId);
await section.PickProjectAsync(damagedItem);
var remove = Assert.NotNull(section.Dialog as RemoveCopyDialogViewModel);
Assert.Equal(Loc.L("Editor.RemoveCopy.DamagedTitle"), remove.Heading);
dialogs.Answer = true;
remove.DiscardCommand.Execute(null);
await WorkspaceTestBed.UntilAsync(() => !Directory.Exists(damaged), "the damaged copy goes");
var discard = dialogs.Asked[^1];
Assert.Equal((Loc.L("Editor.RemoveCopy.DamagedDiscard"), Formatting.Count(2), Loc.L("Editor.RemoveCopy.TypeFiles", Formatting.Count(2))),
(discard.Heading, discard.TypedConfirmation, discard.TypedPrompt));
var aside = Assert.Contains(Directory.EnumerateDirectories(Path.Combine(outside, WorkspaceHost.TrashFolder)),
d => Path.GetFileName(d).StartsWith(damagedId.ToString("N"), StringComparison.Ordinal));
Assert.Equal("kept", await File.ReadAllTextAsync(Path.Combine(aside, "notes.txt")));
}
finally
{
await shell.Sequence.CloseAsync();
shell.Dispose();
await services.DisposeAsync();
}
});
/// <summary>An archive with one sequence of six synthetic photos, indexed.</summary>
private async Task<Guid> SequenceAsync(AppServices services, string root)
{
@@ -133,6 +219,24 @@ public sealed class WorkspaceSectionTests(TestContext context)
return (await services.Database!.Sequences.ListLocationsAsync(archive.Id, context.Cancellation)).Single().Id;
}
/// <summary>Dialogs that pick <see cref="Folder"/> and answer every confirmation with <see cref="Answer"/> (yes first), recording what they were asked.</summary>
private sealed class ScriptedDialogs : IAppDialogs
{
public string? Folder { get; set; }
public bool Answer { get; set; } = true;
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;
}
/// <summary>Dialogs that pick nothing and decline every confirmation.</summary>
private sealed class DeclineDialogs : IAppDialogs
{